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 +4 -4
- data/CHANGELOG.md +4 -0
- data/config/locales/ru.oxaiworkers.iterator.yml +1 -1
- data/lib/oxaiworkers/module_request.rb +56 -16
- 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: ff4f2cb710ff8bf02e912c0354ff62f3f3ce65871edc90f2cfb398805cd8eadb
|
4
|
+
data.tar.gz: fdca1f55dd1cc8721bf8eca0317272c749d7d3f0608b5554f86bd6677d5307e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 555e7b22260a4b443c5b05fcacc6e0f3dbe72dca112e887159abcfe12e0efda767d23ca7e995e60fc3236ce545361a37a7ea65a324171f65d28c8cfe0f975d59
|
7
|
+
data.tar.gz: a5d39e26ecc80a315101cabab6e50486f1e05a293360ef79c38e56b022535bb7a769daf3caf851a69fa06e20546caa4ad9c0648e457715f481166eea9e5bf66a
|
data/CHANGELOG.md
CHANGED
@@ -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. После успешного завершения задачи и получения результата (
|
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
|
-
@
|
75
|
-
@
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
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
|
data/lib/oxaiworkers/version.rb
CHANGED