From 6832e3155154cb42ada01d2d2bf5e280073cabc1 Mon Sep 17 00:00:00 2001 From: anakin87 Date: Thu, 19 Dec 2024 14:40:59 +0100 Subject: [PATCH] feedback --- .../components/generators/chat/hugging_face_api.py | 14 +++++++------- haystack/dataclasses/tool.py | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/haystack/components/generators/chat/hugging_face_api.py b/haystack/components/generators/chat/hugging_face_api.py index 8e7a6dac18..dab61e4d93 100644 --- a/haystack/components/generators/chat/hugging_face_api.py +++ b/haystack/components/generators/chat/hugging_face_api.py @@ -322,15 +322,15 @@ def _run_non_streaming( ) tool_calls.append(tool_call) - meta = { - "model": self._client.model, - "finish_reason": choice.finish_reason, - "index": choice.index, - "usage": { + meta = {"model": self._client.model, "finish_reason": choice.finish_reason, "index": choice.index} + + usage = {"prompt_tokens": 0, "completion_tokens": 0} + if api_chat_output.usage: + usage = { "prompt_tokens": api_chat_output.usage.prompt_tokens, "completion_tokens": api_chat_output.usage.completion_tokens, - }, - } + } + meta["usage"] = usage message = ChatMessage.from_assistant(text=text, tool_calls=tool_calls, meta=meta) return {"replies": [message]} diff --git a/haystack/dataclasses/tool.py b/haystack/dataclasses/tool.py index 4aaf1e2bd1..c6606d51e8 100644 --- a/haystack/dataclasses/tool.py +++ b/haystack/dataclasses/tool.py @@ -218,7 +218,7 @@ def _remove_title_from_schema(schema: Dict[str, Any]): def _check_duplicate_tool_names(tools: List[Tool]) -> None: """ - Check for duplicate tool names. + Check for duplicate tool names and raises a ValueError if they are found. :param tools: The list of tools to check. :raises ValueError: If duplicate tool names are found.