From 8c7b5d0eeac2ad27ad3c5db090024b4873c583bd Mon Sep 17 00:00:00 2001 From: James Date: Tue, 4 Jun 2024 16:01:01 +0700 Subject: [PATCH 1/7] fix: import on web Signed-off-by: James --- src/_shims/index.js | 2 +- src/_shims/index.mjs | 2 +- src/lib/AbstractAssistantStreamRunner.ts | 4 ++-- src/lib/AbstractChatCompletionRunner.ts | 4 ++-- src/lib/AssistantStream.ts | 8 ++++---- src/lib/ChatCompletionRunFunctions.test.ts | 2 +- src/lib/ChatCompletionStream.ts | 6 +++--- src/resources/beta/threads/threads.ts | 2 +- src/streaming.ts | 2 +- 9 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/_shims/index.js b/src/_shims/index.js index b5fc8229..54d85efc 100644 --- a/src/_shims/index.js +++ b/src/_shims/index.js @@ -2,7 +2,7 @@ * Disclaimer: modules in _shims aren't intended to be imported by SDK users. */ const shims = require('./registry'); -const auto = require('openai/_shims/auto/runtime'); +const auto = require('../_shims/auto/runtime'); if (!shims.kind) shims.setShims(auto.getRuntime(), { auto: true }); for (const property of Object.keys(shims)) { Object.defineProperty(exports, property, { diff --git a/src/_shims/index.mjs b/src/_shims/index.mjs index 81665e61..b2a5c6b0 100644 --- a/src/_shims/index.mjs +++ b/src/_shims/index.mjs @@ -2,6 +2,6 @@ * Disclaimer: modules in _shims aren't intended to be imported by SDK users. */ import * as shims from './registry.mjs'; -import * as auto from 'openai/_shims/auto/runtime'; +import * as auto from '../_shims/auto/runtime'; if (!shims.kind) shims.setShims(auto.getRuntime(), { auto: true }); export * from './registry.mjs'; diff --git a/src/lib/AbstractAssistantStreamRunner.ts b/src/lib/AbstractAssistantStreamRunner.ts index b600f0df..39bddbd3 100644 --- a/src/lib/AbstractAssistantStreamRunner.ts +++ b/src/lib/AbstractAssistantStreamRunner.ts @@ -1,5 +1,5 @@ -import * as Core from 'openai/core'; -import { APIUserAbortError, OpenAIError } from 'openai/error'; +import * as Core from '../core'; +import { APIUserAbortError, OpenAIError } from '../error'; import { Run, RunSubmitToolOutputsParamsBase } from 'openai/resources/beta/threads/runs/runs'; import { RunCreateParamsBase, Runs } from 'openai/resources/beta/threads/runs/runs'; import { ThreadCreateAndRunParamsBase, Threads } from 'openai/resources/beta/threads/threads'; diff --git a/src/lib/AbstractChatCompletionRunner.ts b/src/lib/AbstractChatCompletionRunner.ts index 8a8f4670..19196cb8 100644 --- a/src/lib/AbstractChatCompletionRunner.ts +++ b/src/lib/AbstractChatCompletionRunner.ts @@ -1,4 +1,4 @@ -import * as Core from 'openai/core'; +import * as Core from '../core'; import { type CompletionUsage } from 'openai/resources/completions'; import { type Completions, @@ -8,7 +8,7 @@ import { type ChatCompletionCreateParams, type ChatCompletionTool, } from 'openai/resources/chat/completions'; -import { APIUserAbortError, OpenAIError } from 'openai/error'; +import { APIUserAbortError, OpenAIError } from '../error'; import { type RunnableFunction, isRunnableFunctionWithParse, diff --git a/src/lib/AssistantStream.ts b/src/lib/AssistantStream.ts index de7511b5..4545ac52 100644 --- a/src/lib/AssistantStream.ts +++ b/src/lib/AssistantStream.ts @@ -9,8 +9,8 @@ import { Messages, MessageContent, } from 'openai/resources/beta/threads/messages'; -import * as Core from 'openai/core'; -import { RequestOptions } from 'openai/core'; +import * as Core from '../core'; +import { RequestOptions } from '../core'; import { Run, RunCreateParamsBase, @@ -24,8 +24,8 @@ import { AbstractAssistantStreamRunner, } from './AbstractAssistantStreamRunner'; import { type ReadableStream } from 'openai/_shims/index'; -import { Stream } from 'openai/streaming'; -import { APIUserAbortError, OpenAIError } from 'openai/error'; +import { Stream } from '../streaming'; +import { APIUserAbortError, OpenAIError } from '../error'; import { AssistantStreamEvent, MessageStreamEvent, diff --git a/src/lib/ChatCompletionRunFunctions.test.ts b/src/lib/ChatCompletionRunFunctions.test.ts index b524218a..17694fb0 100644 --- a/src/lib/ChatCompletionRunFunctions.test.ts +++ b/src/lib/ChatCompletionRunFunctions.test.ts @@ -1,5 +1,5 @@ import OpenAI from 'openai'; -import { OpenAIError, APIConnectionError } from 'openai/error'; +import { OpenAIError, APIConnectionError } from '../error'; import { PassThrough } from 'stream'; import { ParsingToolFunction, diff --git a/src/lib/ChatCompletionStream.ts b/src/lib/ChatCompletionStream.ts index 2ea04038..f24a0992 100644 --- a/src/lib/ChatCompletionStream.ts +++ b/src/lib/ChatCompletionStream.ts @@ -1,5 +1,5 @@ -import * as Core from 'openai/core'; -import { OpenAIError, APIUserAbortError } from 'openai/error'; +import * as Core from '../core'; +import { OpenAIError, APIUserAbortError } from '../error'; import { Completions, type ChatCompletion, @@ -12,7 +12,7 @@ import { type AbstractChatCompletionRunnerEvents, } from './AbstractChatCompletionRunner'; import { type ReadableStream } from 'openai/_shims/index'; -import { Stream } from 'openai/streaming'; +import { Stream } from '../streaming'; export interface ChatCompletionStreamEvents extends AbstractChatCompletionRunnerEvents { content: (contentDelta: string, contentSnapshot: string) => void; diff --git a/src/resources/beta/threads/threads.ts b/src/resources/beta/threads/threads.ts index 27009437..a246e3f5 100644 --- a/src/resources/beta/threads/threads.ts +++ b/src/resources/beta/threads/threads.ts @@ -10,7 +10,7 @@ import * as AssistantsAPI from '../assistants'; import * as MessagesAPI from './messages'; import * as RunsAPI from './runs/runs'; import { Stream } from '../../../streaming'; -import { Page } from 'openai/pagination'; +import { Page } from '../../../pagination'; /** * Note: no pagination actually occurs yet, this is for forwards-compatibility. diff --git a/src/streaming.ts b/src/streaming.ts index 722a8f69..64cb2efd 100644 --- a/src/streaming.ts +++ b/src/streaming.ts @@ -1,7 +1,7 @@ import { ReadableStream, type Response } from './_shims/index'; import { OpenAIError } from './error'; -import { APIError } from 'openai/error'; +import { APIError } from './error'; type Bytes = string | ArrayBuffer | Uint8Array | Buffer | null | undefined; From 85a5a2d3e9bb7e2cbef26936c5da7651cde32196 Mon Sep 17 00:00:00 2001 From: James Date: Tue, 11 Jun 2024 19:08:41 +0700 Subject: [PATCH 2/7] update Signed-off-by: James --- src/index.ts | 1 + src/resources/beta/beta.ts | 1 + src/resources/beta/index.ts | 1 + src/resources/beta/threads/index.ts | 1 + src/resources/beta/threads/threads.ts | 1 + src/resources/models.ts | 7 +++++++ 6 files changed, 12 insertions(+) diff --git a/src/index.ts b/src/index.ts index f65eefe3..897b4803 100644 --- a/src/index.ts +++ b/src/index.ts @@ -293,6 +293,7 @@ export namespace OpenAI { export import Model = API.Model; export import ModelDeleted = API.ModelDeleted; export import ModelsPage = API.ModelsPage; + export import ThreadsPage = API.Beta.ThreadsPage; export import FineTuning = API.FineTuning; diff --git a/src/resources/beta/beta.ts b/src/resources/beta/beta.ts index cefe6682..9149a064 100644 --- a/src/resources/beta/beta.ts +++ b/src/resources/beta/beta.ts @@ -39,6 +39,7 @@ export namespace Beta { export import AssistantUpdateParams = AssistantsAPI.AssistantUpdateParams; export import AssistantListParams = AssistantsAPI.AssistantListParams; export import Threads = ThreadsAPI.Threads; + export import ThreadsPage = ThreadsAPI.ThreadsPage; export import AssistantResponseFormat = ThreadsAPI.AssistantResponseFormat; export import AssistantResponseFormatOption = ThreadsAPI.AssistantResponseFormatOption; export import AssistantToolChoice = ThreadsAPI.AssistantToolChoice; diff --git a/src/resources/beta/index.ts b/src/resources/beta/index.ts index 029cd084..2d7ecb59 100644 --- a/src/resources/beta/index.ts +++ b/src/resources/beta/index.ts @@ -34,6 +34,7 @@ export { ThreadCreateAndRunPollParams, ThreadCreateAndRunStreamParams, Threads, + ThreadsPage, } from './threads/index'; export { Beta } from './beta'; export { Chat } from './chat/index'; diff --git a/src/resources/beta/threads/index.ts b/src/resources/beta/threads/index.ts index b55f67ed..79d85b2b 100644 --- a/src/resources/beta/threads/index.ts +++ b/src/resources/beta/threads/index.ts @@ -49,6 +49,7 @@ export { ThreadCreateAndRunPollParams, ThreadCreateAndRunStreamParams, Threads, + ThreadsPage, } from './threads'; export { RequiredActionFunctionToolCall, diff --git a/src/resources/beta/threads/threads.ts b/src/resources/beta/threads/threads.ts index a246e3f5..734cf293 100644 --- a/src/resources/beta/threads/threads.ts +++ b/src/resources/beta/threads/threads.ts @@ -1489,6 +1489,7 @@ export namespace Threads { export import AssistantToolChoiceFunction = ThreadsAPI.AssistantToolChoiceFunction; export import AssistantToolChoiceOption = ThreadsAPI.AssistantToolChoiceOption; export import Thread = ThreadsAPI.Thread; + export import ThreadsPage = ThreadsAPI.ThreadsPage; export import ThreadDeleted = ThreadsAPI.ThreadDeleted; export import ThreadCreateParams = ThreadsAPI.ThreadCreateParams; export import ThreadUpdateParams = ThreadsAPI.ThreadUpdateParams; diff --git a/src/resources/models.ts b/src/resources/models.ts index f15422e3..368dccec 100644 --- a/src/resources/models.ts +++ b/src/resources/models.ts @@ -43,6 +43,13 @@ export class Models extends APIResource { stop(model: string, options?: Core.RequestOptions): Core.APIPromise { return this._client.post(`/models/${model}/stop`, options); } + + /** + * Download a model. + */ + download(model: string) { + return this._client.get(`/models/download/${model}`); + } } /** From 4a9ea3542d7e0d90c40eafe3630c404302db722a Mon Sep 17 00:00:00 2001 From: James Date: Thu, 13 Jun 2024 00:30:43 +0700 Subject: [PATCH 3/7] add abort download --- src/resources/models.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/resources/models.ts b/src/resources/models.ts index 368dccec..21eef3f7 100644 --- a/src/resources/models.ts +++ b/src/resources/models.ts @@ -50,6 +50,13 @@ export class Models extends APIResource { download(model: string) { return this._client.get(`/models/download/${model}`); } + + /** + * Abort a model download. + */ + abortDownload(downloadId: string) { + return this._client.get(`/models/abort-download/${downloadId}`); + } } /** From 33a3302feb804bdc984c7ff632d12d3935fddc88 Mon Sep 17 00:00:00 2001 From: James Date: Fri, 14 Jun 2024 16:40:26 +0700 Subject: [PATCH 4/7] update Signed-off-by: James --- src/resources/models.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/resources/models.ts b/src/resources/models.ts index 21eef3f7..0c8cb6e3 100644 --- a/src/resources/models.ts +++ b/src/resources/models.ts @@ -57,6 +57,10 @@ export class Models extends APIResource { abortDownload(downloadId: string) { return this._client.get(`/models/abort-download/${downloadId}`); } + + update(model: string, options: Record) { + return this._client.patch(`/models/${model}`, options); + } } /** From 827870f04cc559c368940481e0503486f0638d05 Mon Sep 17 00:00:00 2001 From: James Date: Wed, 19 Jun 2024 12:09:25 +0700 Subject: [PATCH 5/7] update Signed-off-by: James --- src/resources/models.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/resources/models.ts b/src/resources/models.ts index 0c8cb6e3..2864600f 100644 --- a/src/resources/models.ts +++ b/src/resources/models.ts @@ -58,8 +58,8 @@ export class Models extends APIResource { return this._client.get(`/models/abort-download/${downloadId}`); } - update(model: string, options: Record) { - return this._client.patch(`/models/${model}`, options); + update(model: string, body: Record, options?: Core.RequestOptions) { + return this._client.patch(`/models/${model}`, { body, ...options }); } } From 7ed50a9b44a1aa853b759b0538ccb5f1e41e68fb Mon Sep 17 00:00:00 2001 From: James Date: Wed, 19 Jun 2024 13:08:40 +0700 Subject: [PATCH 6/7] update model Signed-off-by: James --- src/resources/models.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/resources/models.ts b/src/resources/models.ts index 2864600f..f7c390cf 100644 --- a/src/resources/models.ts +++ b/src/resources/models.ts @@ -59,7 +59,7 @@ export class Models extends APIResource { } update(model: string, body: Record, options?: Core.RequestOptions) { - return this._client.patch(`/models/${model}`, { body, ...options }); + return this._client.post(`/models/${model}/config`, { body, ...options }); } } From 3b90d1443893c048711a00fc60504cafc484d2ca Mon Sep 17 00:00:00 2001 From: James Date: Thu, 20 Jun 2024 15:37:46 +0700 Subject: [PATCH 7/7] adding clean thread api Signed-off-by: James --- src/resources/beta/threads/threads.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/resources/beta/threads/threads.ts b/src/resources/beta/threads/threads.ts index 734cf293..709b5a3a 100644 --- a/src/resources/beta/threads/threads.ts +++ b/src/resources/beta/threads/threads.ts @@ -68,6 +68,13 @@ export class Threads extends APIResource { }); } + /** + * Clean up a thread. + */ + clean(threadId: string, options?: Core.RequestOptions): Core.APIPromise { + return this._client.post(`/threads/${threadId}/clean`); + } + /** * Delete a thread. */