raix 0.4.7 → 0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +2 -1
- data/README.md +2 -0
- data/lib/raix/chat_completion.rb +5 -2
- data/lib/raix/predicate.rb +12 -5
- 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: 7537dc5f13d858d6fdd7e5fcdeb60e1d5fd99e0f2aa84e618096f959f2c44ed1
|
4
|
+
data.tar.gz: 8af2e5eb06b2fdaf2c4da8e9b9df28750c6c449d63e5eec25478d61068de2742
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a76e3c1ac764735f05b603c83f6410c5d83274e0d8ef5b80e6a08dfb4ca2338ed324b14db3b4383399ebbd9a88d76615deed4ad8533592ac3dee2ccc84f1ab6d
|
7
|
+
data.tar.gz: c4c89a3d2feac21a80dd1be7f4c0626f48a09756af55b0f38dd0abc769ec4cdb989ae210baabcbbb896f869ec79dd1e26454cecd5df28ee3ff016661d612e7c3
|
data/CHANGELOG.md
CHANGED
@@ -32,3 +32,7 @@
|
|
32
32
|
## [0.4.7] - 2024-11-12
|
33
33
|
- adds missing requires `raix/predicate` so that it can be used in a Rails app automatically
|
34
34
|
- adds missing openai support for `Predicate`
|
35
|
+
|
36
|
+
## [0.4.8] - 2024-11-12
|
37
|
+
- adds documentation for `Predicate` maybe handler
|
38
|
+
- logs to stdout when a response is unhandled by `Predicate`
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
raix (0.
|
4
|
+
raix (0.5)
|
5
5
|
activesupport (>= 6.0)
|
6
6
|
open_router (~> 0.2)
|
7
7
|
ruby-openai (~> 7.0)
|
@@ -211,6 +211,7 @@ GEM
|
|
211
211
|
PLATFORMS
|
212
212
|
arm64-darwin-21
|
213
213
|
arm64-darwin-22
|
214
|
+
arm64-darwin-24
|
214
215
|
x86_64-linux
|
215
216
|
|
216
217
|
DEPENDENCIES
|
data/README.md
CHANGED
@@ -101,6 +101,8 @@ RSpec.describe WhatIsTheWeather do
|
|
101
101
|
end
|
102
102
|
```
|
103
103
|
|
104
|
+
Note that for security reasons, dispatching functions only works with functions implemented using `Raix::FunctionDispatch#function` or directly on the class.
|
105
|
+
|
104
106
|
#### Multiple Tool Calls
|
105
107
|
|
106
108
|
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 and return an array of their results. Here's an example:
|
data/lib/raix/chat_completion.rb
CHANGED
@@ -110,7 +110,10 @@ module Raix
|
|
110
110
|
return tool_calls.map do |tool_call|
|
111
111
|
# dispatch the called function
|
112
112
|
arguments = JSON.parse(tool_call["function"]["arguments"].presence || "{}")
|
113
|
-
|
113
|
+
function_name = tool_call["function"]["name"]
|
114
|
+
raise "Unauthorized function call: #{function_name}" unless self.class.functions.map { |f| f[:name].to_sym }.include?(function_name.to_sym)
|
115
|
+
|
116
|
+
send(function_name, arguments.with_indifferent_access)
|
114
117
|
end
|
115
118
|
end
|
116
119
|
|
@@ -174,7 +177,7 @@ module Raix
|
|
174
177
|
params[:stream] ||= stream.presence
|
175
178
|
params[:stream_options] = { include_usage: true } if params[:stream]
|
176
179
|
|
177
|
-
params.delete(:temperature) if model
|
180
|
+
params.delete(:temperature) if model.start_with?("o")
|
178
181
|
|
179
182
|
Raix.configuration.openai_client.chat(parameters: params.compact.merge(model:, messages:))
|
180
183
|
end
|
data/lib/raix/predicate.rb
CHANGED
@@ -3,19 +3,24 @@
|
|
3
3
|
module Raix
|
4
4
|
# A module for handling yes/no questions using AI chat completion.
|
5
5
|
# When included in a class, it provides methods to define handlers for
|
6
|
-
# yes and no responses.
|
6
|
+
# yes and no responses. All handlers are optional. Any response that
|
7
|
+
# does not begin with "yes, " or "no, " will be considered a maybe.
|
7
8
|
#
|
8
9
|
# @example
|
9
10
|
# class Question
|
10
11
|
# include Raix::Predicate
|
11
12
|
#
|
12
|
-
# yes do |explanation|
|
13
|
+
# yes? do |explanation|
|
13
14
|
# puts "Yes: #{explanation}"
|
14
15
|
# end
|
15
16
|
#
|
16
|
-
# no do |explanation|
|
17
|
+
# no? do |explanation|
|
17
18
|
# puts "No: #{explanation}"
|
18
19
|
# end
|
20
|
+
#
|
21
|
+
# maybe? do |explanation|
|
22
|
+
# puts "Maybe: #{explanation}"
|
23
|
+
# end
|
19
24
|
# end
|
20
25
|
#
|
21
26
|
# question = Question.new
|
@@ -38,8 +43,10 @@ module Raix
|
|
38
43
|
instance_exec(response, &self.class.yes_block) if self.class.yes_block
|
39
44
|
elsif response.downcase.start_with?("no,")
|
40
45
|
instance_exec(response, &self.class.no_block) if self.class.no_block
|
41
|
-
elsif
|
42
|
-
instance_exec(response, &self.class.maybe_block)
|
46
|
+
elsif self.class.maybe_block
|
47
|
+
instance_exec(response, &self.class.maybe_block)
|
48
|
+
else
|
49
|
+
puts "[Raix::Predicate] Unhandled response: #{response}"
|
43
50
|
end
|
44
51
|
end
|
45
52
|
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: 0.
|
4
|
+
version: '0.5'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Obie Fernandez
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -102,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '0'
|
104
104
|
requirements: []
|
105
|
-
rubygems_version: 3.
|
105
|
+
rubygems_version: 3.5.21
|
106
106
|
signing_key:
|
107
107
|
specification_version: 4
|
108
108
|
summary: Ruby AI eXtensions
|