Skip to main content

An asynchronous Python package for integrating OpenAI assistant.

Project description

GitHub Repository: openai-assistant-python

Important Warning

This package is currently under development and may contain bugs. If you encounter any issues, please report them in the issues section.

Description

This is an asynchronous Python package.

The OpenAI Assistant Python package is designed to help developers easily and efficiently integrate OpenAI assistant capabilities into their applications. If you find this package helpful, please consider giving a star to this repository.

ToDo

  • Support for synchronous OpenAI client

  • Optimize code

  • Write a docs

  • more…..

Installation

You can install the OpenAI Assistant package using pip:

pip install openai-assistant

Usage

To use this package, you need to initialize it with your OpenAI client. Here’s an example using AsyncOpenAI:

import asyncio
from openai_assistant import init, OpenAIAssistant
from openai import AsyncOpenAI

# Initialize the OpenAI client with API key
openai = AsyncOpenAI(api_key="sk-123456")

# Initialize OpenAI assistants
assistants = init(openai)

# Define your assistant or agent class
class TestAgent(OpenAIAssistant):
    def __init__(self, assistant_id, thread_id=None, callback=None):
        # or just put your assistant id here
        assistant_id = "your-assistant-id"
        super().__init__(assistant_id, thread_id, callback)

    @classmethod
    async def create(cls, assistant_id, thread_id=None, callback=None):
        # You can remove assistant_id from arguments, if you put it in __init__
        self = cls(assistant_id, thread_id, callback)
        await self.initialize_thread_id()
        return self

    async def submit_request(self, user_input: str):
        return await self.send_request(user_input)

    async def send_request_image_base64(self, user_input: str, base64_images: list):
        return await self.send_request_image_base64(user_input, base64_images)

    async def send_request_image_url(self, user_input: str, urls: list):
        return await self.send_request_image_url(user_input, urls)

# Create an agent instance and submit a request
async def main():
    agent = await TestAgent.create()
    response = await agent.submit_request("Hello, how are you?")
    print(response)

    # Base64 image example
    response = await agent.send_request_image_base64("What is in this image?", ["data:image/jpeg;base64,/9jS..."])
    print(response)

    # URL image example
    response = await agent.send_request_image_url("What is in this image?", ["https://example.com/image.jpg"])
    print(response)

# Run the main function
asyncio.run(main())

Want to enable your assistant to call custom functions? Register your function map:

from openai_assistant import register_function, register_functions

# Register a single function; this only adds to the existing functions, not replaces them
register_function("function_name", function)

# Register multiple functions; this only adds to the existing functions, not replaces them
register_functions({
    "function_name1": function1,
    "function_name2": function2,
})

License

This project is licensed under the MIT License.

Reference

Inspired by and improved upon: openai-assistent-python by shamspias.

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_assistant-0.1.8.tar.gz (12.4 kB view details)

Uploaded Source

Built Distribution

openai_assistant-0.1.8-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file openai_assistant-0.1.8.tar.gz.

File metadata

  • Download URL: openai_assistant-0.1.8.tar.gz
  • Upload date:
  • Size: 12.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for openai_assistant-0.1.8.tar.gz
Algorithm Hash digest
SHA256 f23e06f290997047ae090b52bc85a700f88e734128d6752eb31e99b0fc640d91
MD5 1a16b0727cc0dbfd62933df5e8295238
BLAKE2b-256 6cdcbc3bb3675b6c346591029b3fdf49065c44c1d9bb7b72de5c1fa3e6ee1a58

See more details on using hashes here.

File details

Details for the file openai_assistant-0.1.8-py3-none-any.whl.

File metadata

File hashes

Hashes for openai_assistant-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 c588e4432c2845f0eff0479df31eba85785b6021266b39472685feb6a79ff460
MD5 b436e710d9690cee471b123e9e3b52ae
BLAKE2b-256 552e7507a4797fb5ccbe316016312558e5067603cade55152c5ca6c8f4c9c143

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