mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-20 22:03:52 +00:00
langchain[patch]: init_chat_model() to import ChatOllama from langchain-ollama and fallback on langchain-community (#24821)
Description: init_chat_model() should import ChatOllama from `langchain-ollama`. If that fails, fallback to `langchain-community`
This commit is contained in:
parent
3a7f3d46c3
commit
d8f3ea82db
@ -118,7 +118,7 @@ def init_chat_model(
|
|||||||
- mistralai (langchain-mistralai)
|
- mistralai (langchain-mistralai)
|
||||||
- huggingface (langchain-huggingface)
|
- huggingface (langchain-huggingface)
|
||||||
- groq (langchain-groq)
|
- groq (langchain-groq)
|
||||||
- ollama (langchain-community)
|
- ollama (langchain-ollama)
|
||||||
|
|
||||||
Will attempt to infer model_provider from model if not specified. The
|
Will attempt to infer model_provider from model if not specified. The
|
||||||
following providers will be inferred based on these model prefixes:
|
following providers will be inferred based on these model prefixes:
|
||||||
@ -336,8 +336,12 @@ def _init_chat_model_helper(
|
|||||||
|
|
||||||
return ChatFireworks(model=model, **kwargs)
|
return ChatFireworks(model=model, **kwargs)
|
||||||
elif model_provider == "ollama":
|
elif model_provider == "ollama":
|
||||||
_check_pkg("langchain_community")
|
try:
|
||||||
from langchain_community.chat_models import ChatOllama
|
_check_pkg("langchain_ollama")
|
||||||
|
from langchain_ollama import ChatOllama
|
||||||
|
except ImportError:
|
||||||
|
_check_pkg("langchain_community")
|
||||||
|
from langchain_community import ChatOllama
|
||||||
|
|
||||||
return ChatOllama(model=model, **kwargs)
|
return ChatOllama(model=model, **kwargs)
|
||||||
elif model_provider == "together":
|
elif model_provider == "together":
|
||||||
|
Loading…
Reference in New Issue
Block a user