Skip to main content

Unofficial OpenAI API Python SDK

Project description

OpenAI Unofficial Python SDK

PyPI License Python Versions Downloads

An Free & Unlimited unofficial Python SDK for the OpenAI API, providing seamless integration and easy-to-use methods for interacting with OpenAI's latest powerful AI models, including GPT-4o (Including gpt-4o-audio-preview & gpt-4o-realtime-preview Models), GPT-4, GPT-3.5 Turbo, DALL·E 3, Whisper & Text-to-Speech (TTS) models for Free

Table of Contents


Features

  • Comprehensive Model Support: Integrate with the latest OpenAI models, including GPT-4, GPT-4o, GPT-3.5 Turbo, DALL·E 3, Whisper, Text-to-Speech (TTS) models, and the newest audio preview and real-time models.
  • Chat Completions: Generate chat-like responses using a variety of models.
  • Streaming Responses: Support for streaming chat completions, including real-time models for instantaneous outputs.
  • Audio Generation: Generate high-quality speech audio with various voice options using TTS models.
  • Audio and Text Responses: Utilize models like gpt-4o-audio-preview to receive both audio and text responses.
  • Image Generation: Create stunning images using DALL·E models with customizable parameters.
  • Audio Transcription: Convert speech to text using Whisper models.
  • Easy to Use: Simple and intuitive methods to interact with various endpoints.
  • Extensible: Designed to be easily extendable for future OpenAI models and endpoints.

Installation

Install the package via pip:

pip install openai-unofficial

Quick Start

from openai_unofficial import OpenAIUnofficial

# Initialize the client
client = OpenAIUnofficial()

# Basic chat completion
response = client.chat.completions.create(
    messages=[{"role": "user", "content": "Say hello!"}],
    model="gpt-4o"
)
print(response.choices[0].message.content)

Usage Examples

List Available Models

from openai_unofficial import OpenAIUnofficial

client = OpenAIUnofficial()
models = client.list_models()
print("Available Models:")
for model in models['data']:
    print(f"- {model['id']}")

Basic Chat Completion

from openai_unofficial import OpenAIUnofficial

client = OpenAIUnofficial()
response = client.chat.completions.create(
    messages=[{"role": "user", "content": "Tell me a joke."}],
    model="gpt-4o"
)
print("ChatBot:", response.choices[0].message.content)

Chat Completion with Image Input

from openai_unofficial import OpenAIUnofficial

client = OpenAIUnofficial()
response = client.chat.completions.create(
    messages=[{
        "role": "user",
        "content": [
            {"type": "text", "text": "What's in this image?"},
            {
                "type": "image_url",
                "image_url": {
                    "url": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg",
                }
            },
        ],
    }],
    model="gpt-4o-mini-2024-07-18"
)
print("Response:", response.choices[0].message.content)

Streaming Chat Completion

from openai_unofficial import OpenAIUnofficial

client = OpenAIUnofficial()
completion_stream = client.chat.completions.create(
    messages=[{"role": "user", "content": "Write a short story in 3 sentences."}],
    model="gpt-4o-mini-2024-07-18",
    stream=True
)
for chunk in completion_stream:
    content = chunk.choices[0].delta.content
    if content:
        print(content, end='', flush=True)

Audio Generation with TTS Model

from openai_unofficial import OpenAIUnofficial

client = OpenAIUnofficial()
audio_data = client.audio.create(
    input_text="This is a test of the TTS capabilities!",
    model="tts-1-hd",
    voice="nova"
)
with open("tts_output.mp3", "wb") as f:
    f.write(audio_data)
print("TTS Audio saved as tts_output.mp3")

Chat Completion with Audio Preview Model

from openai_unofficial import OpenAIUnofficial

client = OpenAIUnofficial()
response = client.chat.completions.create(
    messages=[{"role": "user", "content": "Tell me a fun fact."}],
    model="gpt-4o-audio-preview",
    modalities=["text", "audio"],
    audio={"voice": "fable", "format": "wav"}
)

message = response.choices[0].message
print("Text Response:", message.content)

if message.audio and 'data' in message.audio:
    from base64 import b64decode
    with open("audio_preview.wav", "wb") as f:
        f.write(b64decode(message.audio['data']))
    print("Audio saved as audio_preview.wav")

Image Generation

from openai_unofficial import OpenAIUnofficial

client = OpenAIUnofficial()
response = client.image.create(
    prompt="A futuristic cityscape at sunset",
    model="dall-e-3",
    size="1024x1024"
)
print("Image URL:", response.data[0].url)

Audio Speech Recognition with Whisper Model

from openai_unofficial import OpenAIUnofficial

client = OpenAIUnofficial()
with open("speech.mp3", "rb") as audio_file:
    transcription = client.audio.transcribe(
        file=audio_file,
        model="whisper-1"
    )
print("Transcription:", transcription.text)

Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository.
  2. Create a new branch: git checkout -b feature/my-feature.
  3. Commit your changes: git commit -am 'Add new feature'.
  4. Push to the branch: git push origin feature/my-feature.
  5. Open a pull request.

Please ensure your code adheres to the project's coding standards and passes all tests.


License

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


Note: This SDK is unofficial and not affiliated with OpenAI.


If you encounter any issues or have suggestions, please open an issue on GitHub.


Supported Models

Here's a partial list of models that the SDK currently supports. For Complete list, check out the /models endpoint:

  • Chat Models:

    • gpt-4
    • gpt-4-turbo
    • gpt-4o
    • gpt-4o-mini
    • gpt-3.5-turbo
    • gpt-3.5-turbo-16k
    • gpt-3.5-turbo-instruct
    • gpt-4o-realtime-preview
    • gpt-4o-audio-preview
  • Image Generation Models:

    • dall-e-2
    • dall-e-3
  • Text-to-Speech (TTS) Models:

    • tts-1
    • tts-1-hd
    • tts-1-1106
    • tts-1-hd-1106
  • Audio Models:

    • whisper-1
  • Embedding Models:

    • text-embedding-ada-002
    • text-embedding-3-small
    • text-embedding-3-large

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

openai_unofficial-0.1.1.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

openai_unofficial-0.1.1-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file openai_unofficial-0.1.1.tar.gz.

File metadata

  • Download URL: openai_unofficial-0.1.1.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for openai_unofficial-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7c47758a1d2dd4a8b584a37295f84d225bff0f29bf2eda8659eaad876475ebb6
MD5 bb6b0c7e40fdcd33edb550ae3c505f0f
BLAKE2b-256 3668e22b34d86881d4b27d87d328c2eb404db862cd389cf571e11726d802eaab

See more details on using hashes here.

File details

Details for the file openai_unofficial-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for openai_unofficial-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1e65ad2303ed65b54dd3d078f91af5052613e939f347c2704eb80b6a25e71f19
MD5 374cfa10521a5e5d71d4b07de83bb4b3
BLAKE2b-256 cbd0c3f4f2db6d987e09866c7a99af36bf37cc190492fc9aa8c037c740922da0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page