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

Migration of experimental ChatMessage to Haystack #8583

Open
10 of 16 tasks
anakin87 opened this issue Nov 26, 2024 · 3 comments
Open
10 of 16 tasks

Migration of experimental ChatMessage to Haystack #8583

anakin87 opened this issue Nov 26, 2024 · 3 comments
Assignees

Comments

@anakin87
Copy link
Member

anakin87 commented Nov 26, 2024

Summary and motivation

Plan

Tasks

Preview Give feedback
  1. anakin87
  2. 1 of 4
    P1
    bilgeyucel
  3. P2 type:documentation
    dfokina
  4. P3
@anakin87
Copy link
Member Author

Motivation

During the Tools experiment, we have refactored the ChatMessage dataclass to make it more flexible and future-proof.

  • extensible support for different types of content: text, tool calls, tool calls results (images in the future)
  • full support for Tools
  • attributes have been made internal; the preferred way for users to build messages is using specific class methods (ChatMessage.from_user, ChatMessage.from_assistant, …)

Existing Haystack dataclass; Experimental dataclass

Now, we plan to port these changes into Haystack.

My impression is that introducing the new dataclass without breaking changes is rather difficult. I would prefer to minimize breaking changes, but make it clear and transparent to users what is changing.

Breaking changes

Replacing the old dataclass with the new one will introduce the following breaking changes:

  • Direct creation of ChatMessage instances
    ChatMessage(role=ChatRole.USER, content=”Hello!”)
  • Deserialization of previously serialized pipelines
    Pipelines containing serialized ChatMessage instances will need to be recreated.

Existing class methods to create ChatMessage instances (ChatMessage.from_user, ...) won’t break.

Some breaking changes we can avoid/smoothly introduce

  • Accessing the content attribute
    if an application/user is just a consumer of the ChatMessage instance, they are likely accessing the content attribute to retrieve textual content. Introducing a text property in version 2.8.0 that mirrors content and encouraging users to adopt it will ensure compatibility when the new dataclass is introduced in version 2.9.0.
  • function role and from_function
    A less significant breaking change involves the function role: this role is outdated and removing it soon would simplify the management of Tools. Additionally, the ChatMessage.from_function sets the name attribute in ChatMessage , which will not exist in the new dataclass. However, I believe both that the transition can be made gradually and that not many people are still using this.

@sjrl
Copy link
Contributor

sjrl commented Nov 26, 2024

@anakin87 out of curiosity do the changes discussed also allow for support of Image message types? For example, the Image type used by OpenAI https://github.com/openai/openai-python/blob/83f4774156dc3e29c7fe6be9ffd681df68534509/src/openai/types/image.py#L10

This would be needed to be able to pass images to ChatGenerators to run Visual QA.

@anakin87
Copy link
Member Author

@sjrl we will not immediately introduce support for images with the changes in 2.9.0, but that is the idea: make content more flexible. Images will be just another type of content.

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

4 participants
@davidsbatista @sjrl @anakin87 and others