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-ollama (partners): allow passing ChatMessages to Ollama (including arbitrary roles) #30411

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

rylativity
Copy link

@rylativity rylativity commented Mar 21, 2025

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

Copy link

vercel bot commented Mar 21, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
langchain ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 21, 2025 2:39pm

…or and enable future compatibility for strict mode
@rylativity rylativity marked this pull request as ready for review March 21, 2025 13:54
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. langchain Related to the langchain package labels Mar 21, 2025
…ference docs
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Mar 21, 2025
@rylativity
Copy link
Author

@ccurme The change to libs/standard-tests/langchain_tests/unit_tests/chat_models.py in #30385 on 3/20 causes ChatOllama to fail two of the shared chatmodel tests (example test failure - https://github.com/langchain-ai/langchain/actions/runs/13985107639/job/39157371264). Even on the master branch, these tests fail in for ChatOllama (can you confirm?).

I've updated ChatOllama's with_structured_output method to accept the strict param, but I don't believe ollama actually does anything with that param currently (so I noted this in the docstring).

I have added the tests and example for using ChatMessages (optionally with arbitrary roles) with ChatOllama in the API reference.

As mentioned in the PR opening comment, this relies on functionality in ollama-python that is merged into main but not yet in a versioned release. We will need to revert the change to libs/partners/ollama/pyproject.toml before merging, but for now I've left it in for the CI/CD checks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
langchain Related to the langchain package size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Granite 3.2 Thinking
1 participant