diff --git a/package-lock.json b/package-lock.json index 1eca8fd..61d4201 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "dependencies": { "agentkeepalive": "^4.5.0", "dotenv": "^16.3.1", - "openai": "4.55.3" + "openai": "4.77.0" }, "devDependencies": { "@babel/core": "^7.23.3", @@ -5564,9 +5564,9 @@ } }, "node_modules/openai": { - "version": "4.55.3", - "resolved": "https://registry.npmjs.org/openai/-/openai-4.55.3.tgz", - "integrity": "sha512-/IUDdK5w3aB1Kd88Ml7w5F+EkVM5aXlrY+lSpWXdIPL18CmGkC7lV9HFJ7beR0OUSFLFT0qmWvMynqtbMF06/Q==", + "version": "4.77.0", + "resolved": "https://registry.npmjs.org/openai/-/openai-4.77.0.tgz", + "integrity": "sha512-WWacavtns/7pCUkOWvQIjyOfcdr9X+9n9Vvb0zFeKVDAqwCMDHB+iSr24SVaBAhplvSG6JrRXFpcNM9gWhOGIw==", "dependencies": { "@types/node": "^18.11.18", "@types/node-fetch": "^2.6.4", diff --git a/package.json b/package.json index 0979868..09fa1cc 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,6 @@ "dependencies": { "agentkeepalive": "^4.5.0", "dotenv": "^16.3.1", - "openai": "4.55.3" + "openai": "4.77.0" } } diff --git a/src/apis/assistants.ts b/src/apis/assistants.ts index efe08cd..a095f57 100644 --- a/src/apis/assistants.ts +++ b/src/apis/assistants.ts @@ -3,6 +3,7 @@ import { ApiResource } from '../apiResource'; import { RequestOptions } from '../baseClient'; import { finalResponse, initOpenAIClient, overrideConfig } from '../utils'; import { createHeaders } from './createHeaders'; +import { AssistantUpdateParams as oaiAssistantUpdateParams } from 'openai/resources/beta/assistants'; export interface AssistantCreateParams { model: string; @@ -46,6 +47,10 @@ export interface AssistantUpdateParams { model?: string; name?: string | null; tools?: Array; + response_format?: any | null; + temperature?: number | null; + tool_resources?: oaiAssistantUpdateParams.ToolResources | null; + top_p?: number | null; [key: string]: any; } diff --git a/src/apis/chatCompletions.ts b/src/apis/chatCompletions.ts index e50a888..55e69f8 100644 --- a/src/apis/chatCompletions.ts +++ b/src/apis/chatCompletions.ts @@ -59,6 +59,13 @@ class ChatCompletions extends ApiResource { export interface ChatCompletionsBodyBase extends ModelParams { messages?: Array; response_format?: object; + audio?: any | null; + modalities?: Array | null; + prediction?: any | null; + reasoning_effort?: any; + store?: boolean | null; + metadata?: Record | null; + max_completion_tokens?: number | null; } export interface ChatCompletionsBodyStreaming extends ChatCompletionsBodyBase { @@ -89,6 +96,7 @@ interface Message { function_call?: any; tool_calls?: Array; tool_call_id?: string; + [key: string]: any; } export interface Logprobs { diff --git a/src/apis/completions.ts b/src/apis/completions.ts index df66f63..458767b 100644 --- a/src/apis/completions.ts +++ b/src/apis/completions.ts @@ -50,8 +50,13 @@ export interface CompletionsBodyBase extends ModelParams { prompt: string; } +export interface ChatCompletionStreamOptions { + include_usage?: boolean; +} + export interface CompletionsBodyStreaming extends CompletionsBodyBase { stream?: true; + stream_options?: ChatCompletionStreamOptions | null; } export interface CompletionsBodyNonStreaming extends CompletionsBodyBase { @@ -66,16 +71,15 @@ interface Usage { prompt_tokens?: number; completion_tokens?: number; total_tokens?: number; + [key: string]: any; } interface Logprobs { text_offset?: Array; - token_logprobs?: Array; - tokens?: Array; - top_logprobs?: Array>; + [key: string]: any; } interface Choices { @@ -83,6 +87,7 @@ interface Choices { text?: string; logprobs: Logprobs; finish_reason?: string; + [key: string]: any; } interface TextCompletion extends APIResponseType { @@ -93,4 +98,5 @@ interface TextCompletion extends APIResponseType { choices: Array; usage?: Usage; system_fingerprint?: string; + [key: string]: any; } diff --git a/src/apis/embeddings.ts b/src/apis/embeddings.ts index de7c1b1..b96daf2 100644 --- a/src/apis/embeddings.ts +++ b/src/apis/embeddings.ts @@ -13,7 +13,26 @@ export interface EmbeddingsBody extends ModelParams { encoding_format?: string; } -export type EmbeddingsResponse = Record & APIResponseType; +export interface EmbeddingArr { + embedding?: Array; + index?: number; + object?: string; + [key: string]: any; +} + +export interface Usage { + prompt_tokens?: number; + total_tokens?: number; + [key: string]: any; +} + +interface EmbeddingsResponse extends APIResponseType { + data?: Array; + model?: string; + object?: string; + usage?: Usage; + [key: string]: any; +} export class Embeddings extends ApiResource { create( diff --git a/src/apis/files.ts b/src/apis/files.ts index c410885..8bae62e 100644 --- a/src/apis/files.ts +++ b/src/apis/files.ts @@ -128,6 +128,37 @@ export class MainFiles extends ApiResource { return finalResponse(result); } + + async waitForProcessing( + id: string, + _body: PollOptions, + params?: ApiClientInterface + ): Promise { + const body: PollOptions = _body; + if (params) { + const config = overrideConfig(this.client.config, params.config); + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params, config }), + }; + } + + const OAIclient = initOpenAIClient(this.client); + + const result = await OAIclient.files.waitForProcessing(id, { + ...(body.pollInterval !== undefined && { + pollInterval: body.pollInterval, + }), + ...(body.maxWait !== undefined && { maxWait: body.maxWait }), + }); + + return result; + } +} + +interface PollOptions { + pollInterval?: number | undefined; + maxWait?: number | undefined; } export interface FileCreateParams { @@ -145,9 +176,11 @@ export interface FileObject { purpose?: string; status?: string; status_details?: string; + [key: string]: any; } export interface FileListParams { purpose?: string; + order?: 'asc' | 'desc'; [key: string]: any; } diff --git a/src/apis/images.ts b/src/apis/images.ts index 8282cc9..99c9f1f 100644 --- a/src/apis/images.ts +++ b/src/apis/images.ts @@ -40,14 +40,15 @@ export interface ImageCreateVariationParams { export interface ImagesResponse { created: number; - data: Array; + [key: string]: any; } export interface Image { b64_json?: string; revised_prompt?: string; url?: string; + [key: string]: any; } export class Images extends ApiResource { diff --git a/src/apis/threads.ts b/src/apis/threads.ts index 768551d..fb6b2ac 100644 --- a/src/apis/threads.ts +++ b/src/apis/threads.ts @@ -3,6 +3,12 @@ import { ApiResource } from '../apiResource'; import { RequestOptions } from '../baseClient'; import { finalResponse, initOpenAIClient, overrideConfig } from '../utils'; import { createHeaders } from './createHeaders'; +import { + ThreadCreateParams as oaiThreadCreateParams, + ThreadUpdateParams as oaiThreadUpdateParams, + ThreadCreateAndRunParams as oaiThreadCreateAndRunParams, + AssistantToolChoiceOption, +} from 'openai/resources/beta/threads/threads'; export class Threads extends ApiResource { messages: Messages; @@ -278,6 +284,29 @@ export class Messages extends ApiResource { return finalResponse(result); } + + async del( + threadId: string, + messageId: string, + params?: ApiClientInterface, + opts?: RequestOptions + ): Promise { + if (params) { + const config = overrideConfig(this.client.config, params.config); + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params, config }), + }; + } + + const OAIclient = initOpenAIClient(this.client); + + const result = await OAIclient.beta.threads.messages + .del(threadId, messageId, opts) + .withResponse(); + + return finalResponse(result); + } } export class Runs extends ApiResource { @@ -654,6 +683,7 @@ export class Steps extends ApiResource { export interface ThreadCreateParams { messages?: Array; metadata?: unknown | null; + tool_resources?: oaiThreadCreateParams.ToolResources | null; [key: string]: any; } @@ -666,6 +696,7 @@ export interface Message { export interface ThreadUpdateParams { metadata?: unknown | null; + tool_resources?: oaiThreadUpdateParams.ToolResources | null; [key: string]: any; } @@ -673,12 +704,16 @@ export interface MessageCreateParams { content: string; role: string; file_ids?: Array; + attachments?: Array | null; metadata?: unknown | null; [key: string]: any; } export interface MessageListParams extends CursorPageParams { order?: string; + before?: string; + run_id?: string; + [key: string]: any; } export interface CursorPageParams { @@ -705,6 +740,17 @@ export interface RunCreateParams { model?: string | null; tools?: Array | null; stream?: boolean | null; + include?: Array; + additional_messages?: Array | null; + max_completion_tokens?: number | null; + max_prompt_tokens?: number | null; + parallel_tool_calls?: boolean; + response_format?: any | null; + temperature?: number | null; + tool_choice?: any | null; + top_p?: number | null; + truncation_strategy?: any | null; + [key: string]: any; } export interface RunCreateParamsNonStreaming extends RunCreateParams { @@ -719,6 +765,16 @@ export interface ThreadCreateAndRunParams { thread?: any; tools?: Array | null; stream?: boolean | null; + max_completion_tokens?: number | null; + max_prompt_tokens?: number | null; + parallel_tool_calls?: boolean; + response_format?: any | null; + temperature?: number | null; + tool_choice?: AssistantToolChoiceOption | null; + tool_resources?: oaiThreadCreateAndRunParams.ToolResources | null; + top_p?: number | null; + truncation_strategy?: oaiThreadCreateAndRunParams.TruncationStrategy | null; + [key: string]: any; } export interface ThreadCreateAndRunParamsNonStreaming @@ -731,6 +787,7 @@ export type ThreadCreateAndRunParamsBaseStream = Omit< 'stream' > & { stream?: true; + assistant_id: string; }; export interface RunListParams extends CursorPageParams { @@ -741,6 +798,8 @@ export interface RunListParams extends CursorPageParams { export interface StepListParams extends CursorPageParams { before?: string; order?: string; + include?: Array; + [key: string]: any; } export interface RunUpdateParams { @@ -760,6 +819,7 @@ export interface ToolOutput { export type RunCreateParamsBaseStream = Omit & { stream?: true; + assistant_id: string; }; export interface RunSubmitToolOutputsParamsNonStreaming diff --git a/src/apis/uploads.ts b/src/apis/uploads.ts index 4fd901b..7ffb079 100644 --- a/src/apis/uploads.ts +++ b/src/apis/uploads.ts @@ -60,11 +60,11 @@ export class Uploads extends ApiResource { async complete( uploadId: string, - _body: any, + _body: UploadCompleteParams, params?: ApiClientInterface, opts?: RequestOptions ): Promise { - const body: any = _body; + const body: UploadCompleteParams = _body; if (params) { const config = overrideConfig(this.client.config, params.config); this.client.customHeaders = { diff --git a/src/apis/vectorStores.ts b/src/apis/vectorStores.ts index 05d0485..cd86188 100644 --- a/src/apis/vectorStores.ts +++ b/src/apis/vectorStores.ts @@ -4,6 +4,7 @@ import { ApiResource } from '../apiResource'; import { RequestOptions } from '../baseClient'; import { finalResponse, initOpenAIClient, overrideConfig } from '../utils'; import { createHeaders } from './createHeaders'; +import { FileChunkingStrategyParam } from 'openai/resources/beta/vector-stores/vector-stores'; export class VectorStores extends ApiResource { files: Files; @@ -86,11 +87,11 @@ export class VectorStores extends ApiResource { } async list( - _query?: VectorStoreListParams, + _query?: VectorStoreListParams | RequestOptions, params?: ApiClientInterface, opts?: RequestOptions ): Promise { - const query: VectorStoreListParams | undefined = _query; + const query: VectorStoreListParams | RequestOptions | undefined = _query; if (params) { const config = overrideConfig(this.client.config, params.config); this.client.customHeaders = { @@ -102,7 +103,7 @@ export class VectorStores extends ApiResource { const OAIclient = initOpenAIClient(this.client); const result = await OAIclient.beta.vectorStores - .list(query, opts) + .list(query as any, opts) .withResponse(); return finalResponse(result); } @@ -428,11 +429,11 @@ export class FileBatches extends ApiResource { async listFiles( vectorStoreId: string, batchId: string, - _query?: FileBatchListFilesParams, + _query?: FileBatchListFilesParams | RequestOptions, params?: ApiClientInterface, opts?: RequestOptions ): Promise { - const query: FileBatchListFilesParams | undefined = _query; + const query: FileBatchListFilesParams | RequestOptions | undefined = _query; if (params) { const config = overrideConfig(this.client.config, params.config); @@ -446,7 +447,7 @@ export class FileBatches extends ApiResource { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore const result = await OAIclient.beta.vectorStores.fileBatches - .listFiles(vectorStoreId, batchId, query, opts) + .listFiles(vectorStoreId, batchId, query as any, opts) .withResponse(); return finalResponse(result); @@ -508,6 +509,7 @@ export interface ExpiresAfter { } export interface VectorStoreCreateParams { + chunking_strategy?: FileChunkingStrategyParam; expires_after?: ExpiresAfter; file_ids?: Array; metadata?: unknown | null; @@ -535,6 +537,7 @@ export interface CursorPageParams { export interface FileCreateParams { file_id: string; + chunking_strategy?: FileChunkingStrategyParam; [key: string]: any; } @@ -547,6 +550,7 @@ export interface FileListParams extends CursorPageParams { export interface FileBatchCreateParams { file_ids: Array; + chunking_strategy?: FileChunkingStrategyParam; [key: string]: any; } diff --git a/src/baseClient.ts b/src/baseClient.ts index dd67916..f69d177 100644 --- a/src/baseClient.ts +++ b/src/baseClient.ts @@ -285,7 +285,7 @@ export abstract class ApiClient { } buildRequest(opts: FinalRequestOptions): { req: RequestInit; url: string } { - const url = new URL(this.baseURL + opts.path!); + const url = new URL(this.baseURL + opts.path); const { method, body } = opts; const reqHeaders: Record = { ...this.defaultHeaders(),