4040 get_langtrace_attributes ,
4141 get_llm_request_attributes ,
4242 get_llm_url ,
43+ get_tool_calls ,
4344 is_streaming ,
4445)
4546from openai ._types import NOT_GIVEN
@@ -407,12 +408,13 @@ def traced_method(wrapped, instance, args, kwargs):
407408 service_provider = SERVICE_PROVIDERS ["PPLX" ]
408409 elif "azure" in get_base_url (instance ):
409410 service_provider = SERVICE_PROVIDERS ["AZURE" ]
410-
411411 llm_prompts = []
412412 for item in kwargs .get ("messages" , []):
413- if hasattr (item , "tool_calls" ) and item .tool_calls is not None :
413+ tools = get_tool_calls (item )
414+ if tools is not None :
414415 tool_calls = []
415- for tool_call in item .tool_calls :
416+
417+ for tool_call in tools :
416418 tool_call_dict = {
417419 "id" : tool_call .id if hasattr (tool_call , "id" ) else "" ,
418420 "type" : tool_call .type if hasattr (tool_call , "type" ) else "" ,
@@ -501,12 +503,12 @@ async def traced_method(wrapped, instance, args, kwargs):
501503 service_provider = SERVICE_PROVIDERS ["PPLX" ]
502504 elif "azure" in get_base_url (instance ):
503505 service_provider = SERVICE_PROVIDERS ["AZURE" ]
504-
505506 llm_prompts = []
506507 for item in kwargs .get ("messages" , []):
507- if hasattr (item , "tool_calls" ) and item .tool_calls is not None :
508+ tools = get_tool_calls (item )
509+ if tools is not None :
508510 tool_calls = []
509- for tool_call in item . tool_calls :
511+ for tool_call in tools :
510512 tool_call_dict = {
511513 "id" : tool_call .id if hasattr (tool_call , "id" ) else "" ,
512514 "type" : tool_call .type if hasattr (tool_call , "type" ) else "" ,
@@ -524,7 +526,7 @@ async def traced_method(wrapped, instance, args, kwargs):
524526 else ""
525527 ),
526528 }
527- tool_calls .append (tool_call_dict )
529+ tool_calls .append (json . dumps ( tool_call_dict ) )
528530 llm_prompts .append (tool_calls )
529531 else :
530532 llm_prompts .append (item )
0 commit comments