MadcowD / ell

A language model programming library.
http://docs.ell.so/
MIT License
5.02k stars 295 forks source link

Round trip Message serialization/deserialization #336

Open alex-dixon opened 2 days ago

alex-dixon commented 2 days ago

From Merlin von Trott via Discord:

I am struggeling with loading the massage object back from json. What am i doing wrong ?

    original_message = ell.Message(role='assistant', content='Hello, this is a test message.', tool_result=None)
    message_json = json.dumps(original_message.model_dump_json())
    message_data = json.loads(message_json)
    loaded_message = ell.Message.model_validate(message_data)

ell-ai==0.0.14 pydantic==2.9.2 pydantic_core._pydantic_core.ValidationError: 1 validation error for Message Input should be a valid dictionary or instance of Message [type=model_type, input_value='{"role":"assistant","con...l,"tool_result":null}]}', input_type=str] For further information visit https://errors.pydantic.dev/2.9/v/model_type

Not sure what’s going on here exactly. Maybe we need a custom pedantic serialize/deserialize/validate hook?

Merlinvt commented 2 days ago

Opened a Pull request #337

Merlinvt commented 2 days ago

Sorry, I tried to open the pull request with the issue ...