fix: LangChain OpenAI base URL & Bedrock API message format#161
Conversation
There was a problem hiding this comment.
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
systemandmessages. - Corrected formatting to maintain code consistency.
- Updated the message format for Bedrock API calls to include the 'type' field in content dictionaries for both
- examples/openai/langchain-openai-universal.py
- Changed the environment variable used for the OpenAI base URL from
BASE_URLtoJAVELIN_BASE_URL.
- Changed the environment variable used for the OpenAI base URL from
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
-
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 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_URLtoJAVELIN_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.
| "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"} |
There was a problem hiding this comment.
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"}] |
There was a problem hiding this comment.
| "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"} |
There was a problem hiding this comment.
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"}] |
There was a problem hiding this comment.
| 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 |
There was a problem hiding this comment.
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.
| 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 |
No description provided.