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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 77197d6de1d77373260029d955fd0110990b7c562a279d887130ee4f95909377
4
- data.tar.gz: d811d21316bba7c92797dff98c044871ec4382998b77090f29348217156698df
3
+ metadata.gz: f28d49373248dcc8209a5c4c3678c632953aab2282f3f71a887ee1e2b3e7d249
4
+ data.tar.gz: bacd7d9ef9b7aff8ab6b998d1ddb2efe3fd3dfa5855d8d5851161a271b056963
5
5
  SHA512:
6
- metadata.gz: 9a513c9c82ef57ba4beb9681a02111a5207c9418b6f0b26015e9ad299d889b8a65644d594c11246ff7c70a5354419fc3932a8a776072757e615b8afbfc48ca98
7
- data.tar.gz: ab0743ed3d99efd20886053b2d7648fc6dec7b551d48c5f86fee9689441dfbda0280e0c693766fa8f03c944f7dbfc459c8301f2b3bb969de47e3f4bbfbf23d0b
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- raix (0.8.4)
4
+ raix (0.8.6)
5
5
  activesupport (>= 6.0)
6
6
  faraday-retry (~> 2.0)
7
7
  open_router (~> 0.2)
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, "Check the weather for a location", location: { type: "string" } do |arguments|
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 tools are available to the AI on a given chat completion request using the `tools` parameter in the `chat_completion` method:
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(tools: false)
162
+ weather.chat_completion(available_tools: false)
159
163
 
160
164
  # Only pass specific tools to the LLM
161
- weather.chat_completion(tools: [:check_weather])
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 `tools` parameter accepts three types of values:
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 any tool is not declared)
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
 
@@ -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] :tools (nil) Tools to pass to the LLM. If false, no tools are passed. If an array, only declared tools in the array are passed.
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, tools: 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 tools == false
69
+ params[:tools] = if available_tools == false
70
70
  nil
71
- elsif tools.is_a?(Array)
72
- filtered_tools(tools)
71
+ elsif available_tools.is_a?(Array)
72
+ filtered_tools(available_tools)
73
73
  else
74
- self.tools.presence
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
- { name:, parameters: { type: "object", properties: {} } }.tap do |definition|
49
+ {
50
+ name:,
51
+ parameters: { type: "object", properties: {}, required: [] }
52
+ }.tap do |definition|
50
53
  definition[:description] = description if description.present?
51
- parameters.map do |key, value|
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Raix
4
- VERSION = "0.8.4"
4
+ VERSION = "0.8.6"
5
5
  end
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
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: 2025-05-07 00:00:00.000000000 Z
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.2
118
+ rubygems_version: 3.6.8
119
119
  specification_version: 4
120
120
  summary: Ruby AI eXtensions
121
121
  test_files: []