raix 0.8.4 → 0.8.6
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/CHANGELOG.md +9 -0
- data/Gemfile.lock +1 -1
- data/README.md +11 -7
- data/lib/raix/chat_completion.rb +7 -7
- data/lib/raix/function_dispatch.rb +12 -2
- data/lib/raix/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f28d49373248dcc8209a5c4c3678c632953aab2282f3f71a887ee1e2b3e7d249
|
4
|
+
data.tar.gz: bacd7d9ef9b7aff8ab6b998d1ddb2efe3fd3dfa5855d8d5851161a271b056963
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7a75b0c7c8f9ecfcbae002e6b5dfea7cee17be8d3d8825dacf2276f200f9bb542e0ccc4f7bb402b03b57d0240d84431bba3d749657a51ef4a90e937fd096633
|
7
|
+
data.tar.gz: b367bdd61f7c7fb269232387c0d31af1cb2315d9bed8abc16758931851dab4b849139cb23e1c2c4236f8e8ced55368726db8c2a308efa3b6db503290d07165c2
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
## [0.8.6] - 2025-05-19
|
2
|
+
- add `required` and `optional` flags for parameters in `function` declarations
|
3
|
+
|
4
|
+
## [0.8.5] - 2025-05-08
|
5
|
+
- renamed `tools` argument to `chat_completion` to `available_tools` to prevent shadowing the existing tool attribute (potentially breaking change to enhancement introduced in 0.8.1)
|
6
|
+
|
7
|
+
## [0.8.4] - 2025-05-07
|
8
|
+
- Calls strip instead of squish on response of chat_completion in order to not clobber linebreaks
|
9
|
+
|
1
10
|
## [0.8.3] - 2025-04-30
|
2
11
|
- Adds optional ActiveSupport Cache parameter to `dispatch_tool_function` for caching tool calls
|
3
12
|
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -116,7 +116,9 @@ class WhatIsTheWeather
|
|
116
116
|
include Raix::ChatCompletion
|
117
117
|
include Raix::FunctionDispatch
|
118
118
|
|
119
|
-
function :check_weather,
|
119
|
+
function :check_weather,
|
120
|
+
"Check the weather for a location",
|
121
|
+
location: { type: "string", required: true } do |arguments|
|
120
122
|
"The weather in #{arguments[:location]} is hot and sunny"
|
121
123
|
end
|
122
124
|
end
|
@@ -132,11 +134,13 @@ RSpec.describe WhatIsTheWeather do
|
|
132
134
|
end
|
133
135
|
```
|
134
136
|
|
137
|
+
Parameters are optional by default. Mark them as required with `required: true` or explicitly optional with `optional: true`.
|
138
|
+
|
135
139
|
Note that for security reasons, dispatching functions only works with functions implemented using `Raix::FunctionDispatch#function` or directly on the class.
|
136
140
|
|
137
141
|
#### Tool Filtering
|
138
142
|
|
139
|
-
You can control which
|
143
|
+
You can control which tool functions are exposed to the AI per request using the `available_tools` parameter of the `chat_completion` method:
|
140
144
|
|
141
145
|
```ruby
|
142
146
|
class WeatherAndTime
|
@@ -155,19 +159,19 @@ end
|
|
155
159
|
weather = WeatherAndTime.new
|
156
160
|
|
157
161
|
# Don't pass any tools to the LLM
|
158
|
-
weather.chat_completion(
|
162
|
+
weather.chat_completion(available_tools: false)
|
159
163
|
|
160
164
|
# Only pass specific tools to the LLM
|
161
|
-
weather.chat_completion(
|
165
|
+
weather.chat_completion(available_tools: [:check_weather])
|
162
166
|
|
163
167
|
# Pass all declared tools (default behavior)
|
164
168
|
weather.chat_completion
|
165
169
|
```
|
166
170
|
|
167
|
-
The `
|
171
|
+
The `available_tools` parameter accepts three types of values:
|
172
|
+
- `nil`: All declared tool functions are passed (default behavior)
|
168
173
|
- `false`: No tools are passed to the LLM
|
169
|
-
- An array of symbols: Only the specified tools are passed (raises `Raix::UndeclaredToolError` if
|
170
|
-
- Not provided: All declared tools are passed (default behavior)
|
174
|
+
- An array of symbols: Only the specified tools are passed (raises `Raix::UndeclaredToolError` if a specified tool function is not declared)
|
171
175
|
|
172
176
|
#### Multiple Tool Calls
|
173
177
|
|
data/lib/raix/chat_completion.rb
CHANGED
@@ -36,7 +36,7 @@ module Raix
|
|
36
36
|
|
37
37
|
attr_accessor :cache_at, :frequency_penalty, :logit_bias, :logprobs, :loop, :min_p, :model, :presence_penalty,
|
38
38
|
:prediction, :repetition_penalty, :response_format, :stream, :temperature, :max_completion_tokens,
|
39
|
-
:max_tokens, :seed, :stop, :top_a, :top_k, :top_logprobs, :top_p, :tools, :tool_choice, :provider
|
39
|
+
:max_tokens, :seed, :stop, :top_a, :top_k, :top_logprobs, :top_p, :tools, :available_tools, :tool_choice, :provider
|
40
40
|
|
41
41
|
# This method performs chat completion based on the provided transcript and parameters.
|
42
42
|
#
|
@@ -46,9 +46,9 @@ module Raix
|
|
46
46
|
# @option params [Boolean] :openai (false) Whether to use OpenAI's API instead of OpenRouter's.
|
47
47
|
# @option params [Boolean] :raw (false) Whether to return the raw response or dig the text content.
|
48
48
|
# @option params [Array] :messages (nil) An array of messages to use instead of the transcript.
|
49
|
-
# @option tools [Array|false] :
|
49
|
+
# @option tools [Array|false] :available_tools (nil) Tools to pass to the LLM. Ignored if nil (default). If false, no tools are passed. If an array, only declared tools in the array are passed.
|
50
50
|
# @return [String|Hash] The completed chat response.
|
51
|
-
def chat_completion(params: {}, loop: false, json: false, raw: false, openai: false, save_response: true, messages: nil,
|
51
|
+
def chat_completion(params: {}, loop: false, json: false, raw: false, openai: false, save_response: true, messages: nil, available_tools: nil)
|
52
52
|
# set params to default values if not provided
|
53
53
|
params[:cache_at] ||= cache_at.presence
|
54
54
|
params[:frequency_penalty] ||= frequency_penalty.presence
|
@@ -66,12 +66,12 @@ module Raix
|
|
66
66
|
params[:stop] ||= stop.presence
|
67
67
|
params[:temperature] ||= temperature.presence || Raix.configuration.temperature
|
68
68
|
params[:tool_choice] ||= tool_choice.presence
|
69
|
-
params[:tools] = if
|
69
|
+
params[:tools] = if available_tools == false
|
70
70
|
nil
|
71
|
-
elsif
|
72
|
-
filtered_tools(
|
71
|
+
elsif available_tools.is_a?(Array)
|
72
|
+
filtered_tools(available_tools)
|
73
73
|
else
|
74
|
-
|
74
|
+
tools.presence
|
75
75
|
end
|
76
76
|
params[:top_a] ||= top_a.presence
|
77
77
|
params[:top_k] ||= top_k.presence
|
@@ -46,11 +46,21 @@ module Raix
|
|
46
46
|
def function(name, description = nil, **parameters, &block)
|
47
47
|
@functions ||= []
|
48
48
|
@functions << begin
|
49
|
-
{
|
49
|
+
{
|
50
|
+
name:,
|
51
|
+
parameters: { type: "object", properties: {}, required: [] }
|
52
|
+
}.tap do |definition|
|
50
53
|
definition[:description] = description if description.present?
|
51
|
-
parameters.
|
54
|
+
parameters.each do |key, value|
|
55
|
+
value = value.dup
|
56
|
+
required = value.delete(:required)
|
57
|
+
optional = value.delete(:optional)
|
52
58
|
definition[:parameters][:properties][key] = value
|
59
|
+
if required || optional == false
|
60
|
+
definition[:parameters][:required] << key
|
61
|
+
end
|
53
62
|
end
|
63
|
+
definition[:parameters].delete(:required) if definition[:parameters][:required].empty?
|
54
64
|
end
|
55
65
|
end
|
56
66
|
|
data/lib/raix/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: raix
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Obie Fernandez
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: activesupport
|
@@ -115,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
115
|
- !ruby/object:Gem::Version
|
116
116
|
version: '0'
|
117
117
|
requirements: []
|
118
|
-
rubygems_version: 3.6.
|
118
|
+
rubygems_version: 3.6.8
|
119
119
|
specification_version: 4
|
120
120
|
summary: Ruby AI eXtensions
|
121
121
|
test_files: []
|