raix 0.4.3 → 0.4.4

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: 65adb56d006baa2b25193eaa5f87f52b24366876139d1e023c9031e7707f62ea
4
- data.tar.gz: 545da8c28e699f87e53547b53d07fb934727948945f45998f3af5d34752a2854
3
+ metadata.gz: 50d0de4d7ec7fdd83776e539dbed2cc73ba3097c96752050eb768163dd5f510a
4
+ data.tar.gz: c82955632f789a0683e30553ecc8aef8b2f96aa4bc003e0b2e12953e6698adf9
5
5
  SHA512:
6
- metadata.gz: 71a14254199a7e0eeb8195b842fe212516091743ab4799f349caadfeffa654eede58dc066813e4d1360c24b2384406f934086d9b167b45db70a618470c94df84
7
- data.tar.gz: 3d5a8033107bc8037862d11cd88fb3cd7a67a6884b4f7d2d8756244ac676e938094a6580bd55275b353c0b12389f292cbe958138d8d13f2d1001c5befb81662d
6
+ metadata.gz: 48977e0c2265105f22da2c1508a1aced37337ab1a914c7297bca4995cc94d6839708a51edb9f63222e4531bc0dccce305448ad70f78a858f30d7f581ae289114
7
+ data.tar.gz: c52f4078787b2570a6a11eb92e0a0f6172a09e083219d0b8562349fee4efc14012674e25591ef2839e41fd2675bfc834361bf1a64d3b74614854ce944b6cf8ab
@@ -12,10 +12,22 @@ module Raix
12
12
  # with the OpenRouter Chat Completion API via its client. The module includes a few
13
13
  # methods that allow you to build a transcript of messages and then send them to
14
14
  # the API for completion. The API will return a response that you can use however
15
- # you see fit. If the response includes a function call, the module will dispatch
16
- # the function call and return the result. Which implies that function calls need
17
- # to be defined on the class that includes this module. (Note: You should probably
18
- # use the `FunctionDispatch` module to define functions instead of doing it manually.)
15
+ # you see fit.
16
+ #
17
+ # If the response includes a function call, the module will dispatch the function
18
+ # call and return the result. Which implies that function calls need to be defined
19
+ # on the class that includes this module. The `FunctionDispatch` module provides a
20
+ # Rails-like DSL for declaring and implementing tool functions at the top of your
21
+ # class instead of having to manually implement them as instance methods. The
22
+ # primary benefit of using the `FunctionDispatch` module is that it handles
23
+ # adding the function call results to the ongoing conversation transcript for you.
24
+ # It also triggers a new chat completion automatically if you've set the `loop`
25
+ # option to `true`, which is useful for implementing conversational chatbots that
26
+ # include tool calls.
27
+ #
28
+ # Note that some AI models can make more than a single tool function call in a
29
+ # single response. When that happens, the module will dispatch all of the function
30
+ # calls sequentially and return an array of results.
19
31
  module ChatCompletion
20
32
  extend ActiveSupport::Concern
21
33
 
@@ -92,13 +104,13 @@ module Raix
92
104
  # TODO: add a standardized callback hook for usage events
93
105
  # broadcast(:usage_event, usage_subject, self.class.name.to_s, response, premium?)
94
106
 
95
- # TODO: handle parallel tool calls
96
- if (function = response.dig("choices", 0, "message", "tool_calls", 0, "function"))
97
- @current_function = function["name"]
98
- # dispatch the called function
99
- arguments = JSON.parse(function["arguments"].presence || "{}")
100
- arguments[:bot_message] = bot_message if respond_to?(:bot_message)
101
- return send(function["name"], arguments.with_indifferent_access)
107
+ tool_calls = response.dig("choices", 0, "message", "tool_calls") || []
108
+ if tool_calls.any?
109
+ return tool_calls.map do |tool_call|
110
+ # dispatch the called function
111
+ arguments = JSON.parse(tool_call["function"]["arguments"].presence || "{}")
112
+ send(tool_call["function"]["name"], arguments.with_indifferent_access)
113
+ end
102
114
  end
103
115
 
104
116
  response.tap do |res|
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.3"
4
+ VERSION = "0.4.4"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: raix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Obie Fernandez