Compare commits

..

2 Commits

Author SHA1 Message Date
c6232d262d 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.
2026-02-23 18:46:46 +00:00
592b34cff0 Fix: accept array content format in ChatMessage + add extra=allow, update .gitignore 2026-02-23 18:40:28 +00:00
3 changed files with 12 additions and 2 deletions

4
.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
venv/
__pycache__/
*.pyc
.env

View File

@@ -9,12 +9,14 @@ from pydantic import BaseModel, Field
# ============================================================================
class ChatMessage(BaseModel):
model_config = {"extra": "allow"}
"""A chat message in the conversation."""
role: Literal["system", "user", "assistant", "function", "tool", "developer"]
content: Optional[str] = None
content: Optional[Union[str, List[Dict[str, Any]]]] = None
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):
@@ -81,9 +83,10 @@ class ChatCompletionResponse(BaseModel):
class ChatCompletionChunkDelta(BaseModel):
"""Delta content in streaming response."""
role: Optional[str] = None
content: Optional[str] = None
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):

View File

@@ -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