import { OpenAI as OpenAINode, type ClientOptions as ClientOptionsNode } from 'openai'; export type onError = (error: any) => void; export type onOpen = () => void; export type onDone = () => void; export type onEvents = { onError?: onError; onOpen?: onOpen; onDone?: onDone; }; export interface ClientOptions extends ClientOptionsNode { apiKey: string; baseURL: string; } export type onChatCompletionChunkData = (data: ChatCompletionChunk) => void; export type onThreadRunData = (data: Beta.Threads.Run) => void; export type Moderation = OpenAINode.Moderation; export type ModerationCreateResponse = OpenAINode.ModerationCreateResponse; export type ModerationCreateParams = OpenAINode.ModerationCreateParams; export type Model = OpenAINode.Model; export type ChatCompletionCreateParamsNonStreaming = OpenAINode.ChatCompletionCreateParamsNonStreaming; export type ChatCompletionChunk = OpenAINode.ChatCompletionChunk; export type ChatCompletion = OpenAINode.ChatCompletion; export type FileObject = OpenAINode.FileObject; export type FileContent = OpenAINode.FileContent; export type FileDeleted = OpenAINode.FileDeleted; export declare namespace Beta { type ThreadCreateParams = OpenAINode.Beta.ThreadCreateParams; type Thread = OpenAINode.Beta.Thread; type ThreadUpdateParams = OpenAINode.Beta.ThreadUpdateParams; type ThreadCreateAndRunParamsNonStreaming = OpenAINode.Beta.ThreadCreateAndRunParamsNonStreaming; type ThreadDeleted = OpenAINode.Beta.ThreadDeleted; type Assistant = OpenAINode.Beta.Assistant; type AssistantDeleted = OpenAINode.Beta.AssistantDeleted; namespace Assistants { type AssistantCreateParams = OpenAINode.Beta.Assistants.AssistantCreateParams; } namespace Threads { type Run = OpenAINode.Beta.Threads.Run; namespace Runs { type RunCreateParamsNonStreaming = OpenAINode.Beta.Threads.Runs.RunCreateParamsNonStreaming; } type Message = OpenAINode.Beta.Threads.Message; namespace Messages { type MessageCreateParams = OpenAINode.Beta.Threads.Messages.MessageCreateParams; type MessageListParams = OpenAINode.Beta.Threads.Messages.MessageListParams; type MessageDeleted = OpenAINode.Beta.Threads.Messages.MessageDeleted; } } } export declare class OpenAI { apiKey: string; baseURL: string; private client; constructor(opts: ClientOptions); models: { list: () => Promise; }; moderations: { create: (body: ModerationCreateParams) => Promise; }; beta: { assistants: { list: () => Promise; create: (body: Beta.Assistants.AssistantCreateParams) => Promise; del: (assistantId: string) => Promise; retrieve: (assistantId: string) => Promise; update: (assistantId: string, body: Beta.Assistants.AssistantCreateParams) => Promise; }; threads: { create: (body?: Beta.ThreadCreateParams) => Promise; retrieve: (threadId: string) => Promise; update: (threadId: string, body: Beta.ThreadUpdateParams) => Promise; del: (threadId: string) => Promise; createAndRunPoll: (body: Beta.ThreadCreateAndRunParamsNonStreaming) => Promise; messages: { list: (threadId: string, query?: Beta.Threads.Messages.MessageListParams) => Promise; del: (threadId: string, messageId: string) => Promise; create: (threadId: string, body: Beta.Threads.Messages.MessageCreateParams) => Promise; }; runs: { stream: (threadId: string, body: Beta.Threads.Runs.RunCreateParamsNonStreaming, onData: onThreadRunData, callbacks: onEvents) => void; }; }; }; /** * Create a chat completion using the OpenAI API. * @param {OpenAIParams} params - Parameters for the OpenAI chat completion API. * @returns {void} */ chat: { completions: { /** * Create a chat completion using the OpenAI API. * @body {ChatCompletionCreateParamsNonStreaming} body - Parameters for the OpenAI chat completion API. * @returns {Promise} */ create: (body: ChatCompletionCreateParamsNonStreaming) => Promise; /** * Create a chat completion stream using the OpenAI API. * @param {ChatCompletionCreateParamsNonStreaming} params - Parameters for the OpenAI chat completion API since streaming is assumed. * @param {onChatCompletion} onData - Callback to handle incoming messages. * @param {onEvents} callbacks - Object containing optional callback functions. * @returns {void} */ stream: (params: ChatCompletionCreateParamsNonStreaming, onData: onChatCompletionChunkData, callbacks: onEvents) => void; }; }; files: { /** * Upload file using the Expo FileSystem to the OpenAI API /v1/files endpoints * @param {string} filePath - The path of the file to upload. * @param {string} purpose - The purpose of the data (e.g., "fine-tune"). * @see {@link https://docs.expo.dev/versions/latest/sdk/filesystem/ Expo FileSystem} * @see {@link https://beta.openai.com/docs/api-reference/files OpenAI Files API} * @returns {Promise} */ create: (filePath: string, purpose: string) => Promise; content: (fileId: string) => Promise; delete: (fileId: string) => Promise; retrieve: (fileId: string) => Promise; list: () => Promise; }; /** * Connect to a given OpenAI API endpoint and start streaming. * @param {string} url - The API endpoint to connect to. * @param {OpenAIParams} params - The parameters to send with the API request. * @param {onChatCompletion | onThreadRun} onData - Callback to handle incoming data. * @param {onEvents} callbacks - Object containing callback functions. * @param {onStreamError} [callbacks.onError] - Callback to handle errors. * @param {onStreamOpen} [callbacks.onOpen] - Callback to handle when the connection opens. * @param {onStreamDone} [callbacks.onDone] - Callback to handle when the stream ends. * @private */ private _stream; } export default OpenAI;