Skip to content

fix: LangChain OpenAI base URL & Bedrock API message format#161

Merged
dhruvj07 merged 1 commit into
mainfrom
fix/langchain-bedrock-api-compatibility
Mar 18, 2025
Merged

fix: LangChain OpenAI base URL & Bedrock API message format#161
dhruvj07 merged 1 commit into
mainfrom
fix/langchain-bedrock-api-compatibility

Conversation

@dhruvj07
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 @dhruvj07, 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 addresses two main issues. First, it corrects the environment variable used for the OpenAI base URL in examples/openai/langchain-openai-universal.py from BASE_URL to JAVELIN_BASE_URL. Second, it updates the message format for the Bedrock API in examples/bedrock/bedrock_client_universal.py to align with the expected structure, changing the content format from {'text': ...} to {'type': 'text', 'text': ...} for both system and user messages in the bedrock_converse_example and bedrock_converse_stream_example functions. Additionally, there was a minor formatting change in examples/bedrock/bedrock_client_universal.py to maintain code consistency.

Highlights

  • Environment Variable Fix: Corrects the environment variable used for the OpenAI base URL to JAVELIN_BASE_URL.
  • Bedrock API Message Format: Updates the message format for the Bedrock API to include the 'type' field in content dictionaries.

Changelog

  • examples/bedrock/bedrock_client_universal.py
    • Updated the message format for Bedrock API calls to include the 'type' field in content dictionaries for both system and messages.
    • Corrected formatting to maintain code consistency.
  • examples/openai/langchain-openai-universal.py
    • Changed the environment variable used for the OpenAI base URL from BASE_URL to JAVELIN_BASE_URL.
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.


Did you know?

JSON (JavaScript Object Notation) is derived from JavaScript but is language-independent and used in many programming environments.

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 addresses two important issues: the Bedrock API message format and the OpenAI base URL. The changes are straightforward and improve the compatibility and configuration of the Javelin SDK with these services.

Summary of Findings

  • Bedrock API message format: The change updates the Bedrock API message format to include the 'type' field for both 'system' and 'content' messages. This ensures the messages are correctly interpreted by the Bedrock API.
  • OpenAI base URL environment variable: The environment variable used for the OpenAI base URL has been changed from BASE_URL to JAVELIN_BASE_URL. This ensures the correct base URL is used when interacting with the OpenAI API.

Merge Readiness

The pull request is ready to be merged as it addresses important compatibility issues with Bedrock and OpenAI. The changes are well-scoped and improve the overall functionality of the Javelin SDK. I am unable to approve the pull request, and users should have others review and approve this code before merging.

Comment on lines 71 to +72
"system": [
{"text": "You are an economist with access to lots of data"}
{"type": "text", "text": "You are an economist with access to lots of data"}
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

Adding the type key to the system message is correct, but consider adding a comment explaining why this change is necessary for Bedrock API compatibility. This will help future developers understand the purpose of this change.

                    {"type": "text", "text": "You are an economist with access to lots of data"} # Bedrock requires 'type' field

"text": "Write an article about the impact of high inflation on a country's GDP"
}
],
"content": [{"type": "text", "text": "Write an article about the impact of high inflation on a country's GDP"}]
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

Similar to the system message, adding the type key to the content message is correct. Adding a comment here as well would be helpful.

                        "content": [{"type": "text", "text": "Write an article about the impact of high inflation on a country's GDP"}] # Bedrock requires 'type' field

"max_tokens": 500,
"system": [
{"text": "You are an economist with access to lots of data"}
{"type": "text", "text": "You are an economist with access to lots of data"}
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

Adding the type key to the system message is correct, but consider adding a comment explaining why this change is necessary for Bedrock API compatibility. This will help future developers understand the purpose of this change.

                    {"type": "text", "text": "You are an economist with access to lots of data"} # Bedrock requires 'type' field

"text": "Write an article about the impact of high inflation on a country's GDP"
}
],
"content": [{"type": "text", "text": "Write an article about the impact of high inflation on a country's GDP"}]
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

Similar to the system message, adding the type key to the content message is correct. Adding a comment here as well would be helpful.

                        "content": [{"type": "text", "text": "Write an article about the impact of high inflation on a country's GDP"}] # Bedrock requires 'type' field

MODEL_NAME_EMBED = "text-embedding-ada-002"
ROUTE_NAME = "openai_univ"
BASE_URL = os.getenv("BASE_URL", "https://api.javelin.live") # Default base URL
BASE_URL = os.getenv("JAVELIN_BASE_URL", "https://api.javelin.live") # Default 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.

medium

Changing the environment variable name from BASE_URL to JAVELIN_BASE_URL is a good practice to avoid naming conflicts and improve clarity. Consider updating the comment to reflect the new variable name and its purpose.

Suggested change
BASE_URL = os.getenv("JAVELIN_BASE_URL", "https://api.javelin.live") # Default base URL
BASE_URL = os.getenv("JAVELIN_BASE_URL", "https://api.javelin.live") # Javelin base URL

@dhruvj07 dhruvj07 merged commit e82e04b into main Mar 18, 2025
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