langchain-ai / langchain

🦜🔗 Build context-aware reasoning applications
https://python.langchain.com
MIT License
88.76k stars 13.95k forks source link

[ChatVertexAI] 'ChatSession' object has no attribute '_history' #6675

Closed ARKA1112 closed 9 months ago

ARKA1112 commented 1 year ago

System Info

Linux-6.3.7-1-default-x86_64-with-glibc2.37
Python Version: 3.10.11
Langchain Version: 0.0.21

Who can help?

No response

Information

Related Components

Reproduction

Input

from langchain.chat_models import ChatVertexAI
from langchain.schema import HumanMessage, SystemMessage, AIMessage
chat = ChatVertexAI(temperature=0.7,verbose=True)

chat(
    [
        SystemMessage(content="Assume you are an expert tour guide.Help the user and assist him in his travel"),
        HumanMessage(content="I like lush green valleys with cool weather. Where should I go?"),
        AIMessage(content="Switzerland is a nice place to visit"),
        HumanMessage(content="Name some of the popular places there to visit")

    ]
)

Response

File [~/gamedisk/PyTorch2.0_env/lib/python3.10/site-packages/langchain/chat_models/vertexai.py:136], in ChatVertexAI._generate(self, messages, stop, run_manager, **kwargs)
    134     chat = self.client.start_chat(**params)
    135 for pair in history.history:
--> 136     chat._history.append((pair.question.content, pair.answer.content))
    137 response = chat.send_message(question.content, **params)
    138 text = self._enforce_stop_words(response.text, stop)

AttributeError: 'ChatSession' object has no attribute '_history'

Expected behavior

It is expected to return an object similar to this


AIMessage(content='Lauterbrunnen is a nice place to visit', additional_kwargs={}, example=False)
jamontol commented 1 year ago

I'm experiencing this too in RetrievalQA.from_chain_type, specifically with chain_type = 'refine'. It was working with no issues in previous 0.0.206 version

Sheldenburg commented 1 year ago

Google updated the ChatModelBase Class. It no longer has history attribute. Instead, it has an attribute called message_history. To get the code working, you can downgrade google-cloud-aiplatform to 1.26.0 until this gets updated in Langchain. I believe you are using 1.26.1. https://github.com/googleapis/python-aiplatform/commit/bf0e20b497675125e0bc5abc10455b06f7a0c019 @HassanOuda

ARKA1112 commented 1 year ago

Yes, I am using google-cloud-aiplatform version 1.26.1. And downgrading to 1.26.0 makes the code work as expected. Thanks for your help.

dosubot[bot] commented 9 months ago

Hi, @ARKA1112! I'm Dosu, and I'm here to help the LangChain team manage their backlog. I wanted to let you know that we are marking this issue as stale.

From what I understand, you reported an issue regarding the 'ChatSession' object not having the attribute '_history', which resulted in an AttributeError. Another user, jamontol, also experienced the same issue. Sheldenburg suggested downgrading the google-cloud-aiplatform package to version 1.26.0, as the attribute name has changed to 'message_history'. You confirmed that downgrading to 1.26.0 resolved the issue.

Before we close this issue, we wanted to check if it is still relevant to the latest version of the LangChain repository. If it is, please let us know by commenting on this issue. Otherwise, feel free to close the issue yourself, or it will be automatically closed in 7 days.

Thank you for your contribution to the LangChain repository!