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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4c0c7e3c6445442544161a0c6bb1bf7e85d6b64654263fa000cdafaa6a6903ef
4
- data.tar.gz: aeca3a033ff65370a03db4f54530dd211fab181431799ec0317a866083c23770
3
+ metadata.gz: 02c7ccd3357fb07615d22878578cd9138f2f8f0790a7439f08aabe3267a4ecbf
4
+ data.tar.gz: 64cebe6e9f10d7748a19c96c9b779d7b32e57d5e94db56b290a70cc9e63210e2
5
5
  SHA512:
6
- metadata.gz: 0401a214d80347b240f53e45ff44b3b536fbf3094473ae46945c0a59d865952f852dc3e1c162058c478c4563b2bd3c469e2cc3ba8d9df221837f77f6b889794c
7
- data.tar.gz: f1dad1689589b10070f90de6ba5fbafc7a77ae928b9a8bdb72d357591ef040dbf4a6f19898d4edf46b7164794d90a6268145a8eac2a6a6499efd1c3079c33b76
6
+ metadata.gz: 8e4f16c02b75981099a6c389c94ec27fe2626bcf24fd46e32eda54b0d48ac02ed70c090003f7431cad3eaa14ceb6f8ffa4268d2a6a3bd4056c5ce0e77345937c
7
+ data.tar.gz: 305e41419ef2a18fc004718af0e45b1e3b969412463b8e234e6050a7adb2e20687b8f52c38a38d198f22ca69bebd487c51c9d30f741b03a2a1925ab3c43ee216
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+
2
+ ## [0.8.7] - 2025-04-25
3
+
4
+ - Fixed tool calls parsing
5
+
1
6
  ## [0.8.5] - 2025-04-18
2
7
 
3
8
  - Fixed tool calls parsing
@@ -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
- # @tool_calls is already populated by parse_one_choice
88
- # @result, @finish_reason, @is_truncated are updated with the last relevant values
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OxAiWorkers
4
- VERSION = '0.8.6'
4
+ VERSION = '0.8.7'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ox-ai-workers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.6
4
+ version: 0.8.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Smolev