mbxai 0.6.11__py3-none-any.whl → 0.6.12__py3-none-any.whl
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.
mbxai/tools/client.py
CHANGED
@@ -327,99 +327,36 @@ class ToolClient:
|
|
327
327
|
Returns:
|
328
328
|
The parsed response from the model
|
329
329
|
"""
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
kwargs
|
336
|
-
|
337
|
-
while True:
|
338
|
-
# Log messages before sending to OpenRouter
|
339
|
-
self._log_messages(messages)
|
340
|
-
|
341
|
-
# Get the model's response
|
342
|
-
response = self._client.chat_completion_parse(
|
343
|
-
messages=messages,
|
344
|
-
response_format=response_format,
|
345
|
-
model=model,
|
346
|
-
stream=stream,
|
347
|
-
**kwargs,
|
348
|
-
)
|
330
|
+
# First, use chat to handle any tool calls
|
331
|
+
chat_response = await self.chat(
|
332
|
+
messages=messages,
|
333
|
+
model=model,
|
334
|
+
stream=stream,
|
335
|
+
**kwargs,
|
336
|
+
)
|
349
337
|
|
350
|
-
|
351
|
-
|
338
|
+
if stream:
|
339
|
+
return chat_response
|
352
340
|
|
353
|
-
|
354
|
-
|
355
|
-
|
341
|
+
# Get the final message after all tool calls are handled
|
342
|
+
final_message = chat_response.choices[0].message
|
343
|
+
|
344
|
+
# Create a new message list with just the final response
|
345
|
+
parse_messages = [
|
346
|
+
*messages, # Include original context
|
347
|
+
{
|
356
348
|
"role": "assistant",
|
357
|
-
"content":
|
349
|
+
"content": final_message.content,
|
358
350
|
}
|
359
|
-
|
360
|
-
assistant_message["tool_calls"] = [
|
361
|
-
{
|
362
|
-
"id": tool_call.id,
|
363
|
-
"type": "function",
|
364
|
-
"function": {
|
365
|
-
"name": tool_call.function.name,
|
366
|
-
"arguments": tool_call.function.arguments,
|
367
|
-
},
|
368
|
-
}
|
369
|
-
for tool_call in message.tool_calls
|
370
|
-
]
|
371
|
-
messages.append(assistant_message)
|
372
|
-
logger.info(f"Message count: {len(messages)}, Added assistant message with tool calls: {[tc.function.name for tc in message.tool_calls] if message.tool_calls else None}")
|
373
|
-
|
374
|
-
# If there are no tool calls, we're done
|
375
|
-
if not message.tool_calls:
|
376
|
-
return response
|
351
|
+
]
|
377
352
|
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
try:
|
389
|
-
arguments = json.loads(arguments)
|
390
|
-
except json.JSONDecodeError as e:
|
391
|
-
logger.error(f"Failed to parse tool arguments: {e}")
|
392
|
-
raise ValueError(f"Invalid tool arguments format: {arguments}")
|
393
|
-
|
394
|
-
# Call the tool
|
395
|
-
logger.info(f"Calling tool: {tool.name} with args: {self._truncate_dict(arguments)}")
|
396
|
-
if inspect.iscoroutinefunction(tool.function):
|
397
|
-
result = await tool.function(**arguments)
|
398
|
-
else:
|
399
|
-
result = tool.function(**arguments)
|
400
|
-
|
401
|
-
# Convert result to JSON string if it's not already
|
402
|
-
if not isinstance(result, str):
|
403
|
-
result = json.dumps(result)
|
404
|
-
|
405
|
-
# Create the tool response
|
406
|
-
tool_response = {
|
407
|
-
"role": "tool",
|
408
|
-
"tool_call_id": tool_call.id,
|
409
|
-
"content": result,
|
410
|
-
}
|
411
|
-
tool_responses.append(tool_response)
|
412
|
-
logger.info(f"Created tool response for call ID {tool_call.id}")
|
413
|
-
|
414
|
-
# Add all tool responses to the messages
|
415
|
-
messages.extend(tool_responses)
|
416
|
-
logger.info(f"Message count: {len(messages)}, Added {len(tool_responses)} tool responses to messages")
|
417
|
-
|
418
|
-
# Validate the message sequence
|
419
|
-
self._validate_message_sequence(messages, validate_responses=True)
|
420
|
-
|
421
|
-
# Log the messages we're about to send
|
422
|
-
self._log_messages(messages, validate_responses=False)
|
423
|
-
|
424
|
-
# Continue the loop to get the next response
|
425
|
-
continue
|
353
|
+
# Make a final parse request with the structured output format
|
354
|
+
parse_kwargs = kwargs.copy()
|
355
|
+
parse_kwargs["response_format"] = response_format
|
356
|
+
|
357
|
+
return self._client.chat_completion_parse(
|
358
|
+
messages=parse_messages,
|
359
|
+
model=model,
|
360
|
+
stream=stream,
|
361
|
+
**parse_kwargs,
|
362
|
+
)
|
@@ -9,10 +9,10 @@ mbxai/openrouter/client.py,sha256=RO5tbF42vkcjxjvC-QFB8DGA0gQLljH3KPBn3HgZV8I,13
|
|
9
9
|
mbxai/openrouter/config.py,sha256=Ia93s-auim9Sq71eunVDbn9ET5xX2zusXpV4JBdHAzs,3251
|
10
10
|
mbxai/openrouter/models.py,sha256=b3IjjtZAjeGOf2rLsdnCD1HacjTnS8jmv_ZXorc-KJQ,2604
|
11
11
|
mbxai/tools/__init__.py,sha256=QUFaXhDm-UKcuAtT1rbKzhBkvyRBVokcQIOf9cxIuwc,160
|
12
|
-
mbxai/tools/client.py,sha256=
|
12
|
+
mbxai/tools/client.py,sha256=sK2sl8VKB7sgMHtJpnC_2gfy7HCA4RMzRb32sfXvWbI,14260
|
13
13
|
mbxai/tools/example.py,sha256=1HgKK39zzUuwFbnp3f0ThyWVfA_8P28PZcTwaUw5K78,2232
|
14
14
|
mbxai/tools/types.py,sha256=fo5t9UbsHGynhA88vD_ecgDqL8iLvt2E1h1ym43Rrgk,745
|
15
|
-
mbxai-0.6.
|
16
|
-
mbxai-0.6.
|
17
|
-
mbxai-0.6.
|
18
|
-
mbxai-0.6.
|
15
|
+
mbxai-0.6.12.dist-info/METADATA,sha256=3Iwx5kOqV1v-wEQ6FskMYvz-j8AuiXRFHmpvGkUT8HA,4108
|
16
|
+
mbxai-0.6.12.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
17
|
+
mbxai-0.6.12.dist-info/licenses/LICENSE,sha256=hEyhc4FxwYo3NQ40yNgZ7STqwVk-1_XcTXOnAPbGJAw,1069
|
18
|
+
mbxai-0.6.12.dist-info/RECORD,,
|
File without changes
|
File without changes
|