Skip to main content

No project description provided

Project description

Toucans is a streamlined library designed for agile and flexible prompt engineering, leveraging jinja2 for dynamic prompt templating and litellm to seamlessly connect with a wide range of language model providers.

Getting Started

Installation

pip install toucans

Initialize Prompt Function

To initialize a PromptFunction:

from toucans import PromptFunction

qa_func = PromptFunction(
    model="gpt-4",
    temperature=0.7,
    messages=[
        {"role": "system", "content": "You are a helpful {{ role }}."},
        {"role": "user", "content": "Answer the following question: {{ question }}"},
    ],
)

Generate Completion

Generate a completion by calling the PromptFunction with the desired role and question:

completion = qa_func(
    role="Software Developer", 
    question="What is clean code?"
)

Save Prompt Function

To save the initialized PromptFunction to a directory or the toucans hub:

# Push to dir (not implemented yet)
qa_func.push_to_dir("./qa/")

# Push to toucans hub
qa_func.push_to_hub("juunge/qa")

Load Saved Prompt Function

To load a saved PromptFunction from a directory or the toucans hub:

# Load from dir (not implemented yet)
qa_func = PromptFunction.from_dir("./qa/")

# Load from toucans hub
qa_func = PromptFunction.from_hub("juunge/qa")

Loading from Toucans Hub requires that you run a hub and connect to it by setting the HUB_API_URL environment variable.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

toucans-0.0.14.tar.gz (3.9 kB view hashes)

Uploaded Source

Built Distribution

toucans-0.0.14-py3-none-any.whl (4.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page