Fix: pass tool_call_id through to watsonx API
watsonx requires tool_call_id on role=tool messages. Added field to ChatMessage model and passthrough in transformer.
This commit is contained in:
@@ -16,6 +16,7 @@ class ChatMessage(BaseModel):
|
||||
name: Optional[str] = None
|
||||
function_call: Optional[Dict[str, Any]] = None
|
||||
tool_calls: Optional[List[Dict[str, Any]]] = None
|
||||
tool_call_id: Optional[str] = None
|
||||
|
||||
|
||||
class FunctionCall(BaseModel):
|
||||
@@ -85,6 +86,7 @@ class ChatCompletionChunkDelta(BaseModel):
|
||||
content: Optional[Union[str, List[Dict[str, Any]]]] = None
|
||||
function_call: Optional[Dict[str, Any]] = None
|
||||
tool_calls: Optional[List[Dict[str, Any]]] = None
|
||||
tool_call_id: Optional[str] = None
|
||||
|
||||
|
||||
class ChatCompletionChunkChoice(BaseModel):
|
||||
|
||||
@@ -47,6 +47,9 @@ def transform_messages_to_watsonx(messages: List[ChatMessage]) -> List[Dict[str,
|
||||
if msg.function_call:
|
||||
watsonx_msg["function_call"] = msg.function_call
|
||||
|
||||
if msg.tool_call_id:
|
||||
watsonx_msg["tool_call_id"] = msg.tool_call_id
|
||||
|
||||
watsonx_messages.append(watsonx_msg)
|
||||
|
||||
return watsonx_messages
|
||||
|
||||
Reference in New Issue
Block a user