Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

skrashevich
Copy link
Contributor

@skrashevich skrashevich commented Nov 13, 2024

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

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • The code has been formatted using Ruff (ruff format frigate)

Copy link

netlify bot commented Nov 13, 2024

Deploy Preview for frigate-docs ready!

Name Link
🔨 Latest commit ce29ccd
🔍 Latest deploy log https://app.netlify.com/sites/frigate-docs/deploys/6734a5907c170100089ee65f
😎 Deploy Preview https://deploy-preview-14953--frigate-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

frigate/genai/openai.py Outdated Show resolved Hide resolved
docs/docs/configuration/genai.md Outdated Show resolved Hide resolved
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.
Copy link
Collaborator

@hawkeye217 hawkeye217 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't test this directly, but if you've tested it with and without a base_url and it works, I think this can be merged. Please confirm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants