MCPcopy Create free account
hub / github.com/AsyncFuncAI/deepwiki-open / __init__

Method __init__

api/openai_client.py:161–188  ·  view source on GitHub ↗

r"""It is recommended to set the OPENAI_API_KEY environment variable instead of passing it as an argument. Args: api_key (Optional[str], optional): OpenAI API key. Defaults to None. base_url (str): The API base URL to use when initializing the client. env

(
        self,
        api_key: Optional[str] = None,
        chat_completion_parser: Callable[[Completion], Any] = None,
        input_type: Literal["text", "messages"] = "text",
        base_url: Optional[str] = None,
        env_base_url_name: str = "OPENAI_BASE_URL",
        env_api_key_name: str = "OPENAI_API_KEY",
    )

Source from the content-addressed store, hash-verified

159 """
160
161 def __init__(
162 self,
163 api_key: Optional[str] = None,
164 chat_completion_parser: Callable[[Completion], Any] = None,
165 input_type: Literal["text", "messages"] = "text",
166 base_url: Optional[str] = None,
167 env_base_url_name: str = "OPENAI_BASE_URL",
168 env_api_key_name: str = "OPENAI_API_KEY",
169 ):
170 r"""It is recommended to set the OPENAI_API_KEY environment variable instead of passing it as an argument.
171
172 Args:
173 api_key (Optional[str], optional): OpenAI API key. Defaults to None.
174 base_url (str): The API base URL to use when initializing the client.
175 env_api_key_name (str): The environment variable name for the API key. Defaults to `"OPENAI_API_KEY"`.
176 """
177 super().__init__()
178 self._api_key = api_key
179 self._env_api_key_name = env_api_key_name
180 self._env_base_url_name = env_base_url_name
181 self.base_url = base_url or os.getenv(self._env_base_url_name, "https://api.openai.com/v1")
182 self.sync_client = self.init_sync_client()
183 self.async_client = None # only initialize if the async call is called
184 self.chat_completion_parser = (
185 chat_completion_parser or get_first_message_content
186 )
187 self._input_type = input_type
188 self._api_kwargs = {} # add api kwargs when the OpenAI Client is called
189
190 def init_sync_client(self):
191 api_key = self._api_key or os.getenv(self._env_api_key_name)

Callers

nothing calls this directly

Calls 1

init_sync_clientMethod · 0.95

Tested by

no test coverage detected