Skip to content

Commit

Permalink
implement the rest of the assistants api (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
depombo authored Sep 9, 2024
1 parent a147818 commit 6df353f
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 25 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
62 changes: 39 additions & 23 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -60,6 +86,19 @@ export class OpenAI {
assistants: {
list: async (): Promise<Beta.Assistant[]> =>
(await this.client.beta.assistants.list()).data,
create: async (
body: Beta.Assistants.AssistantCreateParams
): Promise<Beta.Assistant> =>
await this.client.beta.assistants.create(body),
del: async (assistantId: string): Promise<Beta.AssistantDeleted> =>
await this.client.beta.assistants.del(assistantId),
retrieve: async (assistantId: string): Promise<Beta.Assistant> =>
await this.client.beta.assistants.retrieve(assistantId),
update: async (
assistantId: string,
body: Beta.Assistants.AssistantCreateParams
): Promise<Beta.Assistant> =>
await this.client.beta.assistants.update(assistantId, body),
},
threads: {
create: async (body?: Beta.ThreadCreateParams): Promise<Beta.Thread> =>
Expand Down Expand Up @@ -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;

0 comments on commit 6df353f

Please sign in to comment.