This package is responsible for calling prompts in a specific format. It uses LangChain and OpenAI API
Project description
PromptCaller
PromptCaller is a Python package for calling prompts in a specific format, using LangChain and the OpenAI API. It enables users to load prompts from a template, render them with contextual data, and make structured requests to the OpenAI API.
Features
- Load prompts from a
.prompt
file containing a YAML configuration and a message template. - Invoke prompts using LangChain and OpenAI API, with support for structured output.
Installation
To install the package, simply run:
pip install prompt-caller
You will also need an .env
file that contains your OpenAI API key:
OPENAI_API_KEY=your_openai_api_key_here
Usage
- Define a prompt file:
Create a .prompt
file in the prompts
directory, e.g., prompts/sample.prompt
:
---
model: gpt-4o-mini
temperature: 0.7
max_tokens: 512
output:
result: "Final result of the expression"
explanation: "Explanation of the calculation"
---
<system>
You are a helpful assistant.
</system>
<user>
How much is {{expression}}?
</user>
This .prompt
file contains:
- A YAML header for configuring the model and parameters.
- A template body using Jinja2 to inject the context (like
{{ expression }}
). - Messages structured in a JSX-like format (
<system>
,<user>
).
- Load and call a prompt:
from prompt_caller import PromptCaller
ai = PromptCaller()
response = ai.call("sample", {"expression": "3+8/9"})
print(response)
In this example:
- The
expression
value3+8/9
is injected into the user message. - The model will respond with both the result of the expression and an explanation, as specified in the
output
section of the prompt.
How It Works
- _loadPrompt: Loads the prompt file, splits the YAML header from the body, and parses them.
- _renderTemplate: Uses the Jinja2 template engine to render the body with the provided context.
- _parseJSXBody: Parses the message body written in JSX-like tags to extract system and user messages.
- call: Invokes the OpenAI API with the parsed configuration and messages, and handles structured output via dynamic Pydantic models.
Build and Upload
To build the distribution and upload it to a package repository like PyPI, follow these steps:
-
Build the distribution:
Run the following command to create both source (
sdist
) and wheel (bdist_wheel
) distributions:python setup.py sdist bdist_wheel
This will generate the distribution files in the
dist/
directory. -
Upload to PyPI using Twine:
Use
twine
to securely upload the distribution to PyPI:twine upload dist/*
Ensure you have configured your PyPI credentials before running this command. You can find more information on configuring credentials in the Twine documentation.
License
This project is licensed under the Apache License 2.0. You may use, modify, and distribute this software as long as you provide proper attribution and include the full text of the license in any distributed copies or derivative works.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file prompt_caller-0.0.3.tar.gz
.
File metadata
- Download URL: prompt_caller-0.0.3.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd8908658e7bda0b1a376f5a466fe1af6d0588b0b298a279a2ecdb65dd2f8d92 |
|
MD5 | c3c85a01917d9293b277c197ca51a2b0 |
|
BLAKE2b-256 | 9071b5e229da87d1e53b3d93144599242450d4f690310bfe4d97c021e74fea3e |
File details
Details for the file prompt_caller-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: prompt_caller-0.0.3-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0bd7f23d6cdd7e7251e91b6bc94342bea380de32f6dcf5ba3e70d6e444d1b191 |
|
MD5 | 7075898ade85f608cf0090ffbad634ee |
|
BLAKE2b-256 | d7fecfa6a3da71ea43166b09957deda42510e7e42c5ce4dba666deb152361727 |