raix 0.7 → 0.7.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/CHANGELOG.md +0 -1
- data/Gemfile.lock +1 -1
- data/README.md +35 -20
- data/lib/raix/function_dispatch.rb +1 -5
- 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: 9a2990e8225edcfbcc5007aae41a0dd69987bff18bd085bb9c486561e5597044
|
4
|
+
data.tar.gz: 60ef3efa8eb6cbe1b445afd09fc65a4b1d6fc62c872588956baee46b511d79d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dfa0a7dfed2782d49c95f749c847b024ef41097b4ab318b34f9eabbfd9f754cf49c6eb859c1b14534332efea930d707df457e2d24a4c1f30f043d7dacb3c801c
|
7
|
+
data.tar.gz: 2e291a98b2ed5e25c2381a30d609e4277cb94458531c03e77b79fc95e70ee92e40c0d9cacb31809a1f7acca860550e4d02698856321869144dc56a4d794ea3d8
|
data/CHANGELOG.md
CHANGED
@@ -16,7 +16,6 @@
|
|
16
16
|
- adds support for `execute_ai_request` in `PromptDeclarations` to handle API calls
|
17
17
|
- adds support for `chat_completion_from_superclass` in `PromptDeclarations` to handle superclass calls
|
18
18
|
- adds support for `model`, `temperature`, and `max_tokens` in `PromptDeclarations` to access prompt parameters
|
19
|
-
- fixes function return values in `FunctionDispatch` to properly return results from tool calls (thanks @ttilberg)
|
20
19
|
- Make automatic JSON parsing available to non-OpenAI providers that don't support the response_format parameter by scanning for json XML tags
|
21
20
|
|
22
21
|
## [0.6.0] - 2024-11-12
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -78,6 +78,26 @@ Note that there is a limit of four breakpoints, and the cache will expire within
|
|
78
78
|
},
|
79
79
|
```
|
80
80
|
|
81
|
+
### JSON Mode
|
82
|
+
|
83
|
+
Raix supports JSON mode for chat completions, which ensures that the AI model's response is valid JSON. This is particularly useful when you need structured data from the model.
|
84
|
+
|
85
|
+
When using JSON mode with OpenAI models, Raix will automatically set the `response_format` parameter on requests accordingly, and attempt to parse the entire response body as JSON.
|
86
|
+
When using JSON mode with other models (e.g. Anthropic) that don't support `response_format`, Raix will look for JSON content inside of <json> XML tags in the response, before
|
87
|
+
falling back to parsing the entire response body. Make sure you tell the AI to reply with JSON inside of XML tags.
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
>> my_class.chat_completion(json: true)
|
91
|
+
=> { "key": "value" }
|
92
|
+
```
|
93
|
+
|
94
|
+
When using JSON mode with non-OpenAI providers, Raix automatically sets the `require_parameters` flag to ensure proper JSON formatting. You can also combine JSON mode with other parameters:
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
>> my_class.chat_completion(json: true, openai: "gpt-4o")
|
98
|
+
=> { "key": "value" }
|
99
|
+
```
|
100
|
+
|
81
101
|
### Use of Tools/Functions
|
82
102
|
|
83
103
|
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.
|
@@ -109,44 +129,39 @@ Note that for security reasons, dispatching functions only works with functions
|
|
109
129
|
|
110
130
|
#### Multiple Tool Calls
|
111
131
|
|
112
|
-
Some AI models (like GPT-4) can make multiple tool calls in a single response. When this happens, Raix will automatically handle all the function calls sequentially
|
132
|
+
Some AI models (like GPT-4) can make multiple tool calls in a single response. When this happens, Raix will automatically handle all the function calls sequentially.
|
133
|
+
If you need to capture the arguments to the function calls, do so in the block passed to `function`. The response from `chat_completion` is always the final text
|
134
|
+
response from the assistant, and is not affected by function calls.
|
113
135
|
|
114
136
|
```ruby
|
115
137
|
class MultipleToolExample
|
116
138
|
include Raix::ChatCompletion
|
117
139
|
include Raix::FunctionDispatch
|
118
140
|
|
141
|
+
attr_reader :invocations
|
142
|
+
|
119
143
|
function :first_tool do |arguments|
|
144
|
+
@invocations << :first
|
120
145
|
"Result from first tool"
|
121
146
|
end
|
122
147
|
|
123
148
|
function :second_tool do |arguments|
|
149
|
+
@invocations << :second
|
124
150
|
"Result from second tool"
|
125
151
|
end
|
152
|
+
|
153
|
+
def initialize
|
154
|
+
@invocations = []
|
155
|
+
end
|
126
156
|
end
|
127
157
|
|
128
158
|
example = MultipleToolExample.new
|
129
159
|
example.transcript << { user: "Please use both tools" }
|
130
|
-
|
131
|
-
# =>
|
132
|
-
```
|
133
|
-
|
134
|
-
Note that as of version 0.6.1, function return values are properly returned from tool calls, whether in single or multiple tool call scenarios. This means you can use the return values from your functions in your application logic.
|
135
|
-
|
136
|
-
```ruby
|
137
|
-
class DiceRoller
|
138
|
-
include Raix::ChatCompletion
|
139
|
-
include Raix::FunctionDispatch
|
140
|
-
|
141
|
-
function :roll_dice, "Roll a die with specified number of faces", faces: { type: :integer } do |arguments|
|
142
|
-
rand(1..arguments[:faces])
|
143
|
-
end
|
144
|
-
end
|
160
|
+
example.chat_completion(openai: "gpt-4o")
|
161
|
+
# => "I used both tools, as requested"
|
145
162
|
|
146
|
-
|
147
|
-
|
148
|
-
results = roller.chat_completion(openai: "gpt-4o")
|
149
|
-
# => [15, 7] # Actual random dice roll results
|
163
|
+
example.invocations
|
164
|
+
# => [:first, :second]
|
150
165
|
```
|
151
166
|
|
152
167
|
#### Manually Stopping a Loop
|
@@ -70,7 +70,7 @@ module Raix
|
|
70
70
|
}
|
71
71
|
]
|
72
72
|
}
|
73
|
-
|
73
|
+
instance_exec(arguments, &block).tap do |content|
|
74
74
|
transcript << {
|
75
75
|
role: "tool",
|
76
76
|
tool_call_id: id,
|
@@ -81,10 +81,6 @@ module Raix
|
|
81
81
|
end
|
82
82
|
|
83
83
|
chat_completion(**chat_completion_args) if loop
|
84
|
-
|
85
|
-
# Return the result of the function call in case that's what the caller wants
|
86
|
-
# https://github.com/OlympiaAI/raix/issues/16
|
87
|
-
result
|
88
84
|
end
|
89
85
|
end
|
90
86
|
end
|
data/lib/raix/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: raix
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.7.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: 2025-04-
|
11
|
+
date: 2025-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|