A library for building image prompts for OpenAI. Made for integration with LiteLLM.
Project description
pic-prompt
A Python library that provides a simple and flexible way to build image-based prompts for OpenAI. Initially it was developed to generate the prompt for different providers, but then we discovered LiteLLM (https://www.litellm.ai/) which will translate between OpenAI and other providers.
It focuses on the following problems:
- Downloading images from different sources, either synchronously or asynchronously
- Encoding images
- Handling media types (e.g. image/jpeg, image/png, etc.)
- Handling oversized images by resizing them to lower quality
- Inserting image data into prompts
It supports adding images from (Image Sources):
- URLs
- Local files
- S3 files
It is easy to add support for other providers and other image sources.
Installation
pip install pic-prompt
or:
uv add pic-prompt
Usage
To use the example scripts, set the OPENAI_API_KEY in your environment, typically in a .env file. These examples will do two queries each.
You do not need to set the OPENAI_API_KEY to actually use this library.
Example: examples/example1.py
This example fetches a local image and runs a LLM query on it,
and the fetches a URL and runs an LLM query on it.
Run it using:
python -m examples.example1
/Users/paul/dev/pic-prompt/examples/example2-image-cache.pyExample: examples/example2-image-cache.py
This example illustrates how to pre-fetch the images before creating the prompt.
Run it using:
python -m examples.example2-image-cache
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pic_prompt-1.8.0.tar.gz.
File metadata
- Download URL: pic_prompt-1.8.0.tar.gz
- Upload date:
- Size: 4.1 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e1ad78537519f0c94dcac6ad2f4c5b886f70f10d9a68ff993479e9f1de3066eb
|
|
| MD5 |
63e47501d8e8240bcc512ff3a58fbad7
|
|
| BLAKE2b-256 |
22463796236628eb31b5f5f6c8b28ea10277c5788b5e26204525243149a3ca6c
|
Provenance
The following attestation bundles were made for pic_prompt-1.8.0.tar.gz:
Publisher:
publish.yml on paulbaranowski/pic-prompt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pic_prompt-1.8.0.tar.gz -
Subject digest:
e1ad78537519f0c94dcac6ad2f4c5b886f70f10d9a68ff993479e9f1de3066eb - Sigstore transparency entry: 1199703031
- Sigstore integration time:
-
Permalink:
paulbaranowski/pic-prompt@a77f6b65a0ea7a43a2d138f5ee7e7ff89bb68af4 -
Branch / Tag:
refs/tags/v1.8.0 - Owner: https://github.com/paulbaranowski
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a77f6b65a0ea7a43a2d138f5ee7e7ff89bb68af4 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pic_prompt-1.8.0-py3-none-any.whl.
File metadata
- Download URL: pic_prompt-1.8.0-py3-none-any.whl
- Upload date:
- Size: 35.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a1853e012b05d25727ef3e810e9b608c9a7afa0ef96dfaee5cd09202bc71ba51
|
|
| MD5 |
c1246f02fff946f7d5789be5b77772d8
|
|
| BLAKE2b-256 |
db28936e0c177c8497041be629bbb3e9746c08d82aa534321591faa32dfaa6d7
|
Provenance
The following attestation bundles were made for pic_prompt-1.8.0-py3-none-any.whl:
Publisher:
publish.yml on paulbaranowski/pic-prompt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pic_prompt-1.8.0-py3-none-any.whl -
Subject digest:
a1853e012b05d25727ef3e810e9b608c9a7afa0ef96dfaee5cd09202bc71ba51 - Sigstore transparency entry: 1199703080
- Sigstore integration time:
-
Permalink:
paulbaranowski/pic-prompt@a77f6b65a0ea7a43a2d138f5ee7e7ff89bb68af4 -
Branch / Tag:
refs/tags/v1.8.0 - Owner: https://github.com/paulbaranowski
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a77f6b65a0ea7a43a2d138f5ee7e7ff89bb68af4 -
Trigger Event:
push
-
Statement type: