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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7db1d4210aef051f8e283697776698a60e5eea60be78e05710cade1749e42181
4
- data.tar.gz: d23d58866d655f860731bbb396fadf7b3ed54bfbc64e7d08cea1c5420e538367
3
+ metadata.gz: 7537dc5f13d858d6fdd7e5fcdeb60e1d5fd99e0f2aa84e618096f959f2c44ed1
4
+ data.tar.gz: 8af2e5eb06b2fdaf2c4da8e9b9df28750c6c449d63e5eec25478d61068de2742
5
5
  SHA512:
6
- metadata.gz: 708045d59a97f42b918ff7749b183195ba02c58853dd54a7ce87e112c9905e7e404e8aec5e541fd9cd62ef2e932fae00f7106379a637e8380e6b0147496e8edb
7
- data.tar.gz: aa6a4e463adba935d83cfaab186a8aa132db9967fb2420ee5821519a5253de176efbdcc1a0fd7460ec2bd4980f2c4f54146dc790dd1d37f8b48eba473b9f946d
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.7)
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:
@@ -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
- send(tool_call["function"]["name"], arguments.with_indifferent_access)
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 == "o1-preview"
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
@@ -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 response.downcase.start_with?("maybe,")
42
- instance_exec(response, &self.class.maybe_block) if 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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Raix
4
- VERSION = "0.4.7"
4
+ VERSION = "0.5"
5
5
  end
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.7
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: 2024-12-03 00:00:00.000000000 Z
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.4.10
105
+ rubygems_version: 3.5.21
106
106
  signing_key:
107
107
  specification_version: 4
108
108
  summary: Ruby AI eXtensions