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

ChatVertexAI broken - Fix error with sending context in params #6652

Merged
merged 2 commits into from
Jun 23, 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
5 changes: 3 additions & 2 deletions langchain/chat_models/vertexai.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,9 @@ def _generate(
context = history.system_message.content if history.system_message else None
params = {**self._default_params, **kwargs}
if not self.is_codey_model:
params["context"] = context
chat = self.client.start_chat(**params)
chat = self.client.start_chat(context=context, **params)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is functionally equivalent, no? we're only adding "context" to params if it's not a codey model

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The start_chat logic is equivalent, but the error is caused by chat.send_message(question.content, **params). In the previous version, context was added, but context isn't a valid argument for either session types (ChatSession and CodeChatSession). With this new change, context is never added to params

Here's the API reference for ChatSession.send_message: https://cloud.google.com/python/docs/reference/aiplatform/latest/vertexai.preview.language_models.ChatSession

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not, because you are using params variable in a different function, send_message just a few lines after and that's causing the issue. That function doesn't support context in params for any chat models for vertexai. Only chat-bison supports context at start chat function only.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah i see, thanks for explaining!

else:
chat = self.client.start_chat(**params)
for pair in history.history:
chat._history.append((pair.question.content, pair.answer.content))
response = chat.send_message(question.content, **params)
Expand Down