From 6df353f747dcb3386806e4cc9fbf5c40b3495b95 Mon Sep 17 00:00:00 2001 From: "L. Fernando De Pombo" <2381303+depombo@users.noreply.github.com> Date: Mon, 9 Sep 2024 14:34:22 -0700 Subject: [PATCH] implement the rest of the assistants api (#9) --- README.md | 8 ++++++- package.json | 2 +- src/index.ts | 62 +++++++++++++++++++++++++++++++++------------------- 3 files changed, 47 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index b4f8d9e..9051028 100644 --- a/README.md +++ b/README.md @@ -76,10 +76,16 @@ Check the [example](https://github.com/backmesh/openai-react-native/blob/main/sa - [x] [Chat Completion](https://platform.openai.com/docs/api-reference/chat) - [x] [Models](https://beta.openai.com/docs/api-reference/models) -- [ ] [Images](https://beta.openai.com/docs/api-reference/images) - [x] [Files](https://beta.openai.com/docs/api-reference/files) - [x] [Moderations](https://beta.openai.com/docs/api-reference/moderations) +- [ ] [Images](https://beta.openai.com/docs/api-reference/images) +- [ ] [Audio](https://platform.openai.com/docs/api-reference/audio) +- [ ] [Embeddings](https://platform.openai.com/docs/api-reference/embeddings) + +## Beta Coverage + - [x] [Threads](https://beta.openai.com/docs/api-reference/threads) +- [x] [Assistants](https://platform.openai.com/docs/api-reference/assistants) ### License diff --git a/package.json b/package.json index a16bbd7..14db7c2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "openai-react-native", - "version": "0.3.5", + "version": "0.3.6", "description": "OpenAI React Native API Client without polyfills", "main": "dist/src/index.js", "types": "dist/src/index.d.ts", diff --git a/src/index.ts b/src/index.ts index 9f8358b..a6bfb50 100644 --- a/src/index.ts +++ b/src/index.ts @@ -31,6 +31,32 @@ export import ChatCompletion = OpenAINode.ChatCompletion; export import FileObject = OpenAINode.FileObject; export import FileContent = OpenAINode.FileContent; export import FileDeleted = OpenAINode.FileDeleted; +// export nested types from OpenAINode Beta API +export namespace Beta { + export import ThreadCreateParams = OpenAINode.Beta.ThreadCreateParams; + export import Thread = OpenAINode.Beta.Thread; + export import ThreadUpdateParams = OpenAINode.Beta.ThreadUpdateParams; + export import ThreadCreateAndRunParamsNonStreaming = OpenAINode.Beta.ThreadCreateAndRunParamsNonStreaming; + export import ThreadDeleted = OpenAINode.Beta.ThreadDeleted; + export import Assistant = OpenAINode.Beta.Assistant; + export import AssistantDeleted = OpenAINode.Beta.AssistantDeleted; + export namespace Assistants { + export import AssistantCreateParams = OpenAINode.Beta.Assistants.AssistantCreateParams; + } + export namespace Threads { + export import Run = OpenAINode.Beta.Threads.Run; + export namespace Runs { + export type RunCreateParamsNonStreaming = + OpenAINode.Beta.Threads.Runs.RunCreateParamsNonStreaming; + } + export import Message = OpenAINode.Beta.Threads.Message; + export namespace Messages { + export import MessageCreateParams = OpenAINode.Beta.Threads.Messages.MessageCreateParams; + export import MessageListParams = OpenAINode.Beta.Threads.Messages.MessageListParams; + export import MessageDeleted = OpenAINode.Beta.Threads.Messages.MessageDeleted; + } + } +} export class OpenAI { public apiKey: string; @@ -60,6 +86,19 @@ export class OpenAI { assistants: { list: async (): Promise => (await this.client.beta.assistants.list()).data, + create: async ( + body: Beta.Assistants.AssistantCreateParams + ): Promise => + await this.client.beta.assistants.create(body), + del: async (assistantId: string): Promise => + await this.client.beta.assistants.del(assistantId), + retrieve: async (assistantId: string): Promise => + await this.client.beta.assistants.retrieve(assistantId), + update: async ( + assistantId: string, + body: Beta.Assistants.AssistantCreateParams + ): Promise => + await this.client.beta.assistants.update(assistantId, body), }, threads: { create: async (body?: Beta.ThreadCreateParams): Promise => @@ -244,27 +283,4 @@ export class OpenAI { } } -// export nested types from OpenAINode Beta API -export namespace Beta { - export import ThreadCreateParams = OpenAINode.Beta.ThreadCreateParams; - export import Thread = OpenAINode.Beta.Thread; - export import ThreadUpdateParams = OpenAINode.Beta.ThreadUpdateParams; - export import ThreadCreateAndRunParamsNonStreaming = OpenAINode.Beta.ThreadCreateAndRunParamsNonStreaming; - export import ThreadDeleted = OpenAINode.Beta.ThreadDeleted; - export import Assistant = OpenAINode.Beta.Assistant; - export namespace Threads { - export import Run = OpenAINode.Beta.Threads.Run; - export namespace Runs { - export type RunCreateParamsNonStreaming = - OpenAINode.Beta.Threads.Runs.RunCreateParamsNonStreaming; - } - export import Message = OpenAINode.Beta.Threads.Message; - export namespace Messages { - export import MessageCreateParams = OpenAINode.Beta.Threads.Messages.MessageCreateParams; - export import MessageListParams = OpenAINode.Beta.Threads.Messages.MessageListParams; - export import MessageDeleted = OpenAINode.Beta.Threads.Messages.MessageDeleted; - } - } -} - export default OpenAI;