ox-ai-workers 0.8.6 → 0.8.7
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 +5 -0
- data/lib/oxaiworkers/module_request.rb +39 -30
- data/lib/oxaiworkers/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: 02c7ccd3357fb07615d22878578cd9138f2f8f0790a7439f08aabe3267a4ecbf
|
4
|
+
data.tar.gz: 64cebe6e9f10d7748a19c96c9b779d7b32e57d5e94db56b290a70cc9e63210e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e4f16c02b75981099a6c389c94ec27fe2626bcf24fd46e32eda54b0d48ac02ed70c090003f7431cad3eaa14ceb6f8ffa4268d2a6a3bd4056c5ce0e77345937c
|
7
|
+
data.tar.gz: 305e41419ef2a18fc004718af0e45b1e3b969412463b8e234e6050a7adb2e20687b8f52c38a38d198f22ca69bebd487c51c9d30f741b03a2a1925ab3c43ee216
|
data/CHANGELOG.md
CHANGED
@@ -81,53 +81,62 @@ module OxAiWorkers
|
|
81
81
|
return if choices.nil? || choices.empty?
|
82
82
|
|
83
83
|
choices.each do |choice|
|
84
|
+
# Parse basic info and accumulate raw tool calls
|
84
85
|
parse_one_choice(choice)
|
85
86
|
end
|
86
87
|
|
87
|
-
#
|
88
|
-
|
88
|
+
# Only parse tool calls if the response wasn't truncated
|
89
|
+
_parse_tool_calls unless @is_truncated || @tool_calls_raw.empty?
|
89
90
|
end
|
90
91
|
|
91
92
|
def parse_one_choice(choice)
|
92
93
|
message = choice['message']
|
93
94
|
return unless message # Skip if there's no message in this choice
|
94
95
|
|
95
|
-
# Accumulate raw tool calls
|
96
|
-
if message['tool_calls']
|
97
|
-
@tool_calls_raw.concat(message['tool_calls'])
|
98
|
-
message['tool_calls'].each do |tool_call|
|
99
|
-
next unless tool_call['type'] == 'function' # Ensure it's a function call
|
100
|
-
|
101
|
-
function = tool_call['function']
|
102
|
-
next unless function && function['name'] && function['arguments']
|
103
|
-
|
104
|
-
begin
|
105
|
-
# Attempt to parse arguments, handle potential JSON errors
|
106
|
-
args = JSON.parse(function['arguments'], symbolize_names: true)
|
107
|
-
rescue JSON::ParserError => e
|
108
|
-
OxAiWorkers.logger.error("Failed to parse tool call arguments: #{e.message}", for: self.class)
|
109
|
-
OxAiWorkers.logger.debug("Raw arguments: #{function['arguments']}", for: self.class)
|
110
|
-
args = {} # Assign empty args or handle error as appropriate
|
111
|
-
end
|
112
|
-
|
113
|
-
# Accumulate parsed tool calls
|
114
|
-
@tool_calls << {
|
115
|
-
class: function['name'].split('__').first,
|
116
|
-
name: function['name'].split('__').last,
|
117
|
-
args: args
|
118
|
-
}
|
119
|
-
end
|
120
|
-
end
|
96
|
+
# Accumulate raw tool calls if present
|
97
|
+
@tool_calls_raw.concat(message['tool_calls']) if message['tool_calls']
|
121
98
|
|
122
99
|
# Update result with the content if present
|
123
100
|
current_result = message['content']
|
124
101
|
@result = current_result if current_result.present?
|
125
102
|
|
126
|
-
# Update finish reason and truncation status
|
103
|
+
# Update finish reason and truncation status based on the *last* choice's reason
|
127
104
|
current_finish_reason = choice['finish_reason']
|
128
105
|
if current_finish_reason.present?
|
129
106
|
@finish_reason = current_finish_reason
|
130
|
-
@is_truncated = @finish_reason == 'length'
|
107
|
+
@is_truncated = (@finish_reason == 'length')
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
private
|
112
|
+
|
113
|
+
# Parses the accumulated raw tool calls into the structured @tool_calls array.
|
114
|
+
# This should only be called after confirming the response is not truncated.
|
115
|
+
def _parse_tool_calls
|
116
|
+
@tool_calls = [] # Ensure it's clean before parsing
|
117
|
+
@tool_calls_raw.each do |tool_call|
|
118
|
+
next unless tool_call['type'] == 'function' # Ensure it's a function call
|
119
|
+
|
120
|
+
function = tool_call['function']
|
121
|
+
next unless function && function['name'] && function['arguments']
|
122
|
+
|
123
|
+
begin
|
124
|
+
# Attempt to parse arguments, handle potential JSON errors
|
125
|
+
args = JSON.parse(function['arguments'], symbolize_names: true)
|
126
|
+
rescue JSON::ParserError => e
|
127
|
+
OxAiWorkers.logger.error("Failed to parse tool call arguments: #{e.message}", for: self.class)
|
128
|
+
OxAiWorkers.logger.debug("Raw arguments: #{function['arguments']}", for: self.class)
|
129
|
+
# Decide how to handle parsing errors, e.g., skip this call or add with empty args
|
130
|
+
# Skipping for now, as partial args are likely useless.
|
131
|
+
next
|
132
|
+
end
|
133
|
+
|
134
|
+
# Accumulate parsed tool calls
|
135
|
+
@tool_calls << {
|
136
|
+
class: function['name'].split('__').first,
|
137
|
+
name: function['name'].split('__').last,
|
138
|
+
args: args
|
139
|
+
}
|
131
140
|
end
|
132
141
|
end
|
133
142
|
end
|
data/lib/oxaiworkers/version.rb
CHANGED