Skip to content

Commit

Permalink
Fix metaclass conflict error when installing pydantic v2 and using la…
Browse files Browse the repository at this point in the history
…ngchain
  • Loading branch information
yacchi committed Oct 20, 2023
1 parent a9b94f4 commit 5cc4a1a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
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

0 comments on commit 5cc4a1a

Please sign in to comment.