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 +4 -4
- data/lib/raix/chat_completion.rb +23 -11
- data/lib/raix/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50d0de4d7ec7fdd83776e539dbed2cc73ba3097c96752050eb768163dd5f510a
|
4
|
+
data.tar.gz: c82955632f789a0683e30553ecc8aef8b2f96aa4bc003e0b2e12953e6698adf9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48977e0c2265105f22da2c1508a1aced37337ab1a914c7297bca4995cc94d6839708a51edb9f63222e4531bc0dccce305448ad70f78a858f30d7f581ae289114
|
7
|
+
data.tar.gz: c52f4078787b2570a6a11eb92e0a0f6172a09e083219d0b8562349fee4efc14012674e25591ef2839e41fd2675bfc834361bf1a64d3b74614854ce944b6cf8ab
|
data/lib/raix/chat_completion.rb
CHANGED
@@ -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.
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
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
|
-
|
96
|
-
if
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
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