feat(genai): add configurable base_url for OpenAI API integration

This commit is contained in:
Sergey Krashevich 2024-11-13 14:34:22 +03:00
parent ed9c67804a
commit cad422f52d
No known key found for this signature in database
GPG Key ID: 625171324E7D3856
2 changed files with 8 additions and 1 deletions

View File

@ -112,6 +112,7 @@ 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
``` ```
## Azure OpenAI ## Azure OpenAI

View File

@ -21,7 +21,13 @@ class OpenAIClient(GenAIClient):
def _init_provider(self): def _init_provider(self):
"""Initialize the client.""" """Initialize the client."""
return OpenAI(api_key=self.genai_config.api_key)
if self.genai_config.base_url is None or self.genai_config.base_url == "":
self.genai_config.base_url = "https://api.openai.com/v1"
return OpenAI(
api_key=self.genai_config.api_key, base_url=self.genai_config.base_url
)
def _send(self, prompt: str, images: list[bytes]) -> Optional[str]: def _send(self, prompt: str, images: list[bytes]) -> Optional[str]:
"""Submit a request to OpenAI.""" """Submit a request to OpenAI."""