Skip to main content

Code-first, type-safe prompt management

Project description

pixie-prompts

Code-first, type-checked prompt management. Manage prompt locally in your codebase, with Jinja rendering, variable type-hint and validations.

Demo

Try it live

Setup

In your project folder, install pixie-prompts[server] Python package:

pip install pixie-prompts[server]

Note: you can install pixie-prompts without the server extras for your production build.

Start the local dev server and open the web UI by running:

pp

Note: The web-browser would automatically open http://localhost:8000. You can also access the web UI at gopixie.ai.

To test prompts, create .env file with LLM API key(s):

# .env
OPENAI_API_KEY=...
GEMINI_API_KEY=...

Register Prompt

In your code, create a new prompt using create_prompt:

# prompts.py
from pixie.prompts import create_prompt

simple_prompt = create_prompt('simple_prompt')

Your prompt would automatically appear in the web UI after your code is saved.

Manage Prompt

You can create new version(s) of a prompt in the web UI.

Once saved from web UI, it will be assigned a new version id, and the content would be saved in your codebase at /.pixie/prompts/<prompt_name>/<version_id>.jinja.

Note: it's recommended to only edit your prompts via the web UI to get type-hint and validation.

Define Variables

For prompt that has variable(s) in it, define a class extending pixie.prompts.Variables (which extends pydantic.BaseModel. Then use the class type when registering your prompt.

# prompts.py
from pixie.prompts import Variables, create_prompt

class Person(Variables):
    name: str
    age: int

# Create a prompt with variables
typed_prompt = create_prompt('typed_prompt', Person)

Other than using dict, you can define your variable class in anyway that's permissible in Pydantic. I.e. you can define your field as basic types such as str, int, bool, you can have a list of permissible items, you can use Union type, and you can have nested Variable field.

The web UI will parse your variable definitions and use it to decide input fields, type-hints and validations.

Use Prompt

Compile your prompt into string with the compile function on the prompt object. Pass in the Variables object (if defined) for your prompt as argument.

# demo.py

from pixie.prompts import Variables, create_prompt

simple_prompt = create_prompt('simple_prompt')

class Person(Variables):
    name: str
    age: int

# Create a prompt with variables
typed_prompt = create_prompt('typed_prompt', Person)

simple_prompt_str = simple_prompt.compile()
typed_prompt_str = typed_prompt.compile(Person(name="Jane", age=30))

Check out more examples.

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

pixie_prompts-0.1.10.dev1.tar.gz (24.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pixie_prompts-0.1.10.dev1-py3-none-any.whl (27.2 kB view details)

Uploaded Python 3

File details

Details for the file pixie_prompts-0.1.10.dev1.tar.gz.

File metadata

  • Download URL: pixie_prompts-0.1.10.dev1.tar.gz
  • Upload date:
  • Size: 24.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.1 CPython/3.12.12 Linux/6.11.0-1018-azure

File hashes

Hashes for pixie_prompts-0.1.10.dev1.tar.gz
Algorithm Hash digest
SHA256 08d4c76387b0cb758a7d05ba206a32a09e1067e644c8d95e889dc3d6571c4180
MD5 b2a2ace8f9a79f8f3820c9acf178fd59
BLAKE2b-256 ac1809cd7bfaf78a67d5346cbf5a989cdaeea25fb9c5d94e8757b3f0e30b173c

See more details on using hashes here.

File details

Details for the file pixie_prompts-0.1.10.dev1-py3-none-any.whl.

File metadata

  • Download URL: pixie_prompts-0.1.10.dev1-py3-none-any.whl
  • Upload date:
  • Size: 27.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.1 CPython/3.12.12 Linux/6.11.0-1018-azure

File hashes

Hashes for pixie_prompts-0.1.10.dev1-py3-none-any.whl
Algorithm Hash digest
SHA256 f80f0f1db55e1a7052a88ff443e01d36c1074753b471ec49bee4305c4c3f75e7
MD5 c16afe544f4e7bf6a6dcf2c275fa4165
BLAKE2b-256 66bc0ebb466db39f15f6ca5f53f0b41877faef89c2613c4025233edf5a087f26

See more details on using hashes here.

Supported by

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