Skip to main content

A minimalist and powerful interface for the OpenAI API with multimodal and history management support.

Project description

oiaapi (OpenAI API Python Interface)

A minimalist yet powerful Python interface for the OpenAI API, designed for structured conversation management and advanced multimodal interactions.

Features

  • Centralized Client: Use a single Client to manage your connection and spawn multiple chat sessions.
  • Variadic Chat Interface: Send multiple message components directly: chat.chat("Text", Image("local.png"), "More text").
  • Node-Based History: Every interaction is a node with an incremental ID.
  • Context Control: Activate or deactivate conversation nodes by their ID to manage the model's window.
  • Enhanced Metrics: Track token usage, models, and active nodes per request with built-in Pandas integration.
  • Multimodal Support: Handle local images (auto-base64 encoding) and remote URLs seamlessly.
  • State Persistence: Save Chat states and load them via the Client to resume sessions.
  • Deep Copy: Create independent clones of your chat session.

Installation

# Via Pip (once published)
pip install oiaapi

# From source
git clone https://github.com/artitzco/openai-api.git
cd openai-api
pip install .

Quick Start

from oiaapi import Client, Image

# Initialize the main client
client = Client(api_key="your-api-key") # or use OPENAI_API_KEY env var

# Start a new chat session
chat = client.chat(model="gpt-4o-mini", system_prompt="You are a helpful assistant.")

# Basic Chat
response = chat.chat("Hello! What can you do?")
print(response)

# Multimodal Chat (Local and URL)
chat.chat(
    "Analyze these images:",
    Image("path/to/local_image.png"),
    "and also this one:",
    Image("https://example.com/image.jpg")
)

# Manage History
df_history = chat.history.to_dataframe()
chat.history.toggle(node_id=1, active=False) # Context management

# Persistence
chat.save("my_session.json")
new_chat_recovered = client.load_chat("my_session.json")

Project Structure

  • src/oiaapi/: Core library modules.
    • __init__.py: Contains the Client factory and exports.
    • core.py: Contains the Chat session manager.
    • history.py: Logic for node-based conversation management.
    • metrics.py: Token usage and request tracking.
    • content.py: Multimodal data builders (Images, etc.).
  • notebooks/: Interactive guides and testing playgrounds.
  • img/: Storage for sample assets.
  • output/: Default location for saved session JSONs.

License

MIT

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

oiaapi-0.1.0.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

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

oiaapi-0.1.0-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file oiaapi-0.1.0.tar.gz.

File metadata

  • Download URL: oiaapi-0.1.0.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for oiaapi-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c51613f076cf4b33802ec0f659a3f3bde409c3ffefb26100542927a97c8818ce
MD5 01d53f1b6e26e209dadbe4f29f280bb6
BLAKE2b-256 2cc6965effd3dfc3927030ce424bb1c73f4d680678e3c54759e077cdadb51159

See more details on using hashes here.

File details

Details for the file oiaapi-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: oiaapi-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for oiaapi-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2cdb7f30f55f1a53d798708c04a9d038fcad5d4f2ac3b70608315dc6c92cc7ad
MD5 9712a7675a60094396b70f543ec0f0eb
BLAKE2b-256 b36f25ffc1eace8c1498a6ffccb048400ce3d0cbfa2a88fe95dbc64a83384454

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