rubyrag 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +13 -1
- data/.rubocop_todo.yml +30 -0
- data/README.md +26 -9
- data/docs/create_api_key_for_ai.png +0 -0
- data/docs/create_api_key_for_r2.png +0 -0
- data/docs/create_rag.png +0 -0
- data/lib/rubyrag/cloudflare_auto_rag.rb +63 -0
- data/lib/rubyrag.rb +22 -2
- data/sig/rubyrag.rbs +0 -2
- metadata +93 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a06d4cbb6436336852a00e1ece33426edd6d12afb513a121504ad0cb429ceba3
|
4
|
+
data.tar.gz: d4e0a68cc490cf7bc22b81b1a0bc0fd7f69bee9b527b63c19f4b6344d3353e4f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f38e83268e4e012a18ff9743c8dbd0ce3de8bed17c72455314876d72c2ea86aa62eff37a410275437d0eb0c51cf4351ab1625d64db57414bcb7de1ea9875f4d
|
7
|
+
data.tar.gz: f4826cbb7da89d2b7e122a8532abaf1e883b9bccf5259ef81fd5f8888269f535a1164aaea5eca375b6440a4967743508f063483590b420fde283bbe43a4d30ab
|
data/.rubocop.yml
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
2
|
+
|
1
3
|
AllCops:
|
2
|
-
TargetRubyVersion:
|
4
|
+
TargetRubyVersion: 2.7.7
|
3
5
|
NewCops: enable
|
4
6
|
|
5
7
|
Style/StringLiterals:
|
@@ -7,3 +9,13 @@ Style/StringLiterals:
|
|
7
9
|
|
8
10
|
Style/StringLiteralsInInterpolation:
|
9
11
|
EnforcedStyle: double_quotes
|
12
|
+
|
13
|
+
Gemspec/DevelopmentDependencies:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Style/Documentation:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Layout/LineLength:
|
20
|
+
Exclude:
|
21
|
+
- rubyrag.gemspec
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2025-04-10 19:57:10 UTC using RuboCop version 1.75.2.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 1
|
10
|
+
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
|
11
|
+
Metrics/AbcSize:
|
12
|
+
Max: 21
|
13
|
+
|
14
|
+
# Offense count: 1
|
15
|
+
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
|
16
|
+
# AllowedMethods: refine
|
17
|
+
Metrics/BlockLength:
|
18
|
+
Max: 59
|
19
|
+
|
20
|
+
# Offense count: 1
|
21
|
+
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
|
22
|
+
Metrics/MethodLength:
|
23
|
+
Max: 11
|
24
|
+
|
25
|
+
# Offense count: 1
|
26
|
+
# This cop supports safe autocorrection (--autocorrect).
|
27
|
+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings.
|
28
|
+
# URISchemes: http, https
|
29
|
+
Layout/LineLength:
|
30
|
+
Max: 568
|
data/README.md
CHANGED
@@ -1,28 +1,44 @@
|
|
1
1
|
# Rubyrag
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rubyrag`. To experiment with that code, run `bin/console` for an interactive prompt.
|
3
|
+
Seamlessly integrate Cloudflare AutoRag into your Ruby on Rails applications with this gem. It provides a simple and idiomatic Ruby interface for leveraging AutoRag’s automatic retrieval-augmented generation (RAG) pipeline—making it easy to connect your app’s data with powerful AI models using Cloudflare Workers and Vectorize.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
9
|
-
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
10
|
-
|
11
|
-
Install the gem and add to the application's Gemfile by executing:
|
12
7
|
|
13
8
|
```bash
|
14
|
-
bundle add
|
9
|
+
bundle add rubyrag
|
15
10
|
```
|
16
11
|
|
17
12
|
If bundler is not being used to manage dependencies, install the gem by executing:
|
18
13
|
|
19
14
|
```bash
|
20
|
-
gem install
|
15
|
+
gem install rubyrag
|
21
16
|
```
|
22
17
|
|
23
18
|
## Usage
|
24
19
|
|
25
|
-
|
20
|
+
Setup Cloudflare Autorag
|
21
|
+

|
22
|
+
Get API keys for R2
|
23
|
+

|
24
|
+
Get API keys for AI
|
25
|
+

|
26
|
+
Setup rubyrag
|
27
|
+
```ruby
|
28
|
+
client = Rubyrag.new(provider: :cloudflare_auto_rag,
|
29
|
+
bucket: "bucket_name",
|
30
|
+
access_key_id: "access_key_id",
|
31
|
+
secret_access_key: "secret_access_key",
|
32
|
+
r2_endpoint: "http://endpoint.com",
|
33
|
+
autorag_endpoint: "http://endpoint.com",
|
34
|
+
autorag_access_token: "autorag_access_token",)
|
35
|
+
|
36
|
+
# Add file to index
|
37
|
+
client.add(file_path: File.expand_path("file_with_text.txt", __dir__))
|
38
|
+
|
39
|
+
# Query the rag
|
40
|
+
client.query(query: "query")
|
41
|
+
```
|
26
42
|
|
27
43
|
## Development
|
28
44
|
|
@@ -37,3 +53,4 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERN
|
|
37
53
|
## License
|
38
54
|
|
39
55
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
56
|
+
|
Binary file
|
Binary file
|
data/docs/create_rag.png
ADDED
Binary file
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "aws-sdk-s3"
|
4
|
+
require "digest"
|
5
|
+
require "net/http"
|
6
|
+
require "uri"
|
7
|
+
require "json"
|
8
|
+
|
9
|
+
class Rubyrag
|
10
|
+
class Rags
|
11
|
+
class CloudflareAutoRag
|
12
|
+
attr_reader :client, :options
|
13
|
+
|
14
|
+
class Error < StandardError; end
|
15
|
+
|
16
|
+
DEFAULT_OPTIONS = {
|
17
|
+
region: "auto"
|
18
|
+
}.freeze
|
19
|
+
|
20
|
+
def initialize(options)
|
21
|
+
@options = options.merge(DEFAULT_OPTIONS)
|
22
|
+
|
23
|
+
@client = Aws::S3::Client.new(
|
24
|
+
access_key_id: options[:access_key_id],
|
25
|
+
secret_access_key: options[:secret_access_key],
|
26
|
+
endpoint: options[:r2_endpoint],
|
27
|
+
region: "auto"
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
def add(file_path:, key: nil)
|
32
|
+
raise Error, "Passed file: #{file_path}" unless File.exist?(file_path)
|
33
|
+
|
34
|
+
client.put_object(
|
35
|
+
bucket: options[:bucket],
|
36
|
+
key: key || Digest::MD5.file(file_path).hexdigest,
|
37
|
+
content_length: File.size(file_path),
|
38
|
+
body: File.open(file_path)
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
def query(query:)
|
43
|
+
raise Error, "Invalid or empty query provided" unless query.length.positive?
|
44
|
+
|
45
|
+
uri = URI("#{options[:autorag_endpoint]}/ai-search")
|
46
|
+
|
47
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
48
|
+
http.use_ssl = true
|
49
|
+
|
50
|
+
request = Net::HTTP::Post.new(uri.path, {
|
51
|
+
"Content-Type" => "application/json",
|
52
|
+
"Authorization" => "Bearer #{options[:autorag_access_token]}"
|
53
|
+
})
|
54
|
+
|
55
|
+
request.body = { query: query }.to_json
|
56
|
+
|
57
|
+
response = http.request(request)
|
58
|
+
|
59
|
+
JSON.parse(response.body)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/lib/rubyrag.rb
CHANGED
@@ -1,6 +1,26 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require "rubyrag/cloudflare_auto_rag"
|
4
|
+
|
5
|
+
class Rubyrag
|
6
|
+
attr_reader :rag
|
7
|
+
|
4
8
|
class Error < StandardError; end
|
5
|
-
|
9
|
+
|
10
|
+
def initialize(provider:, **options)
|
11
|
+
@rag = case provider
|
12
|
+
when :cloudflare_auto_rag
|
13
|
+
Rubyrag::Rags::CloudflareAutoRag.new(options)
|
14
|
+
else
|
15
|
+
raise Error("Invalid provider: #{provider}")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def add(**options)
|
20
|
+
rag.add(**options)
|
21
|
+
end
|
22
|
+
|
23
|
+
def query(**options)
|
24
|
+
rag.query(**options)
|
25
|
+
end
|
6
26
|
end
|
data/sig/rubyrag.rbs
CHANGED
metadata
CHANGED
@@ -1,14 +1,98 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubyrag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Max Rukomoynikov
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-04-
|
11
|
-
dependencies:
|
10
|
+
date: 2025-04-10 00:00:00.000000000 Z
|
11
|
+
dependencies:
|
12
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: debug
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - ">="
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: 1.0.0
|
19
|
+
type: :development
|
20
|
+
prerelease: false
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - ">="
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: 1.0.0
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: rake
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
- !ruby/object:Gem::Dependency
|
41
|
+
name: rspec
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
type: :development
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
- !ruby/object:Gem::Dependency
|
55
|
+
name: rubocop
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
type: :development
|
62
|
+
prerelease: false
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
name: aws-sdk-s3
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
type: :runtime
|
76
|
+
prerelease: false
|
77
|
+
version_requirements: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
name: libxml-ruby
|
84
|
+
requirement: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
type: :runtime
|
90
|
+
prerelease: false
|
91
|
+
version_requirements: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
12
96
|
description: Seamlessly integrate Cloudflare AutoRag into your Ruby on Rails applications
|
13
97
|
with this gem. It provides a simple and idiomatic Ruby interface for leveraging
|
14
98
|
AutoRag’s automatic retrieval-augmented generation (RAG) pipeline—making it easy
|
@@ -22,12 +106,17 @@ extra_rdoc_files: []
|
|
22
106
|
files:
|
23
107
|
- ".rspec"
|
24
108
|
- ".rubocop.yml"
|
109
|
+
- ".rubocop_todo.yml"
|
25
110
|
- CHANGELOG.md
|
26
111
|
- LICENSE.txt
|
27
112
|
- README.md
|
28
113
|
- Rakefile
|
29
114
|
- docker-compose.yml
|
115
|
+
- docs/create_api_key_for_ai.png
|
116
|
+
- docs/create_api_key_for_r2.png
|
117
|
+
- docs/create_rag.png
|
30
118
|
- lib/rubyrag.rb
|
119
|
+
- lib/rubyrag/cloudflare_auto_rag.rb
|
31
120
|
- sig/rubyrag.rbs
|
32
121
|
homepage: https://github.com/rukomoynikov/rubyrag
|
33
122
|
licenses:
|
@@ -44,7 +133,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
44
133
|
requirements:
|
45
134
|
- - ">="
|
46
135
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
136
|
+
version: 2.7.7
|
48
137
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
138
|
requirements:
|
50
139
|
- - ">="
|