Skip to content

fix: update base url to use environment variables#174

Merged
ankumar merged 2 commits intomainfrom
update_baseurl
Apr 5, 2025
Merged

fix: update base url to use environment variables#174
ankumar merged 2 commits intomainfrom
update_baseurl

Conversation

@abhijitjavelin
Copy link
Copy Markdown
Contributor

No description provided.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

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_URL environment 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_url in JavelinConfig to use os.getenv("JAVELIN_BASE_URL").
  • examples/anthropic/openai_compatible_univ_anthropic.py
    • Updated base_url in JavelinConfig to use os.getenv("JAVELIN_BASE_URL").
  • examples/azure-openai/azure_general_route.py
    • Updated base_url in AzureOpenAI client initialization to use f"{os.getenv('JAVELIN_BASE_URL')}/v1/query/azure-openai".
  • examples/azure-openai/azure_openai_javelin_stream_&_non-stream.js
    • Updated url in getCompletion function to use ${process.env.JAVELIN_BASE_URL}/v1/query/${routeName}.
  • examples/azure-openai/javelin_azureopenai_univ_endpoint.py
    • Updated base_url in JavelinConfig to use os.getenv("JAVELIN_BASE_URL").
  • examples/azure-openai/langchain_azure_universal.py
    • Updated base_url to use os.getenv("JAVELIN_BASE_URL") and removed the default value.
  • examples/azure-openai/langchain_chatmodel_example.py
    • Updated azure_endpoint in AzureChatOpenAI to use os.path.join(os.getenv("JAVELIN_BASE_URL"), "v1").
  • examples/azure-openai/openai_compatible_univ_azure.py
    • Updated base_url in JavelinConfig to use os.getenv("JAVELIN_BASE_URL").
  • examples/bedrock/bedrock_client_universal.py
    • Added base_url=os.getenv("JAVELIN_BASE_URL") to JavelinConfig.
  • examples/bedrock/bedrock_general_route.py
    • Updated endpoint_url in boto3.client to use os.path.join(os.getenv("JAVELIN_BASE_URL"), "v1").
  • examples/bedrock/javelin_bedrock_univ_endpoint.py
    • Updated base_url in JavelinConfig to use os.getenv("JAVELIN_BASE_URL").
  • examples/bedrock/langchain-bedrock-universal.py
    • Added base_url=os.getenv("JAVELIN_BASE_URL") to JavelinConfig.
  • examples/bedrock/openai_compatible_univ_bedrock.py
    • Updated base_url in JavelinConfig to use os.getenv("JAVELIN_BASE_URL").
  • examples/gemini/document_processing.py
    • Added base_url=os.getenv("JAVELIN_BASE_URL") to JavelinConfig.
  • examples/gemini/gemini-universal.py
    • Added base_url=os.getenv("JAVELIN_BASE_URL") to JavelinConfig.
  • examples/gemini/javelin_gemini_univ_endpoint.py
    • Updated base_url in JavelinConfig to use os.getenv("JAVELIN_BASE_URL").
  • examples/gemini/langchain_chatmodel_example.py
    • Updated base_url in init_chat_model to use f"{os.getenv('JAVELIN_BASE_URL')}/v1".
  • examples/gemini/openai_compatible_univ_gemini.py
    • Updated base_url in JavelinConfig to use os.getenv("JAVELIN_BASE_URL").
  • examples/gemini/strawberry.py
    • Updated base_url in JavelinConfig to use os.getenv("JAVELIN_BASE_URL").
  • examples/mistral/langchain_chatmodel_example.py
    • Updated base_url in init_chat_model to use f"{os.getenv('JAVELIN_BASE_URL')}/v1".
  • examples/openai/javelin_openai_univ_endpoint.py
    • Updated base_url in JavelinConfig to use os.getenv("JAVELIN_BASE_URL").
  • examples/openai/langchain-openai-universal.py
    • Updated BASE_URL to use os.getenv("JAVELIN_BASE_URL") and removed the default value.
  • examples/openai/langchain_callback_example.py
    • New file added to demonstrate header callback handler.
  • examples/openai/langchain_chatmodel_example.py
    • Updated base_url in init_chat_model to use f"{os.getenv('JAVELIN_BASE_URL')}/v1".
  • examples/openai/o1-03_function-calling.py
    • Added base_url=os.getenv("JAVELIN_BASE_URL") to JavelinConfig.
  • examples/openai/openai-azure-fun_calling.ipynb
    • Added base_url=os.getenv("JAVELIN_BASE_URL") to JavelinConfig.
  • examples/openai/openai-universal.py
    • Added base_url=os.getenv("JAVELIN_BASE_URL") to JavelinConfig in init_javelin_client_sync.
    • Added base_url=os.getenv("JAVELIN_BASE_URL") to JavelinConfig in init_javelin_client_async.
  • examples/openai/openai_compatible_univ.py
    • Updated base_url in JavelinConfig to use os.getenv("JAVELIN_BASE_URL").
  • examples/openai/openai_embedding_example.py
    • Updated openai_api_base in ChatOpenAI to use f"{os.getenv('JAVELIN_BASE_URL')}/v1/query".
  • examples/openai/openai_general_route.py
    • Updated base_url in OpenAI client initialization to use f"{os.getenv('JAVELIN_BASE_URL')}/v1/query/openai".
  • examples/openai/openai_javelin_stream&non-stream.js
    • Updated baseURL in OpenAI client initialization to use ${process.env.JAVELIN_BASE_URL}/v1/query.
  • examples/rag/javelin_rag_embeddings_demo.ipynb
    • Updated base_url in AzureOpenAI client initialization to use os.getenv("JAVELIN_BASE_URL").
    • Updated azure_endpoint in AzureChatOpenAI client initialization to use f"{os.getenv('JAVELIN_BASE_URL')}/query/azureopenai".
  • examples/rag/rag_implemetation_javelin.ipynb
    • Updated base_url in JavelinConfig to use os.getenv("JAVELIN_BASE_URL").
  • examples/route_examples/aexample.py
    • Updated base_url in JavelinConfig to use os.getenv("JAVELIN_BASE_URL").
  • examples/route_examples/drop_in_replacement.py
    • Added base_url=os.getenv("JAVELIN_BASE_URL") to JavelinConfig.
  • examples/route_examples/example.py
    • Updated base_url in JavelinConfig to use os.getenv("JAVELIN_BASE_URL").
  • examples/route_examples/javelin_sdk_app.py
    • Updated base_url in JavelinConfig to use os.getenv("JAVELIN_BASE_URL").
  • javelin_sdk/services/secret_service.py
    • Added api_key_secret_key to the list of keys to check for in update_secret.
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

  1. 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.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

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 the JAVELIN_BASE_URL environment 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 use os.path.join to 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.py contains 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")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

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?

Suggested change
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",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Consider using os.path.join for constructing the base URL to ensure cross-platform compatibility and readability.

base_url = os.path.join(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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

This print statement should be removed before merging to avoid unnecessary output in production.

"api_key",
"api_key_secret_key_javelin",
"provider_name",
"api_key_secret_key"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Is this change necessary? It seems like this entry already exists on line 99.

@ankumar ankumar merged commit a13dc76 into main Apr 5, 2025
6 of 7 checks passed
@ankumar ankumar deleted the update_baseurl branch June 3, 2025 01:54
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.

3 participants