langchain-ollama (partners): allow passing ChatMessage (with custom 'role') to ChatOllama#30191
langchain-ollama (partners): allow passing ChatMessage (with custom 'role') to ChatOllama#30191rylativity wants to merge 9 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
from my initial stack trace in 30122, I'm afraid that I will not be able to use create_react_agent to work with granite3.2 |
|
Clément PAPPALARDO (@lemassykoi) you will have to explicitly use a ChatMessage instance for the "control/thinking" message like so: Or, for example with more context: For now, I'd recommend using a ChatMessage instance as described above. I'm looking into whether we can have it accept a dictionary message like this: |
…hat' type if 'type' arg is not provided
|
In order to make this also work with ccurme (@ccurme) my suggestion would be to merge this PR, which allows using ChatMessage with custom 'role' attributes with ChatOllama and closes #30122. And I can open a separate discussion and/or issue regarding how to handle 'role' vs 'type' keys in |
ccurme (ccurme)
left a comment
There was a problem hiding this comment.
Thanks for this, I'm happy to move forward but think it's best to keep it open until the ollama sdk actually supports control roles. Then we can merge this with a test + example use in the API reference. From what I can tell it's not yet supported by ollama: ollama/ollama-python#462
Let me know if my thinking makes sense.
|
ccurme (@ccurme) makes sense to me. Ollama server already accepts arbitrary roles, and the ollama-python maintainers have now expressed a preference to remove role checking/validation entirely from the python sdk. I expect ollama-python will support it shortly - as soon as this PR is reviewed, approved, and merged ollama/ollama-python#462 |
|
ccurme (@ccurme) the associated functionality on ollama has now been merged into ollama (ollama/ollama#9874 (comment)) and ollama-python sdk (ollama/ollama-python#462 (comment)). I'll get this covered with a test or two and update the API reference, let me know if there's anything else you'd want before we can merge this |
|
ccurme (@ccurme) got some wires crossed, opening a new draft PR here to keep it clean - #30411 |
…ges to Ollama (including arbitrary roles) (#30411) Replacement for PR #30191 (@ccurme) **Description**: currently, ChatOllama [will raise a value error if a ChatMessage is passed to it](https://github.com/langchain-ai/langchain/blob/master/libs/partners/ollama/langchain_ollama/chat_models.py#L514), 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]( ollama/ollama-python#462 (comment)), 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 --------- Co-authored-by: Ryan Stewart <ryanstewart@Ryans-MacBook-Pro.local> Co-authored-by: Chester Curme <chester.curme@gmail.com>
**Description: currently, ChatOllama will raise a value error if a ChatMessage is passed to it, as described here. This PR enables passing a langchain ChatMessage with a custom 'role' attribute through the langchain ChatOllama class.
Issue: resolves #30122 (also related to PR #30147 and ollama-python issue ollama/ollama#8955)
Dependencies: no new dependencies