raix 0.1.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 87fae4c480456492bf09a09b45843820038052a9c1eb48d24d2b677cd627b754
4
- data.tar.gz: 16138c511c83b121dd0a23058fc46c278de437034b8d51ca44b9b1fc515ff3c3
3
+ metadata.gz: eaf67088dabee6158ede28a1a2279124257313326c9bea8ef3791efe3649e7ca
4
+ data.tar.gz: b35022cc748f4ab851044300ee57dcc5ee317d133bdbf68fb3aeb2a6cbaa4bcd
5
5
  SHA512:
6
- metadata.gz: 931376cc102cee9b3c5e6b9be75132133c9c05ad06cebb56292d5bbe415fa6972c15ab10474e83afaf71d83a32d5440c9d1c9e644a421dd63fc82a1a3e151d5e
7
- data.tar.gz: f510d6af1463f0519d4934dee67fcb3154389cd3b0911a96fe789dd12542b26c027d6f8a1f8910b8de2ba063b0829dc83187f0d0d493a110586be7eb78dbef45
6
+ metadata.gz: 8aa98c05854a5697de357f75bacb649e17f51be6a4fe183dfb227aedb803c01f8001ffed29948af2883f726950fd58706d93410abded42cf25e6139c5fde88a2
7
+ data.tar.gz: f7eda9fc1aaf073d874b9c9d3c3c243605d6799d7c0778f701ae53d8ea339e4ca11ed358a0b66894675d774cdd2561cbdf38471bcd577e3e2638f3db947db609
data/.rubocop.yml CHANGED
@@ -1,5 +1,6 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.6
2
+ SuggestExtensions: false
3
+ TargetRubyVersion: 3.2.1
3
4
 
4
5
  Style/StringLiterals:
5
6
  Enabled: true
@@ -11,3 +12,21 @@ Style/StringLiteralsInInterpolation:
11
12
 
12
13
  Layout/LineLength:
13
14
  Max: 120
15
+
16
+ Metrics/BlockLength:
17
+ Enabled: false
18
+
19
+ Metrics/MethodLength:
20
+ Enabled: false
21
+
22
+ Metrics/ModuleLength:
23
+ Enabled: false
24
+
25
+ Metrics/AbcSize:
26
+ Enabled: false
27
+
28
+ Metrics/CyclomaticComplexity:
29
+ Enabled: false
30
+
31
+ Metrics/PerceivedComplexity:
32
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -2,4 +2,9 @@
2
2
 
3
3
  ## [0.1.0] - 2024-04-03
4
4
 
5
- - Initial release
5
+ - Initial release, placeholder gem
6
+
7
+ ## [0.2.0] - tbd
8
+ - adds `ChatCompletion` module
9
+ - adds `PromptDeclarations` module
10
+ - adds `FunctionDispatch` module
data/Gemfile CHANGED
@@ -2,11 +2,23 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- # Specify your gem's dependencies in raix.gemspec
5
+ # Specify your gem's dependencies in raix-rails.gemspec
6
6
  gemspec
7
7
 
8
- gem "rake", "~> 13.0"
8
+ gem "activesupport", ">= 6.0"
9
+ gem "faraday-retry"
10
+ gem "open_router", "~> 0.3"
11
+ gem "ruby-openai", "~> 7.0"
9
12
 
10
- gem "rspec", "~> 3.0"
11
-
12
- gem "rubocop", "~> 1.21"
13
+ group :development do
14
+ gem "dotenv", ">= 2"
15
+ gem "guard"
16
+ gem "guard-rspec"
17
+ gem "pry", ">= 0.14"
18
+ gem "rake", "~> 13.0"
19
+ gem "rspec", "~> 3.0"
20
+ gem "rubocop", "~> 1.21"
21
+ gem "solargraph-rails", "~> 0.2.0.pre"
22
+ gem "sorbet"
23
+ gem "tapioca", require: false
24
+ end
data/Gemfile.lock CHANGED
@@ -2,22 +2,112 @@ PATH
2
2
  remote: .
3
3
  specs:
4
4
  raix (0.1.0)
5
+ activesupport (>= 6.0)
6
+ open_router (~> 0.2)
5
7
 
6
8
  GEM
7
9
  remote: https://rubygems.org/
8
10
  specs:
11
+ activesupport (7.1.3.4)
12
+ base64
13
+ bigdecimal
14
+ concurrent-ruby (~> 1.0, >= 1.0.2)
15
+ connection_pool (>= 2.2.5)
16
+ drb
17
+ i18n (>= 1.6, < 2)
18
+ minitest (>= 5.1)
19
+ mutex_m
20
+ tzinfo (~> 2.0)
9
21
  ast (2.4.2)
22
+ backport (1.2.0)
23
+ base64 (0.2.0)
24
+ benchmark (0.3.0)
25
+ bigdecimal (3.1.8)
26
+ coderay (1.1.3)
27
+ concurrent-ruby (1.3.3)
28
+ connection_pool (2.4.1)
10
29
  diff-lcs (1.5.1)
30
+ dotenv (3.1.2)
31
+ drb (2.2.1)
32
+ e2mmap (0.1.0)
33
+ erubi (1.13.0)
34
+ event_stream_parser (1.0.0)
35
+ faraday (2.9.2)
36
+ faraday-net_http (>= 2.0, < 3.2)
37
+ faraday-multipart (1.0.4)
38
+ multipart-post (~> 2)
39
+ faraday-net_http (3.1.0)
40
+ net-http
41
+ faraday-retry (2.2.1)
42
+ faraday (~> 2.0)
43
+ ffi (1.17.0-arm64-darwin)
44
+ formatador (1.1.0)
45
+ guard (2.18.1)
46
+ formatador (>= 0.2.4)
47
+ listen (>= 2.7, < 4.0)
48
+ lumberjack (>= 1.0.12, < 2.0)
49
+ nenv (~> 0.1)
50
+ notiffany (~> 0.0)
51
+ pry (>= 0.13.0)
52
+ shellany (~> 0.0)
53
+ thor (>= 0.18.1)
54
+ guard-compat (1.2.1)
55
+ guard-rspec (4.7.3)
56
+ guard (~> 2.1)
57
+ guard-compat (~> 1.1)
58
+ rspec (>= 2.99.0, < 4.0)
59
+ i18n (1.14.5)
60
+ concurrent-ruby (~> 1.0)
61
+ jaro_winkler (1.6.0)
11
62
  json (2.7.1)
63
+ kramdown (2.4.0)
64
+ rexml
65
+ kramdown-parser-gfm (1.1.0)
66
+ kramdown (~> 2.0)
12
67
  language_server-protocol (3.17.0.3)
68
+ listen (3.9.0)
69
+ rb-fsevent (~> 0.10, >= 0.10.3)
70
+ rb-inotify (~> 0.9, >= 0.9.10)
71
+ lumberjack (1.2.10)
72
+ method_source (1.1.0)
73
+ minitest (5.24.0)
74
+ multipart-post (2.4.1)
75
+ mutex_m (0.2.0)
76
+ nenv (0.3.0)
77
+ net-http (0.4.1)
78
+ uri
79
+ netrc (0.11.0)
80
+ nokogiri (1.16.6-arm64-darwin)
81
+ racc (~> 1.4)
82
+ notiffany (0.1.3)
83
+ nenv (~> 0.1)
84
+ shellany (~> 0.0)
85
+ open_router (0.3.3)
86
+ activesupport (>= 6.0)
87
+ dotenv (>= 2)
88
+ faraday (>= 1)
89
+ faraday-multipart (>= 1)
13
90
  parallel (1.24.0)
14
91
  parser (3.3.0.5)
15
92
  ast (~> 2.4.1)
16
93
  racc
94
+ prism (0.30.0)
95
+ pry (0.14.2)
96
+ coderay (~> 1.1)
97
+ method_source (~> 1.0)
17
98
  racc (1.7.3)
18
99
  rainbow (3.1.1)
19
100
  rake (13.2.0)
101
+ rb-fsevent (0.11.2)
102
+ rb-inotify (0.11.1)
103
+ ffi (~> 1.0)
104
+ rbi (0.1.13)
105
+ prism (>= 0.18.0, < 1.0.0)
106
+ sorbet-runtime (>= 0.5.9204)
107
+ rbs (2.8.4)
20
108
  regexp_parser (2.9.0)
109
+ reverse_markdown (2.1.1)
110
+ nokogiri
21
111
  rexml (3.2.6)
22
112
  rspec (3.13.0)
23
113
  rspec-core (~> 3.13.0)
@@ -45,17 +135,82 @@ GEM
45
135
  unicode-display_width (>= 2.4.0, < 3.0)
46
136
  rubocop-ast (1.31.2)
47
137
  parser (>= 3.3.0.4)
138
+ ruby-openai (7.1.0)
139
+ event_stream_parser (>= 0.3.0, < 2.0.0)
140
+ faraday (>= 1)
141
+ faraday-multipart (>= 1)
48
142
  ruby-progressbar (1.13.0)
143
+ shellany (0.0.1)
144
+ solargraph (0.50.0)
145
+ backport (~> 1.2)
146
+ benchmark
147
+ bundler (~> 2.0)
148
+ diff-lcs (~> 1.4)
149
+ e2mmap
150
+ jaro_winkler (~> 1.5)
151
+ kramdown (~> 2.3)
152
+ kramdown-parser-gfm (~> 1.1)
153
+ parser (~> 3.0)
154
+ rbs (~> 2.0)
155
+ reverse_markdown (~> 2.0)
156
+ rubocop (~> 1.38)
157
+ thor (~> 1.0)
158
+ tilt (~> 2.0)
159
+ yard (~> 0.9, >= 0.9.24)
160
+ solargraph-rails (0.2.2.pre.4)
161
+ activesupport
162
+ solargraph (>= 0.41.1)
163
+ sorbet (0.5.11447)
164
+ sorbet-static (= 0.5.11447)
165
+ sorbet-runtime (0.5.11447)
166
+ sorbet-static (0.5.11447-universal-darwin)
167
+ sorbet-static-and-runtime (0.5.11447)
168
+ sorbet (= 0.5.11447)
169
+ sorbet-runtime (= 0.5.11447)
170
+ spoom (1.3.2)
171
+ erubi (>= 1.10.0)
172
+ prism (>= 0.19.0)
173
+ sorbet-static-and-runtime (>= 0.5.10187)
174
+ thor (>= 0.19.2)
175
+ tapioca (0.14.4)
176
+ bundler (>= 2.2.25)
177
+ netrc (>= 0.11.0)
178
+ parallel (>= 1.21.0)
179
+ rbi (>= 0.1.4, < 0.2)
180
+ sorbet-static-and-runtime (>= 0.5.11087)
181
+ spoom (>= 1.2.0)
182
+ thor (>= 1.2.0)
183
+ yard-sorbet
184
+ thor (1.3.1)
185
+ tilt (2.3.0)
186
+ tzinfo (2.0.6)
187
+ concurrent-ruby (~> 1.0)
49
188
  unicode-display_width (2.5.0)
189
+ uri (0.13.0)
190
+ yard (0.9.36)
191
+ yard-sorbet (0.8.1)
192
+ sorbet-runtime (>= 0.5)
193
+ yard (>= 0.9)
50
194
 
51
195
  PLATFORMS
52
196
  arm64-darwin-21
53
197
 
54
198
  DEPENDENCIES
199
+ activesupport (>= 6.0)
200
+ dotenv (>= 2)
201
+ faraday-retry
202
+ guard
203
+ guard-rspec
204
+ open_router (~> 0.3)
205
+ pry (>= 0.14)
55
206
  raix!
56
207
  rake (~> 13.0)
57
208
  rspec (~> 3.0)
58
209
  rubocop (~> 1.21)
210
+ ruby-openai (~> 7.0)
211
+ solargraph-rails (~> 0.2.0.pre)
212
+ sorbet
213
+ tapioca
59
214
 
60
215
  BUNDLED WITH
61
216
  2.4.12
data/README.md CHANGED
@@ -1,34 +1,233 @@
1
- # Raix
1
+ # Ruby AI eXtensions
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
3
+ ## What's Raix
4
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/raix`. To experiment with that code, run `bin/console` for an interactive prompt.
5
+ Raix (pronounced "ray" because the x is silent) is a library that gives you everything you need to add discrete large-language model (LLM) AI components to your Ruby applications. Raix consists of proven code that has been extracted from [Olympia](https://olympia.chat), the world's leading virtual AI team platform, and probably one of the biggest and most successful AI chat projects written completely in Ruby.
6
6
 
7
- ## Installation
7
+ Understanding the how to use discrete AI components in otherwise normal code is key to productively leveraging Raix, and the subject of a book written by Raix's author Obie Fernandez, titled [Patterns of Application Development Using AI](https://leanpub.com/patterns-of-application-development-using-ai). You can easily support the ongoing development of this project by buying the book at Leanpub.
8
+
9
+ At the moment, Raix natively supports use of either OpenAI or OpenRouter as its underlying AI provider. Eventually you will be able to specify your AI provider via an adapter, kind of like ActiveRecord maps to databases. Note that you can also use Raix to add AI capabilities to non-Rails applications as long as you include ActiveSupport as a dependency. Extracting the base code to its own standalone library without Rails dependencies is on the roadmap, but not a high priority.
10
+
11
+ ### Chat Completions
12
+
13
+ Raix consists of three modules that can be mixed in to Ruby classes to give them AI powers. The first (and mandatory) module is `ChatCompletion`, which provides `transcript` and `chat_completion` methods.
14
+
15
+ ```ruby
16
+ class MeaningOfLife
17
+ include Raix::ChatCompletion
18
+ end
19
+
20
+ >> ai = MeaningOfLife.new
21
+ >> ai.transcript << { user: "What is the meaning of life?" }
22
+ >> ai.chat_completion
23
+
24
+ => "The question of the meaning of life is one of the most profound and enduring inquiries in philosophy, religion, and science.
25
+ Different perspectives offer various answers..."
26
+
27
+ ```
28
+
29
+ #### Transcript Format
30
+
31
+ The transcript accepts both abbreviated and standard OpenAI message hash formats. The abbreviated format, suitable for system, assistant, and user messages is simply a mapping of `role => content`, as show in the example above.
32
+
33
+ ```ruby
34
+ transcript << { user: "What is the meaning of life?" }
35
+ ```
36
+
37
+ As mentioned, Raix also understands standard OpenAI messages hashes. The previous example could be written as:
38
+
39
+ ```ruby
40
+ transcript << { role: "user", content: "What is the meaning of life?" }
41
+ ```
42
+
43
+ One of the advantages of OpenRouter and the reason that it is used by default by this library is that it handles mapping message formats from the OpenAI standard to whatever other model you're wanting to use (Anthropic, Cohere, etc.)
44
+
45
+ ### Use of Tools/Functions
46
+
47
+ The second (optional) module that you can add to your Ruby classes after `ChatCompletion` is `FunctionDispatch`. It lets you declare and implement functions to be called at the AI's discretion as part of a chat completion "loop" in a declarative, Rails-like "DSL" fashion.
48
+
49
+ Most end-user facing AI components that include functions should be invoked using `chat_completion(loop: true)`, so that the results of each function call are added to the transcript and chat completion is triggered again. The looping will continue until the AI generates a plain text response.
50
+
51
+ ```ruby
52
+ class WhatIsTheWeather
53
+ include Raix::ChatCompletion
54
+ include Raix::FunctionDispatch
55
+
56
+ function :check_weather, "Check the weather for a location", location: { type: "string" } do |arguments|
57
+ "The weather in #{arguments[:location]} is hot and sunny"
58
+ end
59
+ end
60
+
61
+ RSpec.describe WhatIsTheWeather do
62
+ subject { described_class.new }
63
+
64
+ it "can call a function and loop to provide text response" do
65
+ subject.transcript << { user: "What is the weather in Zipolite, Oaxaca?" }
66
+ response = subject.chat_completion(openai: "gpt-4o", loop: true)
67
+ expect(response).to include("hot and sunny")
68
+ end
69
+ end
70
+ ```
71
+
72
+ #### Manually Stopping a Loop
73
+
74
+ To loop AI components that don't interact with end users, at least one function block should invoke `stop_looping!` whenever you're ready to stop processing.
75
+
76
+ ```ruby
77
+ class OrderProcessor
78
+ include Raix::ChatCompletion
79
+ include Raix::FunctionDispatch
80
+
81
+ SYSTEM_DIRECTIVE = "You are an order processor, tasked with order validation, inventory check,
82
+ payment processing, and shipping."
83
+
84
+ attr_accessor :order
85
+
86
+ def initialize(order)
87
+ self.order = order
88
+ transcript << { system: SYSTEM_DIRECTIVE }
89
+ transcript << { user: order.to_json }
90
+ end
91
+
92
+ def perform
93
+ # will continue looping until `stop_looping!` is called
94
+ chat_completion(loop: true)
95
+ end
96
+
97
+
98
+ # implementation of functions that can be called by the AI
99
+ # entirely at its discretion, depending on the needs of the order.
100
+ # The return value of each `perform` method will be added to the
101
+ # transcript of the conversation as a function result.
102
+
103
+ function :validate_order do
104
+ OrderValidationWorker.perform(@order)
105
+ end
106
+
107
+ function :check_inventory do
108
+ InventoryCheckWorker.perform(@order)
109
+ end
110
+
111
+ function :process_payment do
112
+ PaymentProcessingWorker.perform(@order)
113
+ end
8
114
 
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_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.
115
+ function :schedule_shipping do
116
+ ShippingSchedulerWorker.perform(@order)
117
+ end
118
+
119
+ function :send_confirmation do
120
+ OrderConfirmationWorker.perform(@order)
121
+ end
122
+
123
+ function :finished_processing do
124
+ order.update!(transcript:, processed_at: Time.current)
125
+ stop_looping!
126
+ end
127
+ end
128
+ ```
129
+
130
+ ### Prompt Declarations
131
+
132
+ The third (also optional) module that you can add mix in along with `ChatCompletion` is `PromptDeclarations`. It provides the ability to declare a "Prompt Chain" (series of prompts to be called in a sequence), and also features a declarative, Rails-like "DSL" of its own. Prompts can be defined inline or delegate to callable prompt objects, which themselves implement `ChatCompletion`.
133
+
134
+ The following example is a rough excerpt of the main "Conversation Loop" in Olympia, which pre-processes user messages to check for
135
+ the presence of URLs and scan memory before submitting as a prompt to GPT-4. Note that prompt declarations are executed in the order
136
+ that they are declared. The `FetchUrlCheck` callable prompt class is included for instructional purposes. Note that it is passed the
137
+ an instance of the object that is calling it in its initializer as its `context`. The passing of context means that you can assemble
138
+ composite prompt structures of arbitrary depth.
139
+
140
+ ```ruby
141
+ class PromptSubscriber
142
+ include Raix::ChatCompletion
143
+ include Raix::PromptDeclarations
144
+
145
+ attr_accessor :conversation, :bot_message, :user_message
146
+
147
+ # many other declarations ommitted...
148
+
149
+ prompt call: FetchUrlCheck
150
+
151
+ prompt call: MemoryScan
152
+
153
+ prompt text: -> { user_message.content }, stream: -> { ReplyStream.new(self) }, until: -> { bot_message.complete? }
154
+
155
+ def initialize(conversation)
156
+ self.conversation = conversation
157
+ end
158
+
159
+ def message_created(user_message)
160
+ self.user_message = user_message
161
+ self.bot_message = conversation.bot_message!(responding_to: user_message)
162
+
163
+ chat_completion(loop: true, openai: "gpt-4o")
164
+ end
165
+
166
+ ...
167
+
168
+ end
169
+
170
+ class FetchUrlCheck
171
+ include ChatCompletion
172
+ include FunctionDispatch
173
+
174
+ REGEX = %r{\b(?:http(s)?://)?(?:www\.)?[a-zA-Z0-9-]+(\.[a-zA-Z]{2,})+(/[^\s]*)?\b}
175
+
176
+ attr_accessor :context, :conversation
177
+
178
+ delegate :user_message, to: :context
179
+ delegate :content, to: :user_message
180
+
181
+ def initialize(context)
182
+ self.context = context
183
+ self.conversation = context.conversation
184
+ self.model = "anthropic/claude-3-haiku"
185
+ end
186
+
187
+ def call
188
+ return unless content&.match?(REGEX)
189
+
190
+ transcript << { system: "Call the `fetch` function if the user mentions a website, otherwise say nil" }
191
+ transcript << { user: content }
192
+
193
+ chat_completion # TODO: consider looping to fetch more than one URL per user message
194
+ end
195
+
196
+ function :fetch, "Gets the plain text contents of a web page", url: { type: "string" } do |arguments|
197
+ Tools::FetchUrl.fetch(arguments[:url]).tap do |result|
198
+ parent = conversation.function_call!("fetch_url", arguments, parent: user_message)
199
+ conversation.function_result!("fetch_url", result, parent:)
200
+ end
201
+ end
202
+
203
+ ```
204
+
205
+ Notably, Olympia does not use the `FunctionDispatch` module in its primary conversation loop because it does not have a fixed set of tools that are included in every single prompt. Functions are made available dynamically based on a number of factors including the user's plan tier and capabilities of the assistant with whom the user is conversing.
206
+
207
+ Streaming of the AI's response to the end user is handled by the `ReplyStream` class, passed to the final prompt declaration as its `stream` parameter. [Patterns of Application Development Using AI](https://leanpub.com/patterns-of-application-development-using-ai) devotes a whole chapter to describing how to write your own `ReplyStream` class.
208
+
209
+ ## Installation
10
210
 
11
211
  Install the gem and add to the application's Gemfile by executing:
12
212
 
13
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
213
+ $ bundle add raix
14
214
 
15
215
  If bundler is not being used to manage dependencies, install the gem by executing:
16
216
 
17
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
217
+ $ gem install raix
18
218
 
19
- ## Usage
20
-
21
- TODO: Write usage instructions here
22
219
 
23
220
  ## Development
24
221
 
25
222
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
223
 
224
+ Specs require `OR_ACCESS_TOKEN` and `OAI_ACCESS_TOKEN` environment variables, for access to OpenRouter and OpenAI, respectively. You can add those keys to a local unversionsed `.env` file and they will be picked up by the `dotenv` gem.
225
+
27
226
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
227
 
29
228
  ## Contributing
30
229
 
31
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/raix. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/raix/blob/main/CODE_OF_CONDUCT.md).
230
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[OlympiaAI]/raix. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[OlympiaAI]/raix/blob/main/CODE_OF_CONDUCT.md).
32
231
 
33
232
  ## License
34
233
 
@@ -36,4 +235,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
36
235
 
37
236
  ## Code of Conduct
38
237
 
39
- Everyone interacting in the Raix project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/raix/blob/main/CODE_OF_CONDUCT.md).
238
+ Everyone interacting in the Raix::Rails project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[OlympiaAI]/raix/blob/main/CODE_OF_CONDUCT.md).
data/lib/raix/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Raix
4
- VERSION = "0.1.0"
4
+ VERSION = "0.3.1"
5
5
  end
data/lib/raix.rb CHANGED
@@ -1,8 +1,54 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "raix/version"
4
+ require_relative "raix/chat_completion"
5
+ require_relative "raix/function_dispatch"
6
+ require_relative "raix/prompt_declarations"
4
7
 
8
+ # The Raix module provides configuration options for the Raix gem.
5
9
  module Raix
6
- class Error < StandardError; end
7
- # Your code goes here...
10
+ # The Configuration class holds the configuration options for the Raix gem.
11
+ class Configuration
12
+ # The temperature option determines the randomness of the generated text.
13
+ # Higher values result in more random output.
14
+ attr_accessor :temperature
15
+
16
+ # The max_tokens option determines the maximum number of tokens to generate.
17
+ attr_accessor :max_tokens
18
+
19
+ # The model option determines the model to use for text generation. This option
20
+ # is normally set in each class that includes the ChatCompletion module.
21
+ attr_accessor :model
22
+
23
+ # The openrouter_client option determines the default client to use for communicatio.
24
+ attr_accessor :openrouter_client
25
+
26
+ # The openai_client option determines the OpenAI client to use for communication.
27
+ attr_accessor :openai_client
28
+
29
+ DEFAULT_MAX_TOKENS = 1000
30
+ DEFAULT_MODEL = "meta-llama/llama-3-8b-instruct:free"
31
+ DEFAULT_TEMPERATURE = 0.0
32
+
33
+ # Initializes a new instance of the Configuration class with default values.
34
+ def initialize
35
+ self.temperature = DEFAULT_TEMPERATURE
36
+ self.max_tokens = DEFAULT_MAX_TOKENS
37
+ self.model = DEFAULT_MODEL
38
+ end
39
+ end
40
+
41
+ class << self
42
+ attr_writer :configuration
43
+ end
44
+
45
+ # Returns the current configuration instance.
46
+ def self.configuration
47
+ @configuration ||= Configuration.new
48
+ end
49
+
50
+ # Configures the Raix gem using a block.
51
+ def self.configure
52
+ yield(configuration)
53
+ end
8
54
  end
data/raix.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.summary = "Ruby AI eXtensions"
12
12
  spec.homepage = "https://github.com/OlympiaAI/raix"
13
13
  spec.license = "MIT"
14
- spec.required_ruby_version = ">= 3.2.1"
14
+ spec.required_ruby_version = ">= 3.2.2"
15
15
 
16
16
  spec.metadata["homepage_uri"] = spec.homepage
17
17
  spec.metadata["source_code_uri"] = "https://github.com/OlympiaAI/raix"
@@ -28,9 +28,6 @@ Gem::Specification.new do |spec|
28
28
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
29
29
  spec.require_paths = ["lib"]
30
30
 
31
- # Uncomment to register a new dependency of your gem
32
- # spec.add_dependency "example-gem", "~> 1.0"
33
-
34
- # For more information and examples about making a new gem, check out our
35
- # guide at: https://bundler.io/guides/creating_gem.html
31
+ spec.add_dependency "activesupport", ">= 6.0"
32
+ spec.add_dependency "open_router", "~> 0.2"
36
33
  end
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: raix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Obie Fernandez
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-04-03 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2024-06-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '6.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '6.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: open_router
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.2'
13
41
  description:
14
42
  email:
15
43
  - obiefernandez@gmail.com
@@ -45,14 +73,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
45
73
  requirements:
46
74
  - - ">="
47
75
  - !ruby/object:Gem::Version
48
- version: 3.2.1
76
+ version: 3.2.2
49
77
  required_rubygems_version: !ruby/object:Gem::Requirement
50
78
  requirements:
51
79
  - - ">="
52
80
  - !ruby/object:Gem::Version
53
81
  version: '0'
54
82
  requirements: []
55
- rubygems_version: 3.4.12
83
+ rubygems_version: 3.4.10
56
84
  signing_key:
57
85
  specification_version: 4
58
86
  summary: Ruby AI eXtensions