Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Assistants API #1

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

feat: Assistants API #1

wants to merge 11 commits into from

Conversation

cdillard
Copy link
Owner

@cdillard cdillard commented Nov 17, 2023

Yeah, I'd like to be able to support the assistant features like threads, runs, and files with assistants API.

I have a PR to start to explore the possibilities here.

Six new API endpoints are exposed in the APIPath to support the assistants API.

    static let assistants = "/v1/assistants"
    static let threads = "/v1/threads"
    static let runs = "/v1/threads/THREAD_ID/runs"
    static let runRetrieve = "/v1/threads/THREAD_ID/runs/RUN_ID"
    static let threadsMessages = "/v1/threads/THREAD_ID/messages"
    static let files = "/v1/files"

The OpenAIProtocol is modified as follows: added


    func assistants(query: AssistantsQuery?, method: String, completion: @escaping (Result<AssistantsResult, Error>) -> Void)
    

    func threads(query: ThreadsQuery, completion: @escaping (Result<ThreadsResult, Error>) -> Void)


    func runs(threadId: String, query: RunsQuery, completion: @escaping (Result<RunsResult, Error>) -> Void)


    func runRetrieve(threadId: String, runId:String, completion: @escaping (Result<RunRetreiveResult, Error>) -> Void)


    func threadsMessages(threadId: String, before: String?, completion: @escaping (Result<ThreadsMessagesResult, Error>) -> Void)


    func threadsAddMessage(threadId: String, query: ThreadAddMessageQuery, completion: @escaping (Result<ThreadAddMessageResult, Error>) -> Void)


    func files(query: FilesQuery, completion: @escaping (Result<FilesResult, Error>) -> Void)

Assistants:

  • Create
  • Modify
  • Attach 1 file (PDF only currently)
    • Attach up to 10(20) files of all supported OpenAI types.
  • List assistants
    • Paging through assistants list

Tools can be passed to assistant creation.

  • Code Interpreter
  • Retrieval
  • Functions

Threads/Runs

  • Create Thread
  • Create Run
  • Retrieve Run
  • Add Message to Thread
  • Retrieve Threads Messages
    • Paging through messages in a thread

Files

  • Upload
  • Delete
  • List

Example App:

A new demonstration of the assistants API and its requirements of the polling has been added to the Demo app.

  • Now you can create a new assistant on the Chats tab by selecting "+" -> New Assistant -> Fill in details -> OK.
    This should result in a "New Assistant" row being added to the chats, you can chat with your newly created assistant in this conversation.

  • You can now list your OpenAI API Assistants on the "Assistants" tab. Select "+" -> Get Assistants to load the assistants list.

  • I've implemented the file upload and assistant creation with up to 1 PDF. (For now, will be fixed to add support for all of OpenAIs supported file types.)

Create Assistant
createAssistant

Chat with Assistant in thread
chatThread

List assistants
listAssistants

Describe the solution you'd like
Support for Assistants, Threads, Runs, Run Retrieval, Fetching messages from threads, and uploading files to OpenAI API.

@GuillaumeBourge
Copy link

Hello
Thanks for your work ! :)
Is it possible to add "limit" parameter on ListMessages of thread API :
https://platform.openai.com/docs/api-reference/messages/listMessages.
This one is usefull to economize token usage !

Regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants