Skip to content
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

langchain-google: remove possible trailing newline from content text in response candidates #598

Merged
merged 10 commits into from
Dec 24, 2024

Conversation

aaronbriel
Copy link
Contributor

PR Description

Renamed _strip_erroneous_spaces to _strip_erroneous_characters and added trailing newline removal, added unit tests for function.

Relevant issues

24648

Type

🐛 Bug Fix
🧹 Refactoring
✅ Test

Changes(optional)

Testing(optional)

make test

77 passed, 6 warnings in 0.82s

Note(optional)

…ded trailing newline removal, added unit tests
@lkuligin
Copy link
Collaborator

PALM is going to be deprecated, do we really need this one?

@lkuligin
Copy link
Collaborator

actually, if your original issue was with gemini-1.5 model, I'm not sure this PR will fix it.

@aaronbriel aaronbriel marked this pull request as draft December 9, 2024 20:52
@aaronbriel aaronbriel changed the title langchain-google: added _strip_erroneous_characters with trailing newline removal langchain-google: added code to remove trailing newline from content text in response candidates Dec 10, 2024
@aaronbriel
Copy link
Contributor Author

aaronbriel commented Dec 10, 2024

@lkuligin Good catch. I've reverted the earlier code and instead added trailing newline removal to the content text of response candidates.

Before change:

>>> from langchain_google_genai import ChatGoogleGenerativeAI
>>> import os
>>> llm = ChatGoogleGenerativeAI(google_api_key=os.getenv('GOOGLE_API_KEY'), model='gemini-1.5-pro-002')
>>> prompt = "you are a football expert"
>>> text = "what is the name of the football team in Minnesota?"
>>> messages = [('system', prompt), ('human', text)]
>>> ai_msg = llm.invoke(messages)
>>> ai_msg.content
'The NFL team in Minnesota is the **Minnesota Vikings**.\n'

After change:

>>> from langchain_google_genai import ChatGoogleGenerativeAI
>>> import os
>>> llm = ChatGoogleGenerativeAI(google_api_key=os.getenv('GOOGLE_API_KEY'), model='gemini-1.5-pro-002')
>>> prompt = "you are a football expert"
>>> text = "what is the name of the football team in Minnesota?"
>>> messages = [('system', prompt), ('human', text)]
>>> ai_msg = llm.invoke(messages)
>>> ai_msg.content
'The NFL team in Minnesota is the **Minnesota Vikings**.'

@aaronbriel aaronbriel marked this pull request as ready for review December 10, 2024 15:01
@aaronbriel aaronbriel changed the title langchain-google: added code to remove trailing newline from content text in response candidates langchain-google: remove possible trailing newline from content text in response candidates Dec 10, 2024
@aaronbriel
Copy link
Contributor Author

@lkuligin are you able to approve this PR or is there someone else to tag?

@adamJLev
Copy link

waiting for this fix too, thanks for the PR 👌🏼

@aaronbriel aaronbriel requested a review from lkuligin December 23, 2024 13:00
@lkuligin lkuligin merged commit cb64151 into langchain-ai:main Dec 24, 2024
15 checks passed
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