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

"Fix" langchain user warning #12733

Merged
merged 1 commit into from
Aug 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion rasa/shared/utils/llm.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Any, Dict, Optional, Text, Type
import warnings

import structlog
from langchain.embeddings.base import Embeddings
Expand Down Expand Up @@ -147,7 +148,16 @@ def llm_factory(
# need to create a copy as the langchain function modifies the
# config in place...
structlogger.debug("llmfactory.create.llm", config=config)
return load_llm_from_config(config.copy())
# langchain issues a user warning when using chat models. at the same time
# it doesn't provide a way to instantiate a chat model directly using the
# config. so for now, we need to suppress the warning here. Original
# warning:
# packages/langchain/llms/openai.py:189: UserWarning: You are trying to
# use a chat model. This way of initializing it is no longer supported.
# Instead, please use: `from langchain.chat_models import ChatOpenAI
with warnings.catch_warnings():
warnings.simplefilter("ignore", category=UserWarning)
return load_llm_from_config(config.copy())


def embedder_factory(
Expand Down
Loading