fix: update base url to use environment variables#174
Conversation
There was a problem hiding this comment.
Hello @abhijitjavelin, 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!
Summary of Changes
This pull request focuses on updating the base URL for the Javelin client configuration to utilize environment variables instead of hardcoded values. This change promotes better configuration management and allows for easier switching between different environments (e.g., development, staging, production) without modifying the code directly. The changes affect multiple example files across different language model providers (Anthropic, Azure OpenAI, Gemini, Mistral, OpenAI) and various use cases, including universal endpoints, general routes, and Langchain integrations.
Highlights
- Configuration: The base URL for the Javelin client is now sourced from the
JAVELIN_BASE_URLenvironment variable. - Environment Management: This change simplifies environment-specific configurations by using environment variables.
- Consistency: The update ensures consistency across different example files and language model providers.
Changelog
Click here to see the changelog
- examples/anthropic/javelin_anthropic_univ_endpoint.py
- Updated
base_urlinJavelinConfigto useos.getenv("JAVELIN_BASE_URL").
- Updated
- examples/anthropic/openai_compatible_univ_anthropic.py
- Updated
base_urlinJavelinConfigto useos.getenv("JAVELIN_BASE_URL").
- Updated
- examples/azure-openai/azure_general_route.py
- Updated
base_urlinAzureOpenAIclient initialization to usef"{os.getenv('JAVELIN_BASE_URL')}/v1/query/azure-openai".
- Updated
- examples/azure-openai/azure_openai_javelin_stream_&_non-stream.js
- Updated
urlingetCompletionfunction to use${process.env.JAVELIN_BASE_URL}/v1/query/${routeName}.
- Updated
- examples/azure-openai/javelin_azureopenai_univ_endpoint.py
- Updated
base_urlinJavelinConfigto useos.getenv("JAVELIN_BASE_URL").
- Updated
- examples/azure-openai/langchain_azure_universal.py
- Updated
base_urlto useos.getenv("JAVELIN_BASE_URL")and removed the default value.
- Updated
- examples/azure-openai/langchain_chatmodel_example.py
- Updated
azure_endpointinAzureChatOpenAIto useos.path.join(os.getenv("JAVELIN_BASE_URL"), "v1").
- Updated
- examples/azure-openai/openai_compatible_univ_azure.py
- Updated
base_urlinJavelinConfigto useos.getenv("JAVELIN_BASE_URL").
- Updated
- examples/bedrock/bedrock_client_universal.py
- Added
base_url=os.getenv("JAVELIN_BASE_URL")toJavelinConfig.
- Added
- examples/bedrock/bedrock_general_route.py
- Updated
endpoint_urlinboto3.clientto useos.path.join(os.getenv("JAVELIN_BASE_URL"), "v1").
- Updated
- examples/bedrock/javelin_bedrock_univ_endpoint.py
- Updated
base_urlinJavelinConfigto useos.getenv("JAVELIN_BASE_URL").
- Updated
- examples/bedrock/langchain-bedrock-universal.py
- Added
base_url=os.getenv("JAVELIN_BASE_URL")toJavelinConfig.
- Added
- examples/bedrock/openai_compatible_univ_bedrock.py
- Updated
base_urlinJavelinConfigto useos.getenv("JAVELIN_BASE_URL").
- Updated
- examples/gemini/document_processing.py
- Added
base_url=os.getenv("JAVELIN_BASE_URL")toJavelinConfig.
- Added
- examples/gemini/gemini-universal.py
- Added
base_url=os.getenv("JAVELIN_BASE_URL")toJavelinConfig.
- Added
- examples/gemini/javelin_gemini_univ_endpoint.py
- Updated
base_urlinJavelinConfigto useos.getenv("JAVELIN_BASE_URL").
- Updated
- examples/gemini/langchain_chatmodel_example.py
- Updated
base_urlininit_chat_modelto usef"{os.getenv('JAVELIN_BASE_URL')}/v1".
- Updated
- examples/gemini/openai_compatible_univ_gemini.py
- Updated
base_urlinJavelinConfigto useos.getenv("JAVELIN_BASE_URL").
- Updated
- examples/gemini/strawberry.py
- Updated
base_urlinJavelinConfigto useos.getenv("JAVELIN_BASE_URL").
- Updated
- examples/mistral/langchain_chatmodel_example.py
- Updated
base_urlininit_chat_modelto usef"{os.getenv('JAVELIN_BASE_URL')}/v1".
- Updated
- examples/openai/javelin_openai_univ_endpoint.py
- Updated
base_urlinJavelinConfigto useos.getenv("JAVELIN_BASE_URL").
- Updated
- examples/openai/langchain-openai-universal.py
- Updated
BASE_URLto useos.getenv("JAVELIN_BASE_URL")and removed the default value.
- Updated
- examples/openai/langchain_callback_example.py
- New file added to demonstrate header callback handler.
- examples/openai/langchain_chatmodel_example.py
- Updated
base_urlininit_chat_modelto usef"{os.getenv('JAVELIN_BASE_URL')}/v1".
- Updated
- examples/openai/o1-03_function-calling.py
- Added
base_url=os.getenv("JAVELIN_BASE_URL")toJavelinConfig.
- Added
- examples/openai/openai-azure-fun_calling.ipynb
- Added
base_url=os.getenv("JAVELIN_BASE_URL")toJavelinConfig.
- Added
- examples/openai/openai-universal.py
- Added
base_url=os.getenv("JAVELIN_BASE_URL")toJavelinConfigininit_javelin_client_sync. - Added
base_url=os.getenv("JAVELIN_BASE_URL")toJavelinConfigininit_javelin_client_async.
- Added
- examples/openai/openai_compatible_univ.py
- Updated
base_urlinJavelinConfigto useos.getenv("JAVELIN_BASE_URL").
- Updated
- examples/openai/openai_embedding_example.py
- Updated
openai_api_baseinChatOpenAIto usef"{os.getenv('JAVELIN_BASE_URL')}/v1/query".
- Updated
- examples/openai/openai_general_route.py
- Updated
base_urlinOpenAIclient initialization to usef"{os.getenv('JAVELIN_BASE_URL')}/v1/query/openai".
- Updated
- examples/openai/openai_javelin_stream&non-stream.js
- Updated
baseURLinOpenAIclient initialization to use${process.env.JAVELIN_BASE_URL}/v1/query.
- Updated
- examples/rag/javelin_rag_embeddings_demo.ipynb
- Updated
base_urlinAzureOpenAIclient initialization to useos.getenv("JAVELIN_BASE_URL"). - Updated
azure_endpointinAzureChatOpenAIclient initialization to usef"{os.getenv('JAVELIN_BASE_URL')}/query/azureopenai".
- Updated
- examples/rag/rag_implemetation_javelin.ipynb
- Updated
base_urlinJavelinConfigto useos.getenv("JAVELIN_BASE_URL").
- Updated
- examples/route_examples/aexample.py
- Updated
base_urlinJavelinConfigto useos.getenv("JAVELIN_BASE_URL").
- Updated
- examples/route_examples/drop_in_replacement.py
- Added
base_url=os.getenv("JAVELIN_BASE_URL")toJavelinConfig.
- Added
- examples/route_examples/example.py
- Updated
base_urlinJavelinConfigto useos.getenv("JAVELIN_BASE_URL").
- Updated
- examples/route_examples/javelin_sdk_app.py
- Updated
base_urlinJavelinConfigto useos.getenv("JAVELIN_BASE_URL").
- Updated
- javelin_sdk/services/secret_service.py
- Added
api_key_secret_keyto the list of keys to check for inupdate_secret.
- Added
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 is currently in preview and 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 to provide feedback.
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.
Env vars whisper,
Configs dance in the cloud's embrace,
Code finds its true home.
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.
Code Review
The pull request updates the base URL to use environment variables across multiple example files. This change promotes configurability and avoids hardcoding the base URL. The changes look good overall, but I have a few suggestions to improve clarity and robustness.
Summary of Findings
- Missing Default Value for Environment Variable: In
examples/azure-openai/langchain_azure_universal.py, the default value for theJAVELIN_BASE_URLenvironment variable was removed. It's important to provide a default value to ensure the application functions correctly even if the environment variable is not set. - Inconsistent use of
os.path.join: Some files useos.path.jointo construct the base URL, while others use f-strings. Consistency in URL construction improves readability and maintainability. - Print statement in production code: The file
examples/azure-openai/langchain_chatmodel_example.pycontains a print statement that should be removed before merging.
Merge Readiness
The pull request is almost ready for merging. However, I recommend addressing the missing default value in examples/azure-openai/langchain_azure_universal.py and removing the print statement in examples/azure-openai/langchain_chatmodel_example.py before merging. I am unable to approve this pull request, and recommend that others review and approve this code before merging.
| base_url = os.getenv( | ||
| "JAVELIN_BASE_URL", "https://api.javelin.live" | ||
| ) # Default to generic base URL | ||
| base_url = os.getenv("JAVELIN_BASE_URL") |
There was a problem hiding this comment.
The default value for JAVELIN_BASE_URL was removed. It's good practice to provide a default value in case the environment variable is not set. What do you think about adding it back?
| base_url = os.getenv("JAVELIN_BASE_URL") | |
| base_url = os.getenv("JAVELIN_BASE_URL", "https://api.javelin.live") |
| client = AzureOpenAI( | ||
| api_key=llm_api_key, | ||
| base_url="https://api-dev.javelin.live/v1/query/azure-openai", | ||
| base_url=f"{os.getenv('JAVELIN_BASE_URL')}/v1/query/azure-openai", |
| from langchain_openai import AzureChatOpenAI | ||
|
|
||
| url = os.path.join(os.getenv("JAVELIN_BASE_URL"), "v1") | ||
| print(url) |
| "api_key", | ||
| "api_key_secret_key_javelin", | ||
| "provider_name", | ||
| "api_key_secret_key" |
No description provided.