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 Integration doesn't work with langchain_core>=0.3 #6

Open
isbalashov opened this issue Oct 15, 2024 · 3 comments
Open

Langchain Integration doesn't work with langchain_core>=0.3 #6

isbalashov opened this issue Oct 15, 2024 · 3 comments

Comments

@isbalashov
Copy link

Description:

Langchain integration example doesn't work - AttributeError: Config in yandex_cloud_ml_sdk

Steps to Reproduce:

  1. Run example:
from yandex_cloud_ml_sdk import YCloudML
from langchain_core.messages import AIMessage, HumanMessage

sdk = YCloudML(folder_id="...", auth="<APIKey/IAMToken/SomethingElse>")

model = sdk.models.completions('yandexgpt').langchain()

langchain_result = model.invoke([
    HumanMessage(content="hello!"),
    AIMessage(content="Hi there human!"),
    HumanMessage(content="Meow!"),
])

Error Traceback:

AttributeError
Traceback (most recent call last)
Cell In[6], line 6
      2 from langchain_core.messages import AIMessage, HumanMessage
      4 sdk = YCloudML(folder_id="xxxxxx", auth="xxxxxxxxxxxxxx")
----> 6 model = sdk.models.completions('yandexgpt').langchain()
      8 langchain_result = model.invoke([
      9     HumanMessage(content="hello!"),
     10     AIMessage(content="Hi there human!"),
     11     HumanMessage(content="Meow!"),
     12 ])

File xxxxxxxxxx/.venv/lib/python3.12/site-packages/yandex_cloud_ml_sdk/_models/completions/model.py:39, in BaseGPTModel.langchain(self, model_type, timeout)
     38 def langchain(self, model_type: Literal["chat"] = "chat", timeout: int = 60) -> BaseYandexLanguageModel:
---> 39     from .langchain import ChatYandexGPT  # pylint: disable=import-outside-toplevel
     41     if model_type == "chat":
     42     # idk why but pylint thinks this class still abstract
     43         return ChatYandexGPT(ycmlsdk_model=self, timeout=timeout)  # pylint: disable=abstract-class-instantiated

File xxxxxxxxxx/.venv/lib/python3.12/site-packages/yandex_cloud_ml_sdk/_models/completions/langchain.py:12
      9 from langchain_core.messages.ai import UsageMetadata
     10 from langchain_core.outputs import ChatGeneration, ChatGenerationChunk, ChatResult
---> 12 from yandex_cloud_ml_sdk._types.langchain import BaseYandexLanguageModel
     13 from yandex_cloud_ml_sdk._utils.langchain import make_async_run_manager
     14 from yandex_cloud_ml_sdk._utils.sync import run_sync_generator_impl, run_sync_impl

File xxxxxxxxxx/.venv/lib/python3.12/site-packages/yandex_cloud_ml_sdk/_types/langchain.py:15
     10 from yandex_cloud_ml_sdk._types.model import BaseModel
     12 ModelTypeT = TypeVar('ModelTypeT', bound=BaseModel)
---> 15 class BaseYandexModel(LangchainModel, Generic[ModelTypeT]):
     16     ycmlsdk_model: ModelTypeT
     17     timeout: int = 60

File xxxxxxxxxx/.venv/lib/python3.12/site-packages/yandex_cloud_ml_sdk/_types/langchain.py:19, in BaseYandexModel()
     16 ycmlsdk_model: ModelTypeT
     17 timeout: int = 60
---> 19 class Config(Serializable.Config):
     20     arbitrary_types_allowed = True

File xxxxxxxxxx/.venv/lib/python3.12/site-packages/pydantic/_internal/_model_construction.py:262, in ModelMetaclass.__getattr__(self, item)
    260 if private_attributes and item in private_attributes:
    261     return private_attributes[item]
--> 262 raise AttributeError(item)

AttributeError: Config

Environment:

  • Python Version: 3.12
  • yandex_cloud_ml_sdk Version: 0.321.0
  • langchain_core Version: 0.3.10
  • Operating System: MacOS
@vhaldemar
Copy link
Collaborator

Hey!
Langchain just updated its internals and we need to adapt our integration with it.
Meanwhile you could downgrade langchain-core>=0.2.29,<=0.2.41

@isbalashov
Copy link
Author

Yes, downgrading to langchain-core>=0.2.29,<=0.2.41 did the trick

@vhaldemar vhaldemar reopened this Oct 15, 2024
@vhaldemar vhaldemar changed the title Langchain Integration example doesn't work Langchain Integration doesn't work with langchain_core>=0.3 Oct 15, 2024
@vhaldemar
Copy link
Collaborator

vhaldemar commented Oct 15, 2024

I will leave this ticket open until I make the correct fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants