Django OpenAI Assistant
Project description
A Django / Celery scalable OpenAI Assistant Runner.
Assumption: you have Django up and running with Celery. (Tested on Redis)
-
pip install django_openai_assistant
-
in settings.py Add 'django_openai_assistant' to your INSTALLED_APPS [] array
make sure to have OPENAI_API_KEY defined in settings with your OpenAI key
create and apply migrations for django_openai_assistant -
Create a simple Assistant in https://platform.openai.com/assistants To begin you probably want one with no functions. Let's say you called it 'Test Assistant'
-
Use the assistant in your code:
demo.py
ffrom django_openai_assistant.assistant import assistantTask
from celery import shared_task
# Define OPENAI_API_KEY in your settings.py file
# Add 'django_openai_assistant' to your INSTALLED_APPS in settings.py
# run python manage.py makemigrations django_openai_assistant and then python managey.pymigrate
# create at least one Assistant in https://platform.openai.com/assistants
def testAssistant(request=None):
# replace <<your appname>> with the name you django app this file is in!
# replace <<your assistant name>> with the name of the assistant you created in the OpenAI platform
task = assistantTask(assistantName="<<your assistant name>>", tools= [], completionCall = "<<your appname>>.test:afterRunFunction")
task.prompt = "Who was Napoleon Bonaparte?"
task.createRun() ## this will get everything going!
@shared_task(Name="This will be called once the run is complete")
def afterRunFunction(taskID):
# Function is called when run is completed. MUST be annoted as @shared_task!!!
# start by retrieving the task
task = assistantTask(run_id = taskID)
if task.status == 'completed': ## check to make sure it is completed not failed or something else
print(task.markdownresponse())
else:
print('run failed')
Version history:
0.5.3
- Added getfullresponse() that comiles all Assistant repsonses in one message
- still waiting for the openai Python library to support vision. 0.5.2
- Updated the file upload mechanism to determine file types (retrieval yes/no and prepare for vision support (image yes/no))
- When attachments are added to a thread they will always have 'tools' enabled and retrieval will only be enabled for the supported file types https://platform.openai.com/docs/assistants/tools/file-search/supported-files
0.5.1
- Remove getopenaiclient() instead use OpenAI() everywhere
- Fix getAssistant() that could fail if retrieving an Assistant by name from an org with more than 20 Assistants.
0.5.0
- Added support for Assistants 2.0. For now all files are added to a thread with support for both search and code completion. For now no support to upload files to a vectorstore to an Assistant.
0.4.3
- Added optional parameter temperature createRun() default is 1, like the OpenAI default
0.4.2
- Added optional parameter temperature createRun() default is 1, like the OpenAI default
0.4.1
- another fix for metadata always returning {} never None
0.4.0
- redo readme.md
- standard version numbering
- task.metadata is now initiatilized as {} to prevent task.metadata.get() from failing.
0.33
- retrieve by thread_id or run_id openaiTask(run_id='run_xxxx').
- asmarkdown(string) available as a function outside class
- retrievefile() to download a file by openai file ID.
- now processing multi response with embedded image.
0.32
- small fixes.
0.31
- made sure that file uploads to openai receive a 'file name' when uploaded.
0.30
- fix to properly differentiate between two functions that start with the same name like 'company'
- and 'companyfind' and throw and exception (istead of a pass) when running in Debug mode when calling tool function.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django_openai_assistant-0.5.3.tar.gz
.
File metadata
- Download URL: django_openai_assistant-0.5.3.tar.gz
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9847c8ea185dddf95db22436f13cfb8f7d7dc7abb5a472123d775ec5d3e4a702 |
|
MD5 | c637b8b958539e1932b3f5f2c8e55ac1 |
|
BLAKE2b-256 | 4180de1bf12b5d70ff6c352d0d78eb283bfecbfe4d9d00021c82322633159e5d |
File details
Details for the file django_openai_assistant-0.5.3-py2.py3-none-any.whl
.
File metadata
- Download URL: django_openai_assistant-0.5.3-py2.py3-none-any.whl
- Upload date:
- Size: 11.3 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 55aebf3b9b1057cd6c9b00c650d95411843a5e92bbc554e34f9d1b9fcb37f99e |
|
MD5 | c0cc1d579ff2586cc1f1cbf8f9a8e713 |
|
BLAKE2b-256 | f35c5747d16f95352066240deed8a3dd51a68ea23ff1fbda0fa72e841332ff4b |