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 metaclass conflict error when installing pydantic v2 and using langchain #555

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
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
8 changes: 3 additions & 5 deletions gptcache/adapter/langchain_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
from gptcache.core import cache
from gptcache.manager.scalar_data.base import Answer, DataType
from gptcache.session import Session
from gptcache.utils import import_pydantic, import_langchain
from gptcache.utils import import_langchain

import_pydantic()
import_langchain()

# pylint: disable=C0413
from pydantic import BaseModel
from langchain.llms.base import LLM
from langchain.chat_models.base import BaseChatModel
from langchain.schema import (
Expand All @@ -27,7 +25,7 @@


# pylint: disable=protected-access
class LangChainLLMs(LLM, BaseModel):
class LangChainLLMs(LLM):
"""LangChain LLM Wrapper.

:param llm: LLM from langchain.llms.
Expand Down Expand Up @@ -127,7 +125,7 @@ def __call__(


# pylint: disable=protected-access
class LangChainChat(BaseChatModel, BaseModel):
class LangChainChat(BaseChatModel):
"""LangChain LLM Wrapper.

:param chat: LLM from langchain.chat_models.
Expand Down
3 changes: 1 addition & 2 deletions tests/unit_tests/adapter/test_langchain_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
from gptcache.adapter.api import init_similar_cache, get
from gptcache.adapter.langchain_models import LangChainLLMs, LangChainChat, _cache_msg_data_convert
from gptcache.processor.pre import get_prompt, last_content_without_template, get_messages_last_content
from gptcache.utils import import_pydantic, import_langchain
from gptcache.utils import import_langchain
from gptcache.utils.response import get_message_from_openai_answer

import_pydantic()
import_langchain()

from langchain import OpenAI, PromptTemplate
Expand Down
1 change: 0 additions & 1 deletion tests/unit_tests/embedding/test_langchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from gptcache.utils import import_langchain, prompt_install

import_langchain()
prompt_install("pydantic==1.10.8")
from langchain.embeddings import FakeEmbeddings


Expand Down