Creating Chains

Prompt chaining can be done by referencing another prompt in your template. For example, in this case prompt2 references the output of prompt1. Both the input and output can be referenced by other prompts. These connections end up forming a chain, or a graph of prompts.

Serialized JSON

Once published, the output will be serialized to our prompt template spec. You can view the above array of prompts serialized here.

Prompt Template
{
  "name": "my_chain",
  "schema_version": "latest",
  "prompts": [
    {
      "name": "prompt1",
      "input": "Write a short story about a {{ animal }}. Give it a name",
      "metadata": {
        "model": {
          "name": "gpt-3.5-turbo-1106",
          "settings": {
            "temperature": 0.7,
            "max_tokens": 4096,
            "top_p": 1,
            "frequency_penalty": 0,
            "presence_penalty": 0,
            "system_prompt": ""
          }
        },
        "parameters": {
          "animal": "Fox"
        }
      }
    },
    {
      "name": "prompt2",
      "input": "What's the name of the animal in this story? \n {{ prompt1.output }}",
      "metadata": {
        "model": {
          "name": "gpt-3.5-turbo-1106",
          "settings": {
            "temperature": 0.7,
            "max_tokens": 4096,
            "top_p": 1,
            "frequency_penalty": 0,
            "presence_penalty": 0
          }
        },
        "parameters": {}
      }
    }
  ]
}

Invoking Chains via the SDK

The following code executes prompt 2 with it’s dependencies. You can either execute the dependency chain automatically, or individually depending on your needs. If executed individually, the state of previous prompts will be saved for you.

Questions or Feedback?

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