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

chore: use text instead of content for ChatMessage in Cohere and Anthropic #1237

Merged
merged 1 commit into from
Dec 9, 2024

Conversation

anakin87
Copy link
Member

@anakin87 anakin87 commented Dec 9, 2024

Related Issues

Proposed Changes:

  • use text instead of content for ChatMessage in Cohere and Anthropic
  • I did the changes in a single PR because for Anthropic we are only changing tests, so we don't need a release

How did you test it?

CI

Checklist

@anakin87 anakin87 marked this pull request as ready for review December 9, 2024 16:34
@anakin87 anakin87 requested a review from a team as a code owner December 9, 2024 16:34
@anakin87 anakin87 requested review from Amnah199 and removed request for a team December 9, 2024 16:34
@Amnah199
Copy link
Contributor

Amnah199 commented Dec 9, 2024

Not that it impacts the functionality but some comments in anthropic can be updated to replace content with text. In a longer run, this will prevent any inconsistencies in code e.g.

  1. small change for Anthropic here
  2. and here
  3. for AnthropicVertex here

@anakin87
Copy link
Member Author

anakin87 commented Dec 9, 2024

@Amnah199

Let me explain better...

Currently text just mirrors content (code, deepset-ai/haystack#8588). If you access content directly, a deprecation warning is shown.

But printing or converting to message to a dictionary still shows content. (So I don't think we should update the code you linked)

from haystack.dataclasses import ChatMessage
msg=ChatMessage.from_user("I'm Stefano")
print(msg)
>>> ChatMessage(content="I'm Stefano", role=<ChatRole.USER: 'user'>, name=None, meta={})

print(msg.to_dict())
>>> {'content': "I'm Stefano", 'role': 'user', 'name': None, 'meta': {}}

print(msg.text)
>>> "I'm Stefano"

I understand this can be a bit confusing, but it is done to smooth the transition to the new ChatMessage in 2.9.0 (see deepset-ai/haystack#8583 (comment) for details and motivation)

@Amnah199
Copy link
Contributor

Amnah199 commented Dec 9, 2024

Alright. Thanks for explaining.

Copy link
Contributor

@Amnah199 Amnah199 left a comment

Choose a reason for hiding this comment

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

LG!

@anakin87 anakin87 merged commit 7a1297b into main Dec 9, 2024
16 checks passed
@anakin87 anakin87 deleted the anthropic-text branch December 9, 2024 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants