langchain-ollama (partners): allow passing ChatMessages to Ollama (including arbitrary roles) #30411
+126
−60
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.
Replacement for PR #30191 (@ccurme)
Description: currently, ChatOllama will raise a value error if a ChatMessage is passed to it, as described #30147 (comment).
Furthermore, ollama-python is removing the limitations on valid roles that can be passed through chat messages to a model in ollama - ollama/ollama-python#462 (comment).
This PR removes the role limitations imposed by langchain and enables passing langchain ChatMessages with arbitrary 'role' values through the langchain ChatOllama class to the underlying ollama-python Client.
As this PR relies on merged but unreleased functionality in ollama-python, I have temporarily pointed the ollama package source to the main branch of the ollama-python github repo.
Format, lint, and tests of new functionality passing. Need to resolve issue with recently added ChatOllama tests. (Now resolved)
Issue: resolves #30122 (related to ollama issue ollama/ollama#8955)
Dependencies: no new dependencies
[x] PR title
[x] PR message
[x] Lint and test: format, lint, and test all running successfully and passing