Skip to main content

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


Download files

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

Source Distribution

pic_prompt-1.8.0.tar.gz (4.1 MB view details)

Uploaded Source

Built Distribution

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

pic_prompt-1.8.0-py3-none-any.whl (35.0 kB view details)

Uploaded Python 3

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

Hashes for pic_prompt-1.8.0.tar.gz
Algorithm Hash digest
SHA256 e1ad78537519f0c94dcac6ad2f4c5b886f70f10d9a68ff993479e9f1de3066eb
MD5 63e47501d8e8240bcc512ff3a58fbad7
BLAKE2b-256 22463796236628eb31b5f5f6c8b28ea10277c5788b5e26204525243149a3ca6c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pic_prompt-1.8.0.tar.gz:

Publisher: publish.yml on paulbaranowski/pic-prompt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for pic_prompt-1.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a1853e012b05d25727ef3e810e9b608c9a7afa0ef96dfaee5cd09202bc71ba51
MD5 c1246f02fff946f7d5789be5b77772d8
BLAKE2b-256 db28936e0c177c8497041be629bbb3e9746c08d82aa534321591faa32dfaa6d7

See more details on using hashes here.

Provenance

The following attestation bundles were made for pic_prompt-1.8.0-py3-none-any.whl:

Publisher: publish.yml on paulbaranowski/pic-prompt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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