Skip to main content

chaincrafter

Seamless integration and composability for large language model apps.

Features

  • Composable prompts and chains
    • Use multiple models to run one chain and then use that as input for a different chain and model
  • Customizable prompt and response formatting
    • Add modifiers to prompts to change the style, length, and format of the response
    • Extract data from the response to use in the next prompt
    • Add custom functions to process the response
    • Add custom functions to process the input variables
  • Integration with OpenAI API (llama.cpp in progress)
  • Async calls to models
  • Load Prompts and Chains from YAML using Catalogs
    • Makes it easier to share prompts and chains between projects
    • Build up a prompts library

Installation

pip install chaincrafter

Usage

  1. Define your prompts and the variables that they expect
  • The input variables can be of any type, and can be processed by a function
  • The prompt message is treated as an f-string
  1. Define your chain of prompts
  • The chain is a list of tuples, where each tuple contains a prompt and the output key to store the response in
  • The output key is used to access the response in the next prompt
  1. Set up the models that you want to use
  2. 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
python -m examples.interesting_facts_catalog

Metadata

Release files for chaincrafter 0.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for chaincrafter 0.2.3
File Size Uploaded Provenance Actions
chaincrafter-0.2.3.tar.gz 10.0 kB Without provenance Details for chaincrafter-0.2.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for chaincrafter 0.2.3
File Interpreter ABI Platform Actions
chaincrafter-0.2.3-py3-none-any.whl Python 3 none any Details for chaincrafter-0.2.3-py3-none-any.whl

Total release size: 19.9 kB

Release files / chaincrafter-0.2.3.tar.gz

Download URL chaincrafter-0.2.3.tar.gz
Size 10.0 kB
Tags Source
SHA-256 checksum
How to use checksums
3c3969a2f8df827f9ef86a780e29a1d04bc2c74645f3903abf0d23762a2d7854
BLAKE2b-256 checksum
How to use checksums
2cad88d376e98ca910ccc0d252fa20a094fbb962d6670b01e00fec45556529d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.4

Release files / chaincrafter-0.2.3-py3-none-any.whl

Download URL chaincrafter-0.2.3-py3-none-any.whl
Size 9.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
660500d91f484eb2580e85b0f91daea55400b0805883b9cca8871861d3aed3f6
BLAKE2b-256 checksum
How to use checksums
6510bc57bd1a10a2829163d9fcda390a0108e387b194500cf5d5e0971855690d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.4

Security for chaincrafter 0.2.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page