6
6
import json
7
7
import os
8
8
from datetime import datetime , timezone
9
- from typing import Any
9
+ from typing import Any , Dict , List , Optional , Union
10
10
11
11
from haystack import component , default_from_dict , default_to_dict , logging
12
12
from haystack .dataclasses import ChatMessage , StreamingChunk , ToolCall
@@ -177,7 +177,9 @@ def from_dict(cls, data: dict[str, Any]) -> WatsonxChatGenerator:
177
177
return default_from_dict (cls , data )
178
178
179
179
@component .output_types (replies = list [ChatMessage ])
180
- def run (self , messages : list [ChatMessage ], generation_kwargs : dict [str , Any ] | None = None , stream : bool = False ):
180
+ def run (
181
+ self , messages : list [ChatMessage ], generation_kwargs : dict [str , Any ] | None = None , stream : bool = False
182
+ ) -> Dict [str , List [ChatMessage ]]:
181
183
"""
182
184
Generate chat completions synchronously.
183
185
@@ -198,7 +200,7 @@ def run(self, messages: list[ChatMessage], generation_kwargs: dict[str, Any] | N
198
200
@component .output_types (replies = list [ChatMessage ])
199
201
async def run_async (
200
202
self , messages : list [ChatMessage ], generation_kwargs : dict [str , Any ] | None = None , stream : bool = False
201
- ):
203
+ ) -> Dict [ str , List [ ChatMessage ]] :
202
204
"""
203
205
Generate chat completions asynchronously.
204
206
@@ -222,6 +224,7 @@ def _prepare_api_call(
222
224
merged_kwargs = {** self .generation_kwargs , ** (generation_kwargs or {})}
223
225
224
226
watsonx_messages = []
227
+ content : Union [Optional [str ], Dict [str , Any ]]
225
228
for msg in messages :
226
229
if msg .is_from ("user" ):
227
230
content = msg .text
@@ -347,7 +350,10 @@ def _process_response(self, response: dict[str, Any]) -> dict[str, Any]:
347
350
ToolCall (id = tc .get ("id" ), tool_name = tc ["function" ]["name" ], arguments = arguments )
348
351
)
349
352
except json .JSONDecodeError :
350
- logger .warning ("Failed to parse tool call arguments: %s" , tc ["function" ]["arguments" ])
353
+ logger .warning (
354
+ "Failed to parse tool call arguments: {tool_call_args}" ,
355
+ tool_call_args = tc ["function" ]["arguments" ]
356
+ )
351
357
352
358
return {
353
359
"replies" : [
0 commit comments