ox-ai-workers 0.8.4 → 0.8.5

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: 4c3c03d24ee695dc7f931547e96fefee838a761e58a6f1410ffaffae5674b87a
4
- data.tar.gz: 88e9a6a0b4711e49b3d2d168562df273a618fb54129efba683909d2cc8a8c936
3
+ metadata.gz: ff4f2cb710ff8bf02e912c0354ff62f3f3ce65871edc90f2cfb398805cd8eadb
4
+ data.tar.gz: fdca1f55dd1cc8721bf8eca0317272c749d7d3f0608b5554f86bd6677d5307e4
5
5
  SHA512:
6
- metadata.gz: c372c3ae901dcd5d8591633791419cbe2f81ed14f7e2fc1e889d2546db6144954b534504e2ba0e728e844cd758efa67e02a3c4ac8cc91548c45bc3266b64602f
7
- data.tar.gz: 01e5efec2e0b6fac0421415a48f4452def47ffcfb135260820c05c39547e71390b032c7af66877620e2e5c38129228af58e7eb80141eb4ecc5f9e64a66a1eb4c
6
+ metadata.gz: 555e7b22260a4b443c5b05fcacc6e0f3dbe72dca112e887159abcfe12e0efda767d23ca7e995e60fc3236ce545361a37a7ea65a324171f65d28c8cfe0f975d59
7
+ data.tar.gz: a5d39e26ecc80a315101cabab6e50486f1e05a293360ef79c38e56b022535bb7a769daf3caf851a69fa06e20546caa4ad9c0648e457715f481166eea9e5bf66a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## [0.8.5] - 2025-04-18
2
+
3
+ - Fixed tool calls parsing
4
+
1
5
  ## [0.8.4] - 2025-04-18
2
6
 
3
7
  - Refine Russian locale for Iterator with enhanced step descriptions and planning guidance
@@ -26,5 +26,5 @@ ru:
26
26
  - Шаг %d. Когда промежуточные шаги завершены и точное содержание предыдущих сообщений больше не важно, сожми историю диалога с помощью ox_ai_workers_iterator__summarize.
27
27
  - Шаг %d. После выполнения всех шагов плана и получения финального результата через вызов соответствующей функции (инструмента), оцени полноту и корректность решения.
28
28
  - Шаг %d. Если необходимо запросить подтверждение у пользователя используй функцию ox_ai_workers_iterator__action_request для представления финального результата и ожидания ответа.
29
- - Шаг %d. После успешного завершения задачи и получения результата (и, возможно, подтверждения пользователя), вызови ox_ai_workers_iterator__finish_it.
29
+ - Шаг %d. После успешного завершения задачи и получения результата (и подтверждения пользователя), вызови ox_ai_workers_iterator__finish_it.
30
30
  - Старайся выполнить работу наилучшим образом, используя доступные инструменты максимально эффективно.
@@ -70,25 +70,65 @@ module OxAiWorkers
70
70
  end
71
71
 
72
72
  def parse_choices(response)
73
+ # Reset instance variables before processing choices
74
+ @result = nil
75
+ @tool_calls_raw = []
73
76
  @tool_calls = []
74
- @result = response.dig('choices', 0, 'message', 'content')
75
- @tool_calls_raw = response.dig('choices', 0, 'message', 'tool_calls')
76
- @finish_reason = response.dig('choices', 0, 'finish_reason')
77
- @is_truncated = @finish_reason == 'length'
78
-
79
- return @tool_calls if @tool_calls_raw.nil?
80
-
81
- @tool_calls_raw.each do |tool|
82
- function = tool['function']
83
- args = JSON.parse(YAML.load(function['arguments']).to_json, { symbolize_names: true })
84
- @tool_calls << {
85
- class: function['name'].split('__').first,
86
- name: function['name'].split('__').last,
87
- args:
88
- }
77
+ @finish_reason = nil
78
+ @is_truncated = false
79
+
80
+ choices = response['choices']
81
+ return if choices.nil? || choices.empty?
82
+
83
+ choices.each do |choice|
84
+ parse_one_choice(choice)
89
85
  end
90
86
 
91
- @tool_calls
87
+ # @tool_calls is already populated by parse_one_choice
88
+ # @result, @finish_reason, @is_truncated are updated with the last relevant values
89
+ end
90
+
91
+ def parse_one_choice(choice)
92
+ message = choice['message']
93
+ return unless message # Skip if there's no message in this choice
94
+
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
121
+
122
+ # Update result with the content if present
123
+ current_result = message['content']
124
+ @result = current_result if current_result.present?
125
+
126
+ # Update finish reason and truncation status
127
+ current_finish_reason = choice['finish_reason']
128
+ if current_finish_reason.present?
129
+ @finish_reason = current_finish_reason
130
+ @is_truncated = @finish_reason == 'length'
131
+ end
92
132
  end
93
133
  end
94
134
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OxAiWorkers
4
- VERSION = '0.8.4'
4
+ VERSION = '0.8.5'
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.4
4
+ version: 0.8.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Smolev