Skip to main content

A simple tracker for OpenAI API calls for Pype App

Project description

OpenAI Tracker

Python Poetry License: MIT PyPI version GitHub issues GitHub stars

A simple tracker for OpenAI API calls with built-in dashboard integration and unique instance tracking.

Features

  • Easy integration with OpenAI API
  • Built-in dashboard for analytics
  • Unique instance tracking
  • Support for multiple trackers in a single application

Installation

You can install the OpenAI Tracker using pip:

pip install pypeprompts

Or if you're using Poetry:

poetry add pypeprompts

Usage

Basic Usage

For simple use cases where you want all tracked calls to share the same instance ID:

from openai import OpenAI
from pypeprompts import PromptAnalyticsTracker

client = OpenAI(api_key="your-api-key")

# Initialize the PromptAnalyticsTracker
tracker = PromptAnalyticsTracker(
    name="OpenAI API Tracker",
    api_key=analytics_api_key,
)

@tracker.track_prompt
def generate_text(prompt: str) -> str:
    try:
        response = client.chat.completions.create(
            model="gpt-4",
            messages=[{"role": "user", "content": prompt}],
        )
        return response.choices[0].message.content
    except Exception as e:
        print(f"Error calling OpenAI API: {e}")
        return

# Use the function
response = generate_text("Tell me a poem")
print(response)

Advanced Usage

For cases where you want to track different parts of your application separately:

from openai import OpenAI
from pypeprompts import PromptAnalyticsTracker

client = OpenAI(api_key="your-api-key")

# Create separate trackers for different parts of your application
user_tracker = PromptAnalyticsTracker(
    name="User prompts tracker",
    api_key=analytics_api_key,
)
admin_tracker = PromptAnalyticsTracker(
    name="Admin prompts tracker",
    api_key=analytics_api_key,
)

@user_tracker.track_prompt
def user_generate_response(prompt):
    completion = client.chat.completions.create(
        model="gpt-3.5-turbo",
        messages=[{"role": "user", "content": prompt}]
    )
    return completion.choices[0].message.content

@admin_tracker.track_prompt
def admin_generate_response(prompt):
    completion = client.chat.completions.create(
        model="gpt-4",
        messages=[{"role": "system", "content": prompt}]
    )
    return completion.choices[0].message.content

# Use the functions
user_response = user_generate_response("Tell me a joke")
admin_response = admin_generate_response("Explain quantum computing")

Configuration

Detailed configuration options and environment variables...

Dashboard

Information about accessing and using the built-in dashboard...

Contributing

We welcome contributions to OpenAI Tracker! Please see our Contributing Guide for more details.

Testing

To run the tests, use the following command:

poetry run pytest

Changelog

See the CHANGELOG.md file for details on what has changed.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • OpenAI for their excellent API
  • Contributors who have helped to improve this project

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

pypeprompts-0.0.1.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

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

pypeprompts-0.0.1-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file pypeprompts-0.0.1.tar.gz.

File metadata

  • Download URL: pypeprompts-0.0.1.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.5 Darwin/19.6.0

File hashes

Hashes for pypeprompts-0.0.1.tar.gz
Algorithm Hash digest
SHA256 c0bf075cb7d08088d45c665b2a5ad84193a269f43e6575bf319b3be7654239b9
MD5 56f2c9ee827e98a31b26f80debe35cb1
BLAKE2b-256 347a9bbeeb9dc1a0e256fa023d6ff5794a3f6f603c63523091d1d5e5300a23df

See more details on using hashes here.

File details

Details for the file pypeprompts-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: pypeprompts-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.5 Darwin/19.6.0

File hashes

Hashes for pypeprompts-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e00605a80e4c4f2add34f032d8931539fdc6f06e4913fb7e5f3f386fe31f86cd
MD5 2cd0a8e879b46e02c9950e26ee9b6a8b
BLAKE2b-256 a2b4576ff3c3cad8fa43463f3f75d4b4544ac8725dec380ffaa2804b8eb29126

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