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.
Metadata
Release files for openai-assistant 0.1.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| openai_assistant-0.1.8.tar.gz | 12.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| openai_assistant-0.1.8-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 23.2 kB
Release files / openai_assistant-0.1.8.tar.gz
| Download URL | openai_assistant-0.1.8.tar.gz |
|---|---|
| Size | 12.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f23e06f290997047ae090b52bc85a700f88e734128d6752eb31e99b0fc640d91
|
|
BLAKE2b-256 checksum How to use checksums |
6cdcbc3bb3675b6c346591029b3fdf49065c44c1d9bb7b72de5c1fa3e6ee1a58
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.3
|
Release files / openai_assistant-0.1.8-py3-none-any.whl
| Download URL | openai_assistant-0.1.8-py3-none-any.whl |
|---|---|
| Size | 10.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c588e4432c2845f0eff0479df31eba85785b6021266b39472685feb6a79ff460
|
|
BLAKE2b-256 checksum How to use checksums |
552e7507a4797fb5ccbe316016312558e5067603cade55152c5ca6c8f4c9c143
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.3
|