Serialization
Serialization and Deserialization of Rigging objects
The following objects in Rigging have great serialization support for storage and retrieval:
Chat
Completion
Generator
Model
Most of this stems from our use of Pydantic for core models, and we’ve included some helpful fields for reconstructing Chats and Completions.
JSON Serialization
Let’s build a joke pipeline and serialize the final chat into JSON.
You’ll notice that every Chat gets a unique id
field to help track them in a datastore like Elastic or Pandas. We also assign a timestamp
to understand when the generation took place. We are also taking advantage of the .meta()
rigging.chat.ChatPipeline.meta to add a tracking tag for filtering later.
JSON Deserialization
The JSON has everything required to reconstruct a Chat including a generator_id
dynamically constructed to perserve the parameters used to create the generated message(s). We can now deserialize a chat from a datastore, and immediately step back into a ChatPipeline
for exploration.
Pandas DataFrames
Rigging also has helpers in the rigging.data
module for performing conversions between Chat objects and other storage formats like Pandas. In chats_to_df
the messages are flattened and stored with a chat_id
column for grouping. df_to_chats
allows you to reconstruct a list of Chat objects back from a DataFrame.