r"""Runs inference of OpenAI 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],
)
| 122 | ) |
| 123 | |
| 124 | def run( |
| 125 | self, |
| 126 | messages: List[OpenAIMessage], |
| 127 | ) -> Union[ChatCompletion, Stream[ChatCompletionChunk]]: |
| 128 | r"""Runs inference of OpenAI chat completion. |
| 129 | |
| 130 | Args: |
| 131 | messages (List[OpenAIMessage]): Message list with the chat history |
| 132 | in OpenAI API format. |
| 133 | |
| 134 | Returns: |
| 135 | Union[ChatCompletion, Stream[ChatCompletionChunk]]: |
| 136 | `ChatCompletion` in the non-stream mode, or |
| 137 | `Stream[ChatCompletionChunk]` in the stream mode. |
| 138 | """ |
| 139 | from pprint import pprint |
| 140 | # _validate_messages(messages) # new helper |
| 141 | # pprint(messages, depth=2) |
| 142 | |
| 143 | # print([m["role"] for m in messages]) |
| 144 | |
| 145 | response = self._client.chat.completions.create( |
| 146 | messages=messages, |
| 147 | model=self.model_type, |
| 148 | **self.model_config_dict, |
| 149 | ) |
| 150 | return response |
| 151 | |
| 152 | @property |
| 153 | def stream(self) -> bool: |