-
-
Notifications
You must be signed in to change notification settings - Fork 839
feat(openai): respect OPENAI_BASE_URL and OPENAI_API_BASE env vars #254
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
base: main
Are you sure you want to change the base?
feat(openai): respect OPENAI_BASE_URL and OPENAI_API_BASE env vars #254
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @dschrengost, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request introduces a significant enhancement to the OpenAI provider by enabling it to respect OPENAI_BASE_URL and OPENAI_API_BASE environment variables for configuring the API endpoint. This change provides greater flexibility for routing API traffic, such as through proxies or custom test environments, and aligns the provider's behavior with other official OpenAI SDKs. Additionally, it incorporates comprehensive logging to aid in debugging and understanding the flow of API configurations and requests.
Highlights
- Environment Variable Support for Base URL: The OpenAI provider now respects
OPENAI_BASE_URLandOPENAI_API_BASEenvironment variables, allowing users to easily route API calls through proxies, gateways, or test endpoints. These environment variables take precedence over anybase_urlargument provided directly. - Environment Variable Support for Organization: The
organizationparameter for OpenAI API calls can now also be configured via theOPENAI_ORGenvironment variable, aligning with standard OpenAI SDK behavior. - Enhanced Debugging and Observability: Extensive debug and warning logging has been added throughout the OpenAI provider's initialization and request lifecycle. This includes logging when environment variables override explicit settings, details of client initialization, and information about each API call attempt, significantly improving observability.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a valuable feature by allowing OPENAI_BASE_URL and related environment variables to configure the OpenAI provider, which greatly improves flexibility for using proxies or custom endpoints. The addition of debug logging is also helpful for troubleshooting.
My review focuses on two main points:
- There's an inconsistency in the precedence of configuration sources (environment variables vs. arguments) between
base_urlandorganization. - The log levels for the newly added debug messages are inconsistent, with some informational logs being emitted as warnings.
Addressing these points will improve the consistency and usability of the new functionality. Please see the detailed comments for specific suggestions.
| # Organization can also be provided via env for official API usage | ||
| self.organization = kwargs.get("organization") or os.getenv("OPENAI_ORG") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an inconsistency in how configuration precedence is handled. For base_url, environment variables take precedence over arguments, but for organization, it's the other way around. This is also contrary to the PR's goal of matching other OpenAI SDKs, which prioritize arguments over environment variables.
For consistency within this provider and to align with the goal of allowing environment overrides, I recommend prioritizing environment variables for organization as well. You might also want to add a warning log when an override occurs, similar to base_url.
Also, consider supporting the standard OPENAI_ORGANIZATION environment variable in addition to OPENAI_ORG for better compatibility.
| # Organization can also be provided via env for official API usage | |
| self.organization = kwargs.get("organization") or os.getenv("OPENAI_ORG") | |
| # Organization can also be provided via env for official API usage | |
| env_org = os.getenv("OPENAI_ORGANIZATION") or os.getenv("OPENAI_ORG") | |
| kw_org = kwargs.get("organization") | |
| if env_org and kw_org and env_org != kw_org: | |
| logger.warning("[ZEN DEBUG] Overriding provided organization=%r with env=%r", kw_org, env_org) | |
| self.organization = env_org or kw_org |
| logger.warning( | ||
| "[ZEN DEBUG] OPENAI_BASE_URL env=%r effective=%r", | ||
| env_base_url, | ||
| self.base_url, | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new logging messages prefixed with [ZEN DEBUG] use inconsistent log levels. Some informational messages are logged as WARNING, which could add unnecessary noise to the logs for users who have set their log level to WARNING.
For example, this log message is purely informational and would be better suited for the INFO or DEBUG level.
I recommend reviewing all new [ZEN DEBUG] logs and changing the ones that are informational from logger.warning to logger.info or logger.debug. This applies to other places in this file as well, such as lines 52-56, 282-287, and 605-611.
| logger.warning( | |
| "[ZEN DEBUG] OPENAI_BASE_URL env=%r effective=%r", | |
| env_base_url, | |
| self.base_url, | |
| ) | |
| logger.info( | |
| "[ZEN DEBUG] OPENAI_BASE_URL env=%r effective=%r", | |
| env_base_url, | |
| self.base_url, | |
| ) |
This PR updates the OpenAI provider to respect
OPENAI_BASE_URL(and legacyOPENAI_API_BASE)environment variables.