raix 0.8.3 → 0.8.5
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 +6 -0
- data/Gemfile.lock +1 -1
- data/README.md +8 -7
- data/lib/raix/chat_completion.rb +8 -8
- data/lib/raix/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71867dc17116a9f05ab15218ca05c1e76ab95a815e1613ba851ef71155f970c1
|
4
|
+
data.tar.gz: 56987389b0e8e1282603bc08f2fba90b4fe444e2bc43d56a94edd1f7535d03dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18f6a6ab84d743cd04621c39f30563692d048635496a3acfb3f5a20a27fb481cdfc90b116055516430213880c569c413a45752c6e9bdf841026e3311b8c49e9a
|
7
|
+
data.tar.gz: 6c1ad1ec56508974471a24816ae460e0158f605e98d1725f6cef2069749c3d04e5199a5e2f403ad8133e4002ae34e8578abfc74818c30f2d991f0b651573d098
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## [0.8.5] - 2025-05-08
|
2
|
+
- 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)
|
3
|
+
|
4
|
+
## [0.8.4] - 2025-05-07
|
5
|
+
- Calls strip instead of squish on response of chat_completion in order to not clobber linebreaks
|
6
|
+
|
1
7
|
## [0.8.3] - 2025-04-30
|
2
8
|
- Adds optional ActiveSupport Cache parameter to `dispatch_tool_function` for caching tool calls
|
3
9
|
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -136,7 +136,7 @@ Note that for security reasons, dispatching functions only works with functions
|
|
136
136
|
|
137
137
|
#### Tool Filtering
|
138
138
|
|
139
|
-
You can control which
|
139
|
+
You can control which tool functions are exposed to the AI per request using the `available_tools` parameter of the `chat_completion` method:
|
140
140
|
|
141
141
|
```ruby
|
142
142
|
class WeatherAndTime
|
@@ -155,19 +155,19 @@ end
|
|
155
155
|
weather = WeatherAndTime.new
|
156
156
|
|
157
157
|
# Don't pass any tools to the LLM
|
158
|
-
weather.chat_completion(
|
158
|
+
weather.chat_completion(available_tools: false)
|
159
159
|
|
160
160
|
# Only pass specific tools to the LLM
|
161
|
-
weather.chat_completion(
|
161
|
+
weather.chat_completion(available_tools: [:check_weather])
|
162
162
|
|
163
163
|
# Pass all declared tools (default behavior)
|
164
164
|
weather.chat_completion
|
165
165
|
```
|
166
166
|
|
167
|
-
The `
|
167
|
+
The `available_tools` parameter accepts three types of values:
|
168
|
+
- `nil`: All declared tool functions are passed (default behavior)
|
168
169
|
- `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)
|
170
|
+
- An array of symbols: Only the specified tools are passed (raises `Raix::UndeclaredToolError` if a specified tool function is not declared)
|
171
171
|
|
172
172
|
#### Multiple Tool Calls
|
173
173
|
|
@@ -226,6 +226,7 @@ class CustomDispatchExample
|
|
226
226
|
result
|
227
227
|
end
|
228
228
|
end
|
229
|
+
```
|
229
230
|
|
230
231
|
#### Function Call Caching
|
231
232
|
|
@@ -239,7 +240,7 @@ class CachedFunctionExample
|
|
239
240
|
function :expensive_operation do |arguments|
|
240
241
|
"Result of expensive operation with #{arguments}"
|
241
242
|
end
|
242
|
-
|
243
|
+
|
243
244
|
# Override dispatch_tool_function to enable caching for all functions
|
244
245
|
def dispatch_tool_function(function_name, arguments)
|
245
246
|
# Pass the cache to the superclass implementation
|
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
|
@@ -140,7 +140,7 @@ module Raix
|
|
140
140
|
content = res.dig("choices", 0, "message", "content")
|
141
141
|
|
142
142
|
transcript << { assistant: content } if save_response
|
143
|
-
content = content.
|
143
|
+
content = content.strip
|
144
144
|
|
145
145
|
if json
|
146
146
|
# Make automatic JSON parsing available to non-OpenAI providers that don't support the response_format parameter
|
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.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Obie Fernandez
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-05-
|
10
|
+
date: 2025-05-08 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: activesupport
|