Seamless integration and composability for large language model apps.

Features

Python

Installation

pip install chaincrafter

Usage

  1. Define your prompts and the variables that they expect
  2. The input variables can be of any type, and can be processed by a function
  3. The prompt message is treated as an f-string
  4. Define your chain of prompts
  5. The chain is a list of tuples, where each tuple contains a prompt and the output key to store the response in
  6. The output key is used to access the response in the next prompt
  7. Set up the models that you want to use
  8. Run the chain using the models
from chaincrafter import Chain, Prompt
from chaincrafter.models import OpenAiChat

chat_model = OpenAiChat(temperature=0.65, model_name="gpt-3.5-turbo")
system_prompt = Prompt("You are a helpful assistant who responds to questions about the world")
hello_prompt = Prompt("Hello, what is the capital of France? Answer only with the city name.")
followup_prompt = Prompt("{city} sounds like a nice place to visit. What is the population of {city}?")
chain = Chain(
    system_prompt,
    (hello_prompt, "city"),
    (followup_prompt, "followup_response"),
)
messages = chain.run(chat_model)
for message in messages:
    print(f"{message['role']}: {message['content']}")

Running the examples

source venv/bin/activate
export OPENAI_API_KEY="..."
python -m examples.interesting_facts

JavaScript / TypeScript

Work in progress

Installation

npm install chaincrafter

Usage