|
7 | 7 |
|
8 | 8 | from haystack import component, default_to_dict, logging |
9 | 9 | from haystack.components.generators.chat import OpenAIChatGenerator |
10 | | -from haystack.dataclasses import StreamingCallbackT |
| 10 | +from haystack.dataclasses import ChatMessage, StreamingCallbackT |
11 | 11 | from haystack.tools import Tool, Toolset |
12 | 12 | from haystack.utils import serialize_callable |
13 | 13 | from haystack.utils.auth import Secret |
@@ -104,6 +104,27 @@ def __init__( |
104 | 104 | tools=tools, |
105 | 105 | ) |
106 | 106 |
|
| 107 | + def _prepare_api_call( |
| 108 | + self, |
| 109 | + *, |
| 110 | + messages: list[ChatMessage], |
| 111 | + streaming_callback: Optional[StreamingCallbackT] = None, |
| 112 | + generation_kwargs: Optional[dict[str, Any]] = None, |
| 113 | + tools: Optional[Union[list[Tool], Toolset]] = None, |
| 114 | + tools_strict: Optional[bool] = None, |
| 115 | + ) -> dict[str, Any]: |
| 116 | + api_args = super(MetaLlamaChatGenerator, self)._prepare_api_call( # noqa: UP008 |
| 117 | + messages=messages, |
| 118 | + streaming_callback=streaming_callback, |
| 119 | + generation_kwargs=generation_kwargs, |
| 120 | + tools=tools, |
| 121 | + tools_strict=tools_strict, |
| 122 | + ) |
| 123 | + # Meta Llama API does not support None as a value for response_format |
| 124 | + if "response_format" in api_args and api_args["response_format"] is None: |
| 125 | + api_args.pop("response_format") |
| 126 | + return api_args |
| 127 | + |
107 | 128 | def to_dict(self) -> Dict[str, Any]: |
108 | 129 | """ |
109 | 130 | Serialize this component to a dictionary. |
|
0 commit comments