Generate a chat completion with return type based on the the OpenAI v1 API. OpenAI python package is required to use this method. You can install it with `pip install openai`. Args: *args: Positional arguments to pass to create_chat_completion. **kw
(
self,
*args: Any,
**kwargs: Any,
)
| 2098 | ) |
| 2099 | |
| 2100 | def create_chat_completion_openai_v1( |
| 2101 | self, |
| 2102 | *args: Any, |
| 2103 | **kwargs: Any, |
| 2104 | ): |
| 2105 | """Generate a chat completion with return type based on the the OpenAI v1 API. |
| 2106 | |
| 2107 | OpenAI python package is required to use this method. |
| 2108 | |
| 2109 | You can install it with `pip install openai`. |
| 2110 | |
| 2111 | Args: |
| 2112 | *args: Positional arguments to pass to create_chat_completion. |
| 2113 | **kwargs: Keyword arguments to pass to create_chat_completion. |
| 2114 | |
| 2115 | Returns: |
| 2116 | Generated chat completion or a stream of chat completion chunks. |
| 2117 | """ |
| 2118 | try: |
| 2119 | from openai.types.chat import ChatCompletion, ChatCompletionChunk |
| 2120 | |
| 2121 | stream = kwargs.get("stream", False) # type: ignore |
| 2122 | assert isinstance(stream, bool) |
| 2123 | if stream: |
| 2124 | return ( |
| 2125 | ChatCompletionChunk(**chunk) |
| 2126 | for chunk in self.create_chat_completion(*args, **kwargs) |
| 2127 | ) # type: ignore |
| 2128 | else: |
| 2129 | return ChatCompletion(**self.create_chat_completion(*args, **kwargs)) # type: ignore |
| 2130 | except ImportError: |
| 2131 | raise ImportError( |
| 2132 | "To use create_chat_completion_openai_v1, you must install the openai package." |
| 2133 | "You can install it with `pip install openai`." |
| 2134 | ) |
| 2135 | |
| 2136 | def __getstate__(self): |
| 2137 | return dict( |
no test coverage detected