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

Simple way to create a ChatMessage from Document content #8643

Open
julian-risch opened this issue Dec 16, 2024 · 2 comments
Open

Simple way to create a ChatMessage from Document content #8643

julian-risch opened this issue Dec 16, 2024 · 2 comments
Assignees
Labels
P2 Medium priority, add to the next sprint if no P1 available

Comments

@julian-risch
Copy link
Member

Is your feature request related to a problem? Please describe.
We got the feedback that there is no simple way to create a ChatMessage from Document content with the new ChatMessage implementation.

Describe the solution you'd like
Haystack should support something like: {{document.content|ChatMessage.from_user}}.

Describe alternatives you've considered

Additional context

@julian-risch julian-risch added the P2 Medium priority, add to the next sprint if no P1 available label Dec 16, 2024
@anakin87
Copy link
Member

anakin87 commented Dec 16, 2024

I initially thought this was related to the new ChatMessage implementation, so I quickly took a look.

I found that performing this transformation requires the same code with both the current and the new ChatMessage.

from haystack import Document
from haystack.components.converters import OutputAdapter
from haystack.dataclasses import ChatMessage

adapter = OutputAdapter(template="{{ document.content | ChatMessage.from_user }}",
                        output_type=ChatMessage, 
                        unsafe=True, 
                        custom_filters={"ChatMessage.from_user": ChatMessage.from_user})

print(adapter.run(document=Document(content="Test content")))

@mathislucka could you clarify what the original problem was?
(@julian-risch feel free to add information if you know something more)

@mathislucka
Copy link
Member

The example is not serializable.

adapter = OutputAdapter(template="{{ document.content | ChatMessage.from_user }}", output_type=ChatMessage, unsafe=True, custom_filters={"ChatMessage.from_user": ChatMessage.from_user})

Gives me: haystack_experimental.dataclasses.chat_message.from_user when serialized.

Why not allow ChatMessage(text="hello", role="user")?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 Medium priority, add to the next sprint if no P1 available
Projects
None yet
Development

No branches or pull requests

3 participants