From cad422f52dc17a7f18846dcd5a19767f4a7ef5a8 Mon Sep 17 00:00:00 2001 From: Sergey Krashevich Date: Wed, 13 Nov 2024 14:34:22 +0300 Subject: [PATCH] feat(genai): add configurable base_url for OpenAI API integration --- docs/docs/configuration/genai.md | 1 + frigate/genai/openai.py | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/docs/configuration/genai.md b/docs/docs/configuration/genai.md index 2ec9a6276..68ea054d1 100644 --- a/docs/docs/configuration/genai.md +++ b/docs/docs/configuration/genai.md @@ -112,6 +112,7 @@ genai: provider: openai api_key: "{FRIGATE_OPENAI_API_KEY}" model: gpt-4o + base_url: https://api.openai.com/v1 ``` ## Azure OpenAI diff --git a/frigate/genai/openai.py b/frigate/genai/openai.py index 4568905a3..0d3ecaf65 100644 --- a/frigate/genai/openai.py +++ b/frigate/genai/openai.py @@ -21,7 +21,13 @@ class OpenAIClient(GenAIClient): def _init_provider(self): """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]: """Submit a request to OpenAI."""