-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
ChatPromptBuilder
Fails to JSON Serialize due to ChatMessage
class
#7844
Comments
Thanks for reporting this. Reproducible example from haystack.components.builders.chat_prompt_builder import ChatPromptBuilder
from haystack.dataclasses import ChatMessage
from haystack import Pipeline
messages = [ChatMessage.from_system("Message")]
chat_prompt_builder = ChatPromptBuilder(template=messages)
pipeline = Pipeline()
pipeline.add_component("builder", chat_prompt_builder)
pipe_str = pipeline.dumps()
new_pipeline = Pipeline().loads(pipe_str) |
Let me try to solve this! |
I been working on this for an hour now and I find that the problem here is that the 'component_to_dict' and 'deffault_to_dict' functions do not work recursively on fields that may need serialization, and just lives them as is. This makes serialization fail while we only use straightforward data types that should be serialized and deserialized without any problem. |
@CarlosFerLo go for the simple solution, custom |
Describe the bug
The new ChatPromptBuilder fails to serialize because of the ChatMessage dataclass. This component takes in a list of ChatMessages in the init method under the template
Error message
TypeError: Object of type ChatMessage is not JSON serializable
Expected behavior
The behavior I expect is that the component gets converted into JSON like this and that we can load with this JSON to create the pipeline back (I'm using a JSON Marshaller)
Additional context
I noticed that ChatPromptBuilder and ChatMessage classes do not have any from dict or to dict functions, so it explains why they fail to serialize. In general, I've seen similar issues reported for DataClasses so I think they should all be serializable
To Reproduce
The text was updated successfully, but these errors were encountered: