Serializing to Puzzlet’s Specification

Puzzlet allows you to serialize/deserialize your model provider configuration to/from our prompt template specification.

You can create a new prompt template, and add serialized prompts to it.

OpenAI Example

Serialize
const template = PromptTemplateRuntime.create(
  "my_template",
);
const model = "gpt-4-0613";
const data: OpenAI.Chat.Completions.ChatCompletionCreateParams = {
  model: "gpt-3.5-turbo",
  messages: [
    { role: "system", content: "You are a helpful assistant." },
    { role: "user", content: "Hello, who are you?" },
  ],
};

const result = template.serialize(data.model, data, "prompt1");
const prompts = Array.isArray(result) ? result : [result];

for (const prompt of prompts) {
  template.addPrompt(prompt);
}

const templateStr = template.toString();

// Now save templateStr as a JSON file in puzzlet/templates as my_template.json

Deserializing

You may need to deserialize your prompts back to their original format as well. This can be accomplished by the following

Serialize
const template = PromptTemplateRuntime.load("my_template.json");
const result = template.deserialize("prompt1");

Questions or Feedback?

Have any questions or feature requests? Reach out to us at hello@puzzlet.ai