-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
google-genai [minor]: Support Gemini system messages #7235
Open
chrisnathan20
wants to merge
10
commits into
langchain-ai:main
Choose a base branch
from
shannon-ab:feat-genai-system-instruction-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
google-genai [minor]: Support Gemini system messages #7235
chrisnathan20
wants to merge
10
commits into
langchain-ai:main
from
shannon-ab:feat-genai-system-instruction-support
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…ction feat: Add direct system instruction invocation for GenAI [local PR]
feat: Update convertSystemMessageToHumanContent logic [local pr]
…rameter set to false
"False" system message test cases
added test cases for third parameter true
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Skipped Deployment
|
dosubot
bot
added
size:L
This PR changes 100-499 lines, ignoring generated files.
auto:improvement
Medium size change to existing code to handle new use-cases
labels
Nov 21, 2024
Hi @jacoblee93 and @afirstenberg - this is our PR to support system instructions for capable Generative AI models based on the implementation plan shared under the issue. If there are any points of concern or improvements, please do not hesitate to let us know. Thank you and have a great rest of your day! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
auto:improvement
Medium size change to existing code to handle new use-cases
size:L
This PR changes 100-499 lines, ignoring generated files.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #5069
Currently for Google Gen AI, system message (it can only be the first element in list of messages) are prepended to the following human message which is used to steer the model's behavior. The handling of system messages is the same although some newer gen ai models support direct invocation of system messages via the systemInstructions field per https://ai.google.dev/gemini-api/docs/system-instructions?lang=node
This PR provides support for models that allow direct system instructions by providing an alternative method of handling system messages when possible or set via convertSystemMessageToHumanContent. The changes in this PR are modeled after the changes in google-common to support system instructions (#5089)
High Level Outline of Changes and Additions:
Test Cases created:
Given: Input has single system message followed by one user message
When: convertBaseMessagesToContent is invoked with 3rd parameter set to true
Then: the System message is removed from prompt and passed as systemInstruction field instead and actualPrompt would only have 1 user message under the role of user
Given: Input has single system message followed by one user message
When: convertBaseMessagesToContent is invoked with 3rd parameter set to false
Then: the System message is not removed from prompt as actualPrompt would only have the system message prepended to the user message under the role of user
Given: Input has a system message that is not the first message
When: convertBaseMessagesToContent is invoked with 3rd parameter set to true
Then: convertBaseMessagesToContent should raise the error - "System message should be the first one"
Given: Input has a system message that is not the first message
When: convertBaseMessagesToContent is invoked with 3rd parameter set to false
Then: convertBaseMessagesToContent should raise the error - "System message should be the first one"
Given: Input has multiple system messages
When: convertBaseMessagesToContent is invoked with 3rd parameter set to true
Then: convertBaseMessagesToContent should raise the error - "System message should be the first one"
Given: Input has multiple system messages
When: convertBaseMessagesToContent is invoked with 3rd parameter set to false
Then: convertBaseMessagesToContent should raise the error - "System message should be the first one"
Given: Input has no system message and one user message
When: convertBaseMessagesToContent is invoked with 3rd parameter set to true
Then: actualPrompt would only have the user message under the role of user
Given: Input has no system message and one user message
When: convertBaseMessagesToContent is invoked with 3rd parameter set to false
Then: actualPrompt would only have the user message under the role of user
Given: Input has no system message and multiple user messages
When: convertBaseMessagesToContent is invoked with 3rd parameter set to true
Then: actualPrompt would only have the first user message followed by the next user messages as separate messages
Given: Input has no system message and multiple user messages
When: convertBaseMessagesToContent is invoked with 3rd parameter set to false
Then: actualPrompt would only have the first user message followed by the next user messages as separate messages
Credits:
Issue selection - @shannon-ab
Implementation - @chrisnathan20 @garychen2002
Testing - @shannon-ab @martinl498