r"""Runs inference of NVIDIA chat completion. Args: messages (List[OpenAIMessage]): Message list with the chat history in OpenAI API format. Returns: Union[ChatCompletion, Stream[ChatCompletionChunk]]: `ChatCompletion` in the
(
self,
messages: List[OpenAIMessage],
)
| 78 | ) |
| 79 | |
| 80 | def run( |
| 81 | self, |
| 82 | messages: List[OpenAIMessage], |
| 83 | ) -> Union[ChatCompletion, Stream[ChatCompletionChunk]]: |
| 84 | r"""Runs inference of NVIDIA chat completion. |
| 85 | |
| 86 | Args: |
| 87 | messages (List[OpenAIMessage]): Message list with the chat history |
| 88 | in OpenAI API format. |
| 89 | |
| 90 | Returns: |
| 91 | Union[ChatCompletion, Stream[ChatCompletionChunk]]: |
| 92 | `ChatCompletion` in the non-stream mode, or |
| 93 | `Stream[ChatCompletionChunk]` in the stream mode. |
| 94 | """ |
| 95 | |
| 96 | # Remove tool-related parameters if no tools are specified |
| 97 | config = dict(self.model_config_dict) |
| 98 | if not config.get('tools'): # None or empty list |
| 99 | config.pop('tools', None) |
| 100 | config.pop('tool_choice', None) |
| 101 | |
| 102 | response = self._client.chat.completions.create( |
| 103 | messages=messages, |
| 104 | model=self.model_type, |
| 105 | **config, |
| 106 | ) |
| 107 | return response |
| 108 | |
| 109 | @property |
| 110 | def token_counter(self) -> BaseTokenCounter: |