feat(genai): add configurable base_url for OpenAI API integration #14953
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Description: Add Configurable base_url for OpenAI API Integration
Overview
This pull request introduces a new feature that enhances the integration with the OpenAI API by allowing the base_url to be configurable. This flexibility is particularly useful for scenarios where the default OpenAI API endpoint needs to be changed or for testing against mock servers.
Changes Made
• Configuration Update: Modified the configuration file genai.md to include base_url as a new configurable parameter. The default value is set to https://api.openai.com/v1 .
• Code Enhancements: Updated the OpenAIClient class in frigate/genai/openai.py to support the new base_url configuration parameter:
• If base_url is not provided or is empty, it defaults to https://api.openai.com/v1 .
• The OpenAI client is now initialized with both api_key and base_url .
Benefits
• Increased Flexibility: Users can now specify a different API endpoint if needed, which enhances the adaptability of the integration to different deployment environments or testing needs.
• Backward Compatibility: Existing configurations continue to work without modification, thanks to the default value setting.
Files Changed
• docs/docs/configuration/genai.md : Added documentation for the new base_url configuration option.
• frigate/genai/openai.py : Updated the OpenAI client initialization to incorporate the configurable base_url .
Use Case
Users who wish to utilize an alternative endpoint or a self-hosted proxy for the OpenAI API can now simply adjust the base_url parameter in their configuration settings, making the client versatile for various setups.
Checklist
ruff format frigate
)