mirror of
https://github.com/Xe138/AI-Trader.git
synced 2026-04-02 09:37:23 -04:00
Compare commits
2 Commits
v0.4.2-alp
...
v0.4.2-alp
| Author | SHA1 | Date | |
|---|---|---|---|
| d199b093c1 | |||
| 483621f9b7 |
@@ -32,14 +32,37 @@ class ToolCallArgsParsingWrapper:
|
||||
# Model doesn't have this method (e.g., MockChatModel), skip patching
|
||||
return
|
||||
|
||||
# CRITICAL: Also patch parse_tool_call to see what it's returning
|
||||
from langchain_core.output_parsers import openai_tools
|
||||
original_parse_tool_call = openai_tools.parse_tool_call
|
||||
|
||||
def patched_parse_tool_call(raw_tool_call, *, partial=False, strict=False, return_id=True):
|
||||
"""Patched parse_tool_call to log what it returns"""
|
||||
result = original_parse_tool_call(raw_tool_call, partial=partial, strict=strict, return_id=return_id)
|
||||
if result:
|
||||
args_type = type(result.get('args', None)).__name__
|
||||
print(f"[DIAGNOSTIC] parse_tool_call returned: args type = {args_type}")
|
||||
if args_type == 'str':
|
||||
print(f"[DIAGNOSTIC] ⚠️ BUG FOUND! parse_tool_call returned STRING args: {result['args']}")
|
||||
return result
|
||||
|
||||
# Replace globally
|
||||
openai_tools.parse_tool_call = patched_parse_tool_call
|
||||
|
||||
original_create_chat_result = self.wrapped_model._create_chat_result
|
||||
|
||||
@wraps(original_create_chat_result)
|
||||
def patched_create_chat_result(response: Any, generation_info: Optional[Dict] = None):
|
||||
"""Patched version with diagnostic logging and args parsing"""
|
||||
import traceback
|
||||
response_dict = response if isinstance(response, dict) else response.model_dump()
|
||||
|
||||
# DIAGNOSTIC: Log response structure for debugging
|
||||
print(f"\n[DIAGNOSTIC] _create_chat_result called")
|
||||
print(f" Response type: {type(response)}")
|
||||
print(f" Call stack:")
|
||||
for line in traceback.format_stack()[-5:-1]: # Show last 4 stack frames
|
||||
print(f" {line.strip()}")
|
||||
print(f"\n[DIAGNOSTIC] Response structure:")
|
||||
print(f" Response keys: {list(response_dict.keys())}")
|
||||
|
||||
@@ -116,7 +139,18 @@ class ToolCallArgsParsingWrapper:
|
||||
# Keep as-is if serialization fails
|
||||
|
||||
# Call original method with fixed response
|
||||
return original_create_chat_result(response_dict, generation_info)
|
||||
print(f"[DIAGNOSTIC] Calling original_create_chat_result...")
|
||||
result = original_create_chat_result(response_dict, generation_info)
|
||||
print(f"[DIAGNOSTIC] original_create_chat_result returned successfully")
|
||||
print(f"[DIAGNOSTIC] Result type: {type(result)}")
|
||||
if hasattr(result, 'generations') and result.generations:
|
||||
gen = result.generations[0]
|
||||
if hasattr(gen, 'message') and hasattr(gen.message, 'tool_calls'):
|
||||
print(f"[DIAGNOSTIC] Result has {len(gen.message.tool_calls)} tool_calls")
|
||||
if gen.message.tool_calls:
|
||||
tc = gen.message.tool_calls[0]
|
||||
print(f"[DIAGNOSTIC] tool_calls[0]['args'] type in result: {type(tc['args'])}")
|
||||
return result
|
||||
|
||||
# Replace the method
|
||||
self.wrapped_model._create_chat_result = patched_create_chat_result
|
||||
|
||||
Reference in New Issue
Block a user