docs(configuration): document optional base_url parameter for OpenAI

Add explanation for the optional base_url parameter in genai.md, allowing custom endpoint configuration for OpenAI API. Update logic in openai.py to handle empty string by setting base_url to None.
This commit is contained in:
Sergey Krashevich 2024-11-13 16:11:34 +03:00
parent cad422f52d
commit ce29ccda8d
No known key found for this signature in database
GPG Key ID: 625171324E7D3856
2 changed files with 6 additions and 3 deletions

View File

@ -112,9 +112,12 @@ genai:
provider: openai provider: openai
api_key: "{FRIGATE_OPENAI_API_KEY}" api_key: "{FRIGATE_OPENAI_API_KEY}"
model: gpt-4o model: gpt-4o
base_url: https://api.openai.com/v1 base_url: http://example.endpoint/v1 # optional
``` ```
### Optional base_url Parameter
The base_url parameter is an optional configuration setting that allows you to specify a custom endpoint for the OpenAI API. By default, the OpenAI client uses the standard API endpoint provided by OpenAI. However, if you need to route your requests through a different server or use a proxy, you can set this parameter to the desired URL.
## Azure OpenAI ## Azure OpenAI
Microsoft offers several vision models through Azure OpenAI. A subscription is required. Microsoft offers several vision models through Azure OpenAI. A subscription is required.

View File

@ -22,8 +22,8 @@ class OpenAIClient(GenAIClient):
def _init_provider(self): def _init_provider(self):
"""Initialize the client.""" """Initialize the client."""
if self.genai_config.base_url is None or self.genai_config.base_url == "": if self.genai_config.base_url == "":
self.genai_config.base_url = "https://api.openai.com/v1" self.genai_config.base_url = None
return OpenAI( return OpenAI(
api_key=self.genai_config.api_key, base_url=self.genai_config.base_url api_key=self.genai_config.api_key, base_url=self.genai_config.base_url