(
self,
*,
messages: List[llama_types.ChatCompletionRequestMessage],
functions: Optional[List[llama_types.ChatCompletionFunction]] = None,
function_call: Optional[llama_types.ChatCompletionRequestFunctionCall] = None,
tools: Optional[List[llama_types.ChatCompletionTool]] = None,
tool_choice: Optional[llama_types.ChatCompletionToolChoiceOption] = None,
**kwargs: Any,
)
| 256 | ) |
| 257 | |
| 258 | def __call__( |
| 259 | self, |
| 260 | *, |
| 261 | messages: List[llama_types.ChatCompletionRequestMessage], |
| 262 | functions: Optional[List[llama_types.ChatCompletionFunction]] = None, |
| 263 | function_call: Optional[llama_types.ChatCompletionRequestFunctionCall] = None, |
| 264 | tools: Optional[List[llama_types.ChatCompletionTool]] = None, |
| 265 | tool_choice: Optional[llama_types.ChatCompletionToolChoiceOption] = None, |
| 266 | **kwargs: Any, |
| 267 | ) -> ChatFormatterResponse: |
| 268 | def raise_exception(message: str): |
| 269 | raise ValueError(message) |
| 270 | |
| 271 | prompt = self._environment.render( |
| 272 | messages=messages, |
| 273 | eos_token=self.eos_token, |
| 274 | bos_token=self.bos_token, |
| 275 | raise_exception=raise_exception, |
| 276 | add_generation_prompt=self.add_generation_prompt, |
| 277 | functions=functions, |
| 278 | function_call=function_call, |
| 279 | tools=tools, |
| 280 | tool_choice=tool_choice, |
| 281 | strftime_now=self.strftime_now, |
| 282 | **kwargs, |
| 283 | ) |
| 284 | |
| 285 | stopping_criteria = None |
| 286 | if self.stop_token_ids is not None: |
| 287 | |
| 288 | def stop_on_last_token( |
| 289 | tokens: npt.NDArray[np.intc], logits: npt.NDArray[np.single] |
| 290 | ) -> bool: |
| 291 | return tokens[-1] in self.stop_token_ids |
| 292 | |
| 293 | stopping_criteria = llama.StoppingCriteriaList([stop_on_last_token]) |
| 294 | |
| 295 | return ChatFormatterResponse( |
| 296 | prompt=prompt, |
| 297 | stop=[self.eos_token], |
| 298 | stopping_criteria=stopping_criteria, |
| 299 | added_special=True, |
| 300 | ) |
| 301 | |
| 302 | def to_chat_handler(self) -> LlamaChatCompletionHandler: |
| 303 | return chat_formatter_to_chat_completion_handler(self) |
nothing calls this directly
no test coverage detected