@livekit/agents-plugin-openai 0.9.1 → 0.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/llm.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/llm.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { llm, log } from '@livekit/agents';\nimport { randomUUID } from 'node:crypto';\nimport { AzureOpenAI, OpenAI } from 'openai';\nimport sharp from 'sharp';\nimport type {\n CerebrasChatModels,\n ChatModels,\n DeepSeekChatModels,\n GroqChatModels,\n OctoChatModels,\n PerplexityChatModels,\n TelnyxChatModels,\n TogetherChatModels,\n XAIChatModels,\n} from './models.js';\n\nexport interface LLMOptions {\n model: string | ChatModels;\n apiKey?: string;\n baseURL?: string;\n user?: string;\n temperature?: number;\n client?: OpenAI;\n}\n\nconst defaultLLMOptions: LLMOptions = {\n model: 'gpt-4o',\n apiKey: process.env.OPENAI_API_KEY,\n};\n\nconst defaultAzureLLMOptions: LLMOptions = {\n model: 'gpt-4o',\n apiKey: process.env.AZURE_API_KEY,\n};\n\nexport class LLM extends llm.LLM {\n #opts: LLMOptions;\n #client: OpenAI;\n\n /**\n * Create a new instance of OpenAI LLM.\n *\n * @remarks\n * `apiKey` must be set to your OpenAI API key, either using the argument or by setting the\n * `OPENAI_API_KEY` environmental variable.\n */\n constructor(opts: Partial<LLMOptions> = defaultLLMOptions) {\n super();\n\n this.#opts = { ...defaultLLMOptions, ...opts };\n if (this.#opts.apiKey === undefined) {\n throw new Error('OpenAI API key is required, whether as an argument or as $OPENAI_API_KEY');\n }\n\n this.#client =\n this.#opts.client ||\n new OpenAI({\n baseURL: opts.baseURL,\n apiKey: opts.apiKey,\n });\n }\n\n /**\n * Create a new instance of OpenAI LLM with Azure.\n *\n * @remarks\n * This automatically infers the following arguments from their corresponding environment variables if they are not provided:\n * - `apiKey` from `AZURE_OPENAI_API_KEY`\n * - `organization` from `OPENAI_ORG_ID`\n * - `project` from `OPENAI_PROJECT_ID`\n * - `azureAdToken` from `AZURE_OPENAI_AD_TOKEN`\n * - `apiVersion` from `OPENAI_API_VERSION`\n * - `azureEndpoint` from `AZURE_OPENAI_ENDPOINT`\n */\n static withAzure(\n opts: {\n model: string | ChatModels;\n azureEndpoint?: string;\n azureDeployment?: string;\n apiVersion?: string;\n apiKey?: string;\n azureAdToken?: string;\n azureAdTokenProvider?: () => Promise<string>;\n organization?: string;\n project?: string;\n baseURL?: string;\n user?: string;\n temperature?: number;\n } = defaultAzureLLMOptions,\n ): LLM {\n opts = { ...defaultLLMOptions, ...opts };\n if (opts.apiKey === undefined) {\n throw new Error('Azure API key is required, whether as an argument or as $AZURE_API_KEY');\n }\n\n return new LLM({\n temperature: opts.temperature,\n user: opts.user,\n client: new AzureOpenAI(opts),\n });\n }\n\n /**\n * Create a new instance of Cerebras LLM.\n *\n * @remarks\n * `apiKey` must be set to your Cerebras API key, either using the argument or by setting the\n * `CEREBRAS_API_KEY` environmental variable.\n */\n static withCerebras(\n opts: Partial<{\n model: string | CerebrasChatModels;\n apiKey?: string;\n baseURL?: string;\n user?: string;\n temperature?: number;\n client: OpenAI;\n }> = {},\n ): LLM {\n opts.apiKey = opts.apiKey || process.env.CEREBRAS_API_KEY;\n if (opts.apiKey === undefined) {\n throw new Error(\n 'Cerebras API key is required, whether as an argument or as $CEREBRAS_API_KEY',\n );\n }\n\n return new LLM({\n model: 'llama3.1-8b',\n baseURL: 'https://api.cerebras.ai/v1',\n ...opts,\n });\n }\n\n /**\n * Create a new instance of Fireworks LLM.\n *\n * @remarks\n * `apiKey` must be set to your Fireworks API key, either using the argument or by setting the\n * `FIREWORKS_API_KEY` environmental variable.\n */\n static withFireworks(opts: Partial<LLMOptions> = {}): LLM {\n opts.apiKey = opts.apiKey || process.env.FIREWORKS_API_KEY;\n if (opts.apiKey === undefined) {\n throw new Error(\n 'Fireworks API key is required, whether as an argument or as $FIREWORKS_API_KEY',\n );\n }\n\n return new LLM({\n model: 'accounts/fireworks/models/llama-v3p1-70b-instruct',\n baseURL: 'https://api.fireworks.ai/inference/v1',\n ...opts,\n });\n }\n\n /**\n * Create a new instance of xAI LLM.\n *\n * @remarks\n * `apiKey` must be set to your xAI API key, either using the argument or by setting the\n * `XAI_API_KEY` environmental variable.\n */\n static withXAI(\n opts: Partial<{\n model: string | XAIChatModels;\n apiKey?: string;\n baseURL?: string;\n user?: string;\n temperature?: number;\n client: OpenAI;\n }> = {},\n ): LLM {\n opts.apiKey = opts.apiKey || process.env.XAI_API_KEY;\n if (opts.apiKey === undefined) {\n throw new Error('xAI API key is required, whether as an argument or as $XAI_API_KEY');\n }\n\n return new LLM({\n model: 'grok-2-public',\n baseURL: 'https://api.x.ai/v1',\n ...opts,\n });\n }\n\n /**\n * Create a new instance of Groq LLM.\n *\n * @remarks\n * `apiKey` must be set to your Groq API key, either using the argument or by setting the\n * `GROQ_API_KEY` environmental variable.\n */\n static withGroq(\n opts: Partial<{\n model: string | GroqChatModels;\n apiKey?: string;\n baseURL?: string;\n user?: string;\n temperature?: number;\n client: OpenAI;\n }> = {},\n ): LLM {\n opts.apiKey = opts.apiKey || process.env.GROQ_API_KEY;\n if (opts.apiKey === undefined) {\n throw new Error('Groq API key is required, whether as an argument or as $GROQ_API_KEY');\n }\n\n return new LLM({\n model: 'llama3-8b-8192',\n baseURL: 'https://api.groq.com/openai/v1',\n ...opts,\n });\n }\n\n /**\n * Create a new instance of DeepSeek LLM.\n *\n * @remarks\n * `apiKey` must be set to your DeepSeek API key, either using the argument or by setting the\n * `DEEPSEEK_API_KEY` environmental variable.\n */\n static withDeepSeek(\n opts: Partial<{\n model: string | DeepSeekChatModels;\n apiKey?: string;\n baseURL?: string;\n user?: string;\n temperature?: number;\n client: OpenAI;\n }> = {},\n ): LLM {\n opts.apiKey = opts.apiKey || process.env.DEEPSEEK_API_KEY;\n if (opts.apiKey === undefined) {\n throw new Error(\n 'DeepSeek API key is required, whether as an argument or as $DEEPSEEK_API_KEY',\n );\n }\n\n return new LLM({\n model: 'deepseek-chat',\n baseURL: 'https://api.deepseek.com/v1',\n ...opts,\n });\n }\n\n /**\n * Create a new instance of OctoAI LLM.\n *\n * @remarks\n * `apiKey` must be set to your OctoAI API key, either using the argument or by setting the\n * `OCTOAI_TOKEN` environmental variable.\n */\n static withOcto(\n opts: Partial<{\n model: string | OctoChatModels;\n apiKey?: string;\n baseURL?: string;\n user?: string;\n temperature?: number;\n client: OpenAI;\n }> = {},\n ): LLM {\n opts.apiKey = opts.apiKey || process.env.OCTOAI_TOKEN;\n if (opts.apiKey === undefined) {\n throw new Error('OctoAI API key is required, whether as an argument or as $OCTOAI_TOKEN');\n }\n\n return new LLM({\n model: 'llama-2-13b-chat',\n baseURL: 'https://text.octoai.run/v1',\n ...opts,\n });\n }\n\n /** Create a new instance of Ollama LLM. */\n static withOllama(\n opts: Partial<{\n model: string;\n baseURL?: string;\n temperature?: number;\n client: OpenAI;\n }> = {},\n ): LLM {\n return new LLM({\n model: 'llama-2-13b-chat',\n baseURL: 'https://text.octoai.run/v1',\n apiKey: 'ollama',\n ...opts,\n });\n }\n\n /**\n * Create a new instance of PerplexityAI LLM.\n *\n * @remarks\n * `apiKey` must be set to your PerplexityAI API key, either using the argument or by setting the\n * `PERPLEXITY_API_KEY` environmental variable.\n */\n static withPerplexity(\n opts: Partial<{\n model: string | PerplexityChatModels;\n apiKey?: string;\n baseURL?: string;\n user?: string;\n temperature?: number;\n client: OpenAI;\n }> = {},\n ): LLM {\n opts.apiKey = opts.apiKey || process.env.PERPLEXITY_API_KEY;\n if (opts.apiKey === undefined) {\n throw new Error(\n 'PerplexityAI API key is required, whether as an argument or as $PERPLEXITY_API_KEY',\n );\n }\n\n return new LLM({\n model: 'llama-3.1-sonar-small-128k-chat',\n baseURL: 'https://api.perplexity.ai',\n ...opts,\n });\n }\n\n /**\n * Create a new instance of TogetherAI LLM.\n *\n * @remarks\n * `apiKey` must be set to your TogetherAI API key, either using the argument or by setting the\n * `TOGETHER_API_KEY` environmental variable.\n */\n static withTogether(\n opts: Partial<{\n model: string | TogetherChatModels;\n apiKey?: string;\n baseURL?: string;\n user?: string;\n temperature?: number;\n client: OpenAI;\n }> = {},\n ): LLM {\n opts.apiKey = opts.apiKey || process.env.TOGETHER_API_KEY;\n if (opts.apiKey === undefined) {\n throw new Error(\n 'TogetherAI API key is required, whether as an argument or as $TOGETHER_API_KEY',\n );\n }\n\n return new LLM({\n model: 'meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo',\n baseURL: 'https://api.together.xyz/v1',\n ...opts,\n });\n }\n\n /**\n * Create a new instance of Telnyx LLM.\n *\n * @remarks\n * `apiKey` must be set to your Telnyx API key, either using the argument or by setting the\n * `TELNYX_API_KEY` environmental variable.\n */\n static withTelnyx(\n opts: Partial<{\n model: string | TelnyxChatModels;\n apiKey?: string;\n baseURL?: string;\n user?: string;\n temperature?: number;\n client: OpenAI;\n }> = {},\n ): LLM {\n opts.apiKey = opts.apiKey || process.env.TELNYX_API_KEY;\n if (opts.apiKey === undefined) {\n throw new Error('Telnyx API key is required, whether as an argument or as $TELNYX_API_KEY');\n }\n\n return new LLM({\n model: 'meta-llama/Meta-Llama-3.1-70B-Instruct',\n baseURL: 'https://api.telnyx.com/v2/ai',\n ...opts,\n });\n }\n\n chat({\n chatCtx,\n fncCtx,\n temperature,\n n,\n parallelToolCalls,\n }: {\n chatCtx: llm.ChatContext;\n fncCtx?: llm.FunctionContext | undefined;\n temperature?: number | undefined;\n n?: number | undefined;\n parallelToolCalls?: boolean | undefined;\n }): LLMStream {\n temperature = temperature || this.#opts.temperature;\n\n return new LLMStream(\n this,\n this.#client,\n chatCtx,\n fncCtx,\n this.#opts,\n parallelToolCalls,\n temperature,\n n,\n );\n }\n}\n\nexport class LLMStream extends llm.LLMStream {\n #toolCallId?: string;\n #fncName?: string;\n #fncRawArguments?: string;\n #client: OpenAI;\n #logger = log();\n #id = randomUUID();\n label = 'openai.LLMStream';\n\n constructor(\n llm: LLM,\n client: OpenAI,\n chatCtx: llm.ChatContext,\n fncCtx: llm.FunctionContext | undefined,\n opts: LLMOptions,\n parallelToolCalls?: boolean,\n temperature?: number,\n n?: number,\n ) {\n super(llm, chatCtx, fncCtx);\n this.#client = client;\n this.#run(opts, n, parallelToolCalls, temperature);\n }\n\n async #run(opts: LLMOptions, n?: number, parallelToolCalls?: boolean, temperature?: number) {\n const tools = this.fncCtx\n ? Object.entries(this.fncCtx).map(([name, func]) => ({\n type: 'function' as const,\n function: {\n name,\n description: func.description,\n // don't format parameters if they are raw openai params\n parameters:\n func.parameters.type == ('object' as const)\n ? func.parameters\n : llm.oaiParams(func.parameters),\n },\n }))\n : undefined;\n\n try {\n const stream = await this.#client.chat.completions.create({\n model: opts.model,\n user: opts.user,\n n,\n messages: await Promise.all(\n this.chatCtx.messages.map(async (m) => await buildMessage(m, this.#id)),\n ),\n temperature: temperature || opts.temperature,\n stream_options: { include_usage: true },\n stream: true,\n tools,\n parallel_tool_calls: this.fncCtx && parallelToolCalls,\n });\n\n for await (const chunk of stream) {\n for (const choice of chunk.choices) {\n const chatChunk = this.#parseChoice(chunk.id, choice);\n if (chatChunk) {\n this.queue.put(chatChunk);\n }\n\n if (chunk.usage) {\n const usage = chunk.usage;\n this.queue.put({\n requestId: chunk.id,\n choices: [],\n usage: {\n completionTokens: usage.completion_tokens,\n promptTokens: usage.prompt_tokens,\n totalTokens: usage.total_tokens,\n },\n });\n }\n }\n }\n } finally {\n this.queue.close();\n }\n }\n\n #parseChoice(id: string, choice: OpenAI.ChatCompletionChunk.Choice): llm.ChatChunk | undefined {\n const delta = choice.delta;\n\n if (delta.tool_calls) {\n // check if we have functions to calls\n for (const tool of delta.tool_calls) {\n if (!tool.function) {\n continue; // oai may add other tools in the future\n }\n\n let callChunk: llm.ChatChunk | undefined;\n if (this.#toolCallId && tool.id && tool.id !== this.#toolCallId) {\n callChunk = this.#tryBuildFunction(id, choice);\n }\n\n if (tool.function.name) {\n this.#toolCallId = tool.id;\n this.#fncName = tool.function.name;\n this.#fncRawArguments = tool.function.arguments || '';\n } else if (tool.function.arguments) {\n this.#fncRawArguments += tool.function.arguments;\n }\n\n if (callChunk) {\n return callChunk;\n }\n }\n }\n\n if (\n choice.finish_reason &&\n ['tool_calls', 'stop'].includes(choice.finish_reason) &&\n this.#toolCallId\n ) {\n // we're done with the tool calls, run the last one\n return this.#tryBuildFunction(id, choice);\n }\n\n return {\n requestId: id,\n choices: [\n {\n delta: { content: delta.content || undefined, role: llm.ChatRole.ASSISTANT },\n index: choice.index,\n },\n ],\n };\n }\n\n #tryBuildFunction(\n id: string,\n choice: OpenAI.ChatCompletionChunk.Choice,\n ): llm.ChatChunk | undefined {\n if (!this.fncCtx) {\n this.#logger.warn('oai stream tried to run function without function context');\n return undefined;\n }\n\n if (!this.#toolCallId) {\n this.#logger.warn('oai stream tried to run function but toolCallId is not set');\n return undefined;\n }\n\n if (!this.#fncRawArguments || !this.#fncName) {\n this.#logger.warn('oai stream tried to run function but rawArguments or fncName are not set');\n return undefined;\n }\n\n const functionInfo = llm.oaiBuildFunctionInfo(\n this.fncCtx,\n this.#toolCallId,\n this.#fncName,\n this.#fncRawArguments,\n );\n this.#toolCallId = this.#fncName = this.#fncRawArguments = undefined;\n this._functionCalls.push(functionInfo);\n\n return {\n requestId: id,\n choices: [\n {\n delta: {\n content: choice.delta.content || undefined,\n role: llm.ChatRole.ASSISTANT,\n toolCalls: this._functionCalls,\n },\n index: choice.index,\n },\n ],\n };\n }\n}\n\nconst buildMessage = async (msg: llm.ChatMessage, cacheKey: any) => {\n const oaiMsg: Partial<OpenAI.ChatCompletionMessageParam> = {};\n\n switch (msg.role) {\n case llm.ChatRole.SYSTEM:\n oaiMsg.role = 'system';\n break;\n case llm.ChatRole.USER:\n oaiMsg.role = 'user';\n break;\n case llm.ChatRole.ASSISTANT:\n oaiMsg.role = 'assistant';\n break;\n case llm.ChatRole.TOOL:\n oaiMsg.role = 'tool';\n if (oaiMsg.role === 'tool') {\n oaiMsg.tool_call_id = msg.toolCallId;\n }\n break;\n }\n\n if (typeof msg.content === 'string') {\n oaiMsg.content = msg.content;\n } else if (Array.isArray(msg.content)) {\n oaiMsg.content = (await Promise.all(\n msg.content.map(async (c) => {\n if (typeof c === 'string') {\n return { type: 'text', text: c };\n } else if (\n // typescript type guard for determining ChatAudio vs ChatImage\n ((c: llm.ChatAudio | llm.ChatImage): c is llm.ChatImage => {\n return (c as llm.ChatImage).image !== undefined;\n })(c)\n ) {\n return await buildImageContent(c, cacheKey);\n } else {\n throw new Error('ChatAudio is not supported');\n }\n }),\n )) as OpenAI.ChatCompletionContentPart[];\n } else if (msg.content === undefined) {\n oaiMsg.content = '';\n }\n\n // make sure to provide when function has been called inside the context\n // (+ raw_arguments)\n if (msg.toolCalls && oaiMsg.role === 'assistant') {\n oaiMsg.tool_calls = Object.entries(msg.toolCalls).map(([name, func]) => ({\n id: func.toolCallId,\n type: 'function' as const,\n function: {\n name: name,\n arguments: func.rawParams,\n },\n }));\n }\n\n return oaiMsg as OpenAI.ChatCompletionMessageParam;\n};\n\nconst buildImageContent = async (image: llm.ChatImage, cacheKey: any) => {\n if (typeof image.image === 'string') {\n // image url\n return {\n type: 'image_url',\n image_url: {\n url: image.image,\n detail: 'auto',\n },\n };\n } else {\n if (!image.cache[cacheKey]) {\n // inside our internal implementation, we allow to put extra metadata to\n // each ChatImage (avoid to reencode each time we do a chatcompletion request)\n let encoded = sharp(image.image.data);\n\n if (image.inferenceHeight && image.inferenceHeight) {\n encoded = encoded.resize(image.inferenceWidth, image.inferenceHeight);\n }\n\n image.cache[cacheKey] = await encoded\n .jpeg()\n .toBuffer()\n .then((buffer) => buffer.toString('utf-8'));\n }\n\n return {\n type: 'image_url',\n image_url: {\n url: `data:image/jpeg;base64,${image.cache[cacheKey]}`,\n },\n };\n }\n};\n"],"mappings":"AAGA,SAAS,KAAK,WAAW;AACzB,SAAS,kBAAkB;AAC3B,SAAS,aAA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A,MACN,WAAW;AAAA,QACT,KAAK,MAAM;AAAA,QACX,QAAQ;AAAA,MACV;AAAA,IACF;AAAA,EACF,OAAO;AACL,QAAI,CAAC,MAAM,MAAM,QAAQ,GAAG;AAG1B,UAAI,UAAU,MAAM,MAAM,MAAM,IAAI;AAEpC,UAAI,MAAM,mBAAmB,MAAM,iBAAiB;AAClD,kBAAU,QAAQ,OAAO,MAAM,gBAAgB,MAAM,eAAe;AAAA,MACtE;AAEA,YAAM,MAAM,QAAQ,IAAI,MAAM,QAC3B,KAAK,EACL,SAAS,EACT,KAAK,CAAC,WAAW,OAAO,SAAS,OAAO,CAAC;AAAA,IAC9C;AAEA,WAAO;AAAA,MACL,MAAM;AAAA,MACN,WAAW;AAAA,QACT,KAAK,0BAA0B,MAAM,MAAM,QAAQ,CAAC;AAAA,MACtD;AAAA,IACF;AAAA,EACF;AACF;","names":["llm","c"]}
1
+ {"version":3,"sources":["../src/llm.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { llm, log } from '@livekit/agents';\nimport { randomUUID } from 'node:crypto';\nimport { AzureOpenAI, OpenAI } from 'openai';\nimport sharp from 'sharp';\nimport type {\n CerebrasChatModels,\n ChatModels,\n DeepSeekChatModels,\n GroqChatModels,\n MetaChatModels,\n OctoChatModels,\n PerplexityChatModels,\n TelnyxChatModels,\n TogetherChatModels,\n XAIChatModels,\n} from './models.js';\n\nexport interface LLMOptions {\n model: string | ChatModels;\n apiKey?: string;\n baseURL?: string;\n user?: string;\n temperature?: number;\n client?: OpenAI;\n}\n\nconst defaultLLMOptions: LLMOptions = {\n model: 'gpt-4o',\n apiKey: process.env.OPENAI_API_KEY,\n};\n\nconst defaultAzureLLMOptions: LLMOptions = {\n model: 'gpt-4o',\n apiKey: process.env.AZURE_API_KEY,\n};\n\nexport class LLM extends llm.LLM {\n #opts: LLMOptions;\n #client: OpenAI;\n\n /**\n * Create a new instance of OpenAI LLM.\n *\n * @remarks\n * `apiKey` must be set to your OpenAI API key, either using the argument or by setting the\n * `OPENAI_API_KEY` environmental variable.\n */\n constructor(opts: Partial<LLMOptions> = defaultLLMOptions) {\n super();\n\n this.#opts = { ...defaultLLMOptions, ...opts };\n if (this.#opts.apiKey === undefined) {\n throw new Error('OpenAI API key is required, whether as an argument or as $OPENAI_API_KEY');\n }\n\n this.#client =\n this.#opts.client ||\n new OpenAI({\n baseURL: opts.baseURL,\n apiKey: opts.apiKey,\n });\n }\n\n /**\n * Create a new instance of OpenAI LLM with Azure.\n *\n * @remarks\n * This automatically infers the following arguments from their corresponding environment variables if they are not provided:\n * - `apiKey` from `AZURE_OPENAI_API_KEY`\n * - `organization` from `OPENAI_ORG_ID`\n * - `project` from `OPENAI_PROJECT_ID`\n * - `azureAdToken` from `AZURE_OPENAI_AD_TOKEN`\n * - `apiVersion` from `OPENAI_API_VERSION`\n * - `azureEndpoint` from `AZURE_OPENAI_ENDPOINT`\n */\n static withAzure(\n opts: {\n model: string | ChatModels;\n azureEndpoint?: string;\n azureDeployment?: string;\n apiVersion?: string;\n apiKey?: string;\n azureAdToken?: string;\n azureAdTokenProvider?: () => Promise<string>;\n organization?: string;\n project?: string;\n baseURL?: string;\n user?: string;\n temperature?: number;\n } = defaultAzureLLMOptions,\n ): LLM {\n opts = { ...defaultLLMOptions, ...opts };\n if (opts.apiKey === undefined) {\n throw new Error('Azure API key is required, whether as an argument or as $AZURE_API_KEY');\n }\n\n return new LLM({\n temperature: opts.temperature,\n user: opts.user,\n client: new AzureOpenAI(opts),\n });\n }\n\n /**\n * Create a new instance of Cerebras LLM.\n *\n * @remarks\n * `apiKey` must be set to your Cerebras API key, either using the argument or by setting the\n * `CEREBRAS_API_KEY` environmental variable.\n */\n static withCerebras(\n opts: Partial<{\n model: string | CerebrasChatModels;\n apiKey?: string;\n baseURL?: string;\n user?: string;\n temperature?: number;\n client: OpenAI;\n }> = {},\n ): LLM {\n opts.apiKey = opts.apiKey || process.env.CEREBRAS_API_KEY;\n if (opts.apiKey === undefined) {\n throw new Error(\n 'Cerebras API key is required, whether as an argument or as $CEREBRAS_API_KEY',\n );\n }\n\n return new LLM({\n model: 'llama3.1-8b',\n baseURL: 'https://api.cerebras.ai/v1',\n ...opts,\n });\n }\n\n /**\n * Create a new instance of Fireworks LLM.\n *\n * @remarks\n * `apiKey` must be set to your Fireworks API key, either using the argument or by setting the\n * `FIREWORKS_API_KEY` environmental variable.\n */\n static withFireworks(opts: Partial<LLMOptions> = {}): LLM {\n opts.apiKey = opts.apiKey || process.env.FIREWORKS_API_KEY;\n if (opts.apiKey === undefined) {\n throw new Error(\n 'Fireworks API key is required, whether as an argument or as $FIREWORKS_API_KEY',\n );\n }\n\n return new LLM({\n model: 'accounts/fireworks/models/llama-v3p1-70b-instruct',\n baseURL: 'https://api.fireworks.ai/inference/v1',\n ...opts,\n });\n }\n\n /**\n * Create a new instance of xAI LLM.\n *\n * @remarks\n * `apiKey` must be set to your xAI API key, either using the argument or by setting the\n * `XAI_API_KEY` environmental variable.\n */\n static withXAI(\n opts: Partial<{\n model: string | XAIChatModels;\n apiKey?: string;\n baseURL?: string;\n user?: string;\n temperature?: number;\n client: OpenAI;\n }> = {},\n ): LLM {\n opts.apiKey = opts.apiKey || process.env.XAI_API_KEY;\n if (opts.apiKey === undefined) {\n throw new Error('xAI API key is required, whether as an argument or as $XAI_API_KEY');\n }\n\n return new LLM({\n model: 'grok-2-public',\n baseURL: 'https://api.x.ai/v1',\n ...opts,\n });\n }\n\n /**\n * Create a new instance of Groq LLM.\n *\n * @remarks\n * `apiKey` must be set to your Groq API key, either using the argument or by setting the\n * `GROQ_API_KEY` environmental variable.\n */\n static withGroq(\n opts: Partial<{\n model: string | GroqChatModels;\n apiKey?: string;\n baseURL?: string;\n user?: string;\n temperature?: number;\n client: OpenAI;\n }> = {},\n ): LLM {\n opts.apiKey = opts.apiKey || process.env.GROQ_API_KEY;\n if (opts.apiKey === undefined) {\n throw new Error('Groq API key is required, whether as an argument or as $GROQ_API_KEY');\n }\n\n return new LLM({\n model: 'llama3-8b-8192',\n baseURL: 'https://api.groq.com/openai/v1',\n ...opts,\n });\n }\n\n /**\n * Create a new instance of DeepSeek LLM.\n *\n * @remarks\n * `apiKey` must be set to your DeepSeek API key, either using the argument or by setting the\n * `DEEPSEEK_API_KEY` environmental variable.\n */\n static withDeepSeek(\n opts: Partial<{\n model: string | DeepSeekChatModels;\n apiKey?: string;\n baseURL?: string;\n user?: string;\n temperature?: number;\n client: OpenAI;\n }> = {},\n ): LLM {\n opts.apiKey = opts.apiKey || process.env.DEEPSEEK_API_KEY;\n if (opts.apiKey === undefined) {\n throw new Error(\n 'DeepSeek API key is required, whether as an argument or as $DEEPSEEK_API_KEY',\n );\n }\n\n return new LLM({\n model: 'deepseek-chat',\n baseURL: 'https://api.deepseek.com/v1',\n ...opts,\n });\n }\n\n /**\n * Create a new instance of OctoAI LLM.\n *\n * @remarks\n * `apiKey` must be set to your OctoAI API key, either using the argument or by setting the\n * `OCTOAI_TOKEN` environmental variable.\n */\n static withOcto(\n opts: Partial<{\n model: string | OctoChatModels;\n apiKey?: string;\n baseURL?: string;\n user?: string;\n temperature?: number;\n client: OpenAI;\n }> = {},\n ): LLM {\n opts.apiKey = opts.apiKey || process.env.OCTOAI_TOKEN;\n if (opts.apiKey === undefined) {\n throw new Error('OctoAI API key is required, whether as an argument or as $OCTOAI_TOKEN');\n }\n\n return new LLM({\n model: 'llama-2-13b-chat',\n baseURL: 'https://text.octoai.run/v1',\n ...opts,\n });\n }\n\n /** Create a new instance of Ollama LLM. */\n static withOllama(\n opts: Partial<{\n model: string;\n baseURL?: string;\n temperature?: number;\n client: OpenAI;\n }> = {},\n ): LLM {\n return new LLM({\n model: 'llama-2-13b-chat',\n baseURL: 'https://text.octoai.run/v1',\n apiKey: 'ollama',\n ...opts,\n });\n }\n\n /**\n * Create a new instance of PerplexityAI LLM.\n *\n * @remarks\n * `apiKey` must be set to your PerplexityAI API key, either using the argument or by setting the\n * `PERPLEXITY_API_KEY` environmental variable.\n */\n static withPerplexity(\n opts: Partial<{\n model: string | PerplexityChatModels;\n apiKey?: string;\n baseURL?: string;\n user?: string;\n temperature?: number;\n client: OpenAI;\n }> = {},\n ): LLM {\n opts.apiKey = opts.apiKey || process.env.PERPLEXITY_API_KEY;\n if (opts.apiKey === undefined) {\n throw new Error(\n 'PerplexityAI API key is required, whether as an argument or as $PERPLEXITY_API_KEY',\n );\n }\n\n return new LLM({\n model: 'llama-3.1-sonar-small-128k-chat',\n baseURL: 'https://api.perplexity.ai',\n ...opts,\n });\n }\n\n /**\n * Create a new instance of TogetherAI LLM.\n *\n * @remarks\n * `apiKey` must be set to your TogetherAI API key, either using the argument or by setting the\n * `TOGETHER_API_KEY` environmental variable.\n */\n static withTogether(\n opts: Partial<{\n model: string | TogetherChatModels;\n apiKey?: string;\n baseURL?: string;\n user?: string;\n temperature?: number;\n client: OpenAI;\n }> = {},\n ): LLM {\n opts.apiKey = opts.apiKey || process.env.TOGETHER_API_KEY;\n if (opts.apiKey === undefined) {\n throw new Error(\n 'TogetherAI API key is required, whether as an argument or as $TOGETHER_API_KEY',\n );\n }\n\n return new LLM({\n model: 'meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo',\n baseURL: 'https://api.together.xyz/v1',\n ...opts,\n });\n }\n\n /**\n * Create a new instance of Telnyx LLM.\n *\n * @remarks\n * `apiKey` must be set to your Telnyx API key, either using the argument or by setting the\n * `TELNYX_API_KEY` environmental variable.\n */\n static withTelnyx(\n opts: Partial<{\n model: string | TelnyxChatModels;\n apiKey?: string;\n baseURL?: string;\n user?: string;\n temperature?: number;\n client: OpenAI;\n }> = {},\n ): LLM {\n opts.apiKey = opts.apiKey || process.env.TELNYX_API_KEY;\n if (opts.apiKey === undefined) {\n throw new Error('Telnyx API key is required, whether as an argument or as $TELNYX_API_KEY');\n }\n\n return new LLM({\n model: 'meta-llama/Meta-Llama-3.1-70B-Instruct',\n baseURL: 'https://api.telnyx.com/v2/ai',\n ...opts,\n });\n }\n\n /**\n * Create a new instance of Meta Llama LLM.\n *\n * @remarks\n * `apiKey` must be set to your Meta Llama API key, either using the argument or by setting the\n * `LLAMA_API_KEY` environmental variable.\n */\n static withMeta(\n opts: Partial<{\n apiKey?: string;\n baseURL?: string;\n client?: OpenAI;\n model?: string | MetaChatModels;\n temperature?: number;\n user?: string;\n }> = {},\n ): LLM {\n opts.apiKey = opts.apiKey || process.env.LLAMA_API_KEY;\n opts.baseURL = opts.baseURL || 'https://api.llama.com/compat/v1/';\n opts.model = opts.model || 'Llama-4-Maverick-17B-128E-Instruct-FP8';\n\n if (opts.apiKey === undefined) {\n throw new Error(\n 'Meta Llama API key is required, either as argument or set LLAMA_API_KEY environmental variable',\n );\n }\n\n return new LLM(opts);\n }\n\n chat({\n chatCtx,\n fncCtx,\n temperature,\n n,\n parallelToolCalls,\n }: {\n chatCtx: llm.ChatContext;\n fncCtx?: llm.FunctionContext | undefined;\n temperature?: number | undefined;\n n?: number | undefined;\n parallelToolCalls?: boolean | undefined;\n }): LLMStream {\n temperature = temperature || this.#opts.temperature;\n\n return new LLMStream(\n this,\n this.#client,\n chatCtx,\n fncCtx,\n this.#opts,\n parallelToolCalls,\n temperature,\n n,\n );\n }\n}\n\nexport class LLMStream extends llm.LLMStream {\n #toolCallId?: string;\n #fncName?: string;\n #fncRawArguments?: string;\n #client: OpenAI;\n #logger = log();\n #id = randomUUID();\n label = 'openai.LLMStream';\n\n constructor(\n llm: LLM,\n client: OpenAI,\n chatCtx: llm.ChatContext,\n fncCtx: llm.FunctionContext | undefined,\n opts: LLMOptions,\n parallelToolCalls?: boolean,\n temperature?: number,\n n?: number,\n ) {\n super(llm, chatCtx, fncCtx);\n this.#client = client;\n this.#run(opts, n, parallelToolCalls, temperature);\n }\n\n async #run(opts: LLMOptions, n?: number, parallelToolCalls?: boolean, temperature?: number) {\n const tools = this.fncCtx\n ? Object.entries(this.fncCtx).map(([name, func]) => ({\n type: 'function' as const,\n function: {\n name,\n description: func.description,\n // don't format parameters if they are raw openai params\n parameters:\n func.parameters.type == ('object' as const)\n ? func.parameters\n : llm.oaiParams(func.parameters),\n },\n }))\n : undefined;\n\n try {\n const stream = await this.#client.chat.completions.create({\n model: opts.model,\n user: opts.user,\n n,\n messages: await Promise.all(\n this.chatCtx.messages.map(async (m) => await buildMessage(m, this.#id)),\n ),\n temperature: temperature || opts.temperature,\n stream_options: { include_usage: true },\n stream: true,\n tools,\n parallel_tool_calls: this.fncCtx && parallelToolCalls,\n });\n\n for await (const chunk of stream) {\n for (const choice of chunk.choices) {\n const chatChunk = this.#parseChoice(chunk.id, choice);\n if (chatChunk) {\n this.queue.put(chatChunk);\n }\n\n if (chunk.usage) {\n const usage = chunk.usage;\n this.queue.put({\n requestId: chunk.id,\n choices: [],\n usage: {\n completionTokens: usage.completion_tokens,\n promptTokens: usage.prompt_tokens,\n totalTokens: usage.total_tokens,\n },\n });\n }\n }\n }\n } finally {\n this.queue.close();\n }\n }\n\n #parseChoice(id: string, choice: OpenAI.ChatCompletionChunk.Choice): llm.ChatChunk | undefined {\n const delta = choice.delta;\n\n if (delta.tool_calls) {\n // check if we have functions to calls\n for (const tool of delta.tool_calls) {\n if (!tool.function) {\n continue; // oai may add other tools in the future\n }\n\n let callChunk: llm.ChatChunk | undefined;\n if (this.#toolCallId && tool.id && tool.id !== this.#toolCallId) {\n callChunk = this.#tryBuildFunction(id, choice);\n }\n\n if (tool.function.name) {\n this.#toolCallId = tool.id;\n this.#fncName = tool.function.name;\n this.#fncRawArguments = tool.function.arguments || '';\n } else if (tool.function.arguments) {\n this.#fncRawArguments += tool.function.arguments;\n }\n\n if (callChunk) {\n return callChunk;\n }\n }\n }\n\n if (\n choice.finish_reason &&\n ['tool_calls', 'stop'].includes(choice.finish_reason) &&\n this.#toolCallId\n ) {\n // we're done with the tool calls, run the last one\n return this.#tryBuildFunction(id, choice);\n }\n\n return {\n requestId: id,\n choices: [\n {\n delta: { content: delta.content || undefined, role: llm.ChatRole.ASSISTANT },\n index: choice.index,\n },\n ],\n };\n }\n\n #tryBuildFunction(\n id: string,\n choice: OpenAI.ChatCompletionChunk.Choice,\n ): llm.ChatChunk | undefined {\n if (!this.fncCtx) {\n this.#logger.warn('oai stream tried to run function without function context');\n return undefined;\n }\n\n if (!this.#toolCallId) {\n this.#logger.warn('oai stream tried to run function but toolCallId is not set');\n return undefined;\n }\n\n if (!this.#fncRawArguments || !this.#fncName) {\n this.#logger.warn('oai stream tried to run function but rawArguments or fncName are not set');\n return undefined;\n }\n\n const functionInfo = llm.oaiBuildFunctionInfo(\n this.fncCtx,\n this.#toolCallId,\n this.#fncName,\n this.#fncRawArguments,\n );\n this.#toolCallId = this.#fncName = this.#fncRawArguments = undefined;\n this._functionCalls.push(functionInfo);\n\n return {\n requestId: id,\n choices: [\n {\n delta: {\n content: choice.delta.content || undefined,\n role: llm.ChatRole.ASSISTANT,\n toolCalls: this._functionCalls,\n },\n index: choice.index,\n },\n ],\n };\n }\n}\n\nconst buildMessage = async (msg: llm.ChatMessage, cacheKey: any) => {\n const oaiMsg: Partial<OpenAI.ChatCompletionMessageParam> = {};\n\n switch (msg.role) {\n case llm.ChatRole.SYSTEM:\n oaiMsg.role = 'system';\n break;\n case llm.ChatRole.USER:\n oaiMsg.role = 'user';\n break;\n case llm.ChatRole.ASSISTANT:\n oaiMsg.role = 'assistant';\n break;\n case llm.ChatRole.TOOL:\n oaiMsg.role = 'tool';\n if (oaiMsg.role === 'tool') {\n oaiMsg.tool_call_id = msg.toolCallId;\n }\n break;\n }\n\n if (msg.role === llm.ChatRole.TOOL) {\n try {\n const serializedContent =\n typeof msg.content === 'string' ? msg.content : JSON.stringify(msg.content);\n oaiMsg.content = serializedContent;\n } catch (e) {\n throw Error(`Tool call output is not JSON serializable: ${e}`);\n }\n } else {\n if (typeof msg.content === 'string') {\n oaiMsg.content = msg.content;\n } else if (Array.isArray(msg.content)) {\n oaiMsg.content = (await Promise.all(\n msg.content.map(async (c) => {\n if (typeof c === 'string') {\n return { type: 'text', text: c };\n } else if (\n // typescript type guard for determining ChatAudio vs ChatImage\n ((c: llm.ChatAudio | llm.ChatImage): c is llm.ChatImage => {\n return (c as llm.ChatImage).image !== undefined;\n })(c)\n ) {\n return await buildImageContent(c, cacheKey);\n } else {\n throw new Error('ChatAudio is not supported');\n }\n }),\n )) as OpenAI.ChatCompletionContentPart[];\n } else if (msg.content === undefined) {\n oaiMsg.content = '';\n }\n }\n\n // make sure to provide when function has been called inside the context\n // (+ raw_arguments)\n if (msg.toolCalls && oaiMsg.role === 'assistant') {\n oaiMsg.tool_calls = Object.entries(msg.toolCalls).map(([name, func]) => ({\n id: func.toolCallId,\n type: 'function' as const,\n function: {\n name: name,\n arguments: func.rawParams,\n },\n }));\n }\n\n return oaiMsg as OpenAI.ChatCompletionMessageParam;\n};\n\nconst buildImageContent = async (image: llm.ChatImage, cacheKey: any) => {\n if (typeof image.image === 'string') {\n // image url\n return {\n type: 'image_url',\n image_url: {\n url: image.image,\n detail: 'auto',\n },\n };\n } else {\n if (!image.cache[cacheKey]) {\n // inside our internal implementation, we allow to put extra metadata to\n // each ChatImage (avoid to reencode each time we do a chatcompletion request)\n let encoded = sharp(image.image.data);\n\n if (image.inferenceHeight && image.inferenceHeight) {\n encoded = encoded.resize(image.inferenceWidth, image.inferenceHeight);\n }\n\n image.cache[cacheKey] = await encoded\n .jpeg()\n .toBuffer()\n .then((buffer) => buffer.toString('utf-8'));\n }\n\n return {\n type: 'image_url',\n image_url: {\n url: `data:image/jpeg;base64,${image.cache[cacheKey]}`,\n },\n };\n }\n};\n"],"mappings":"AAGA,SAAS,KAAK,WAAW;AACzB,SAAS,kBAAkB;AAC3B,SAAS,aAAa,cAAc;AACpC,OAAO,WAAW;AAuBlB,MAAM,oBAAgC;AAAA,EACpC,OAAO;AAAA,EACP,QAAQ,QAAQ,IAAI;AACtB;AAEA,MAAM,yBAAqC;AAAA,EACzC,OAAO;AAAA,EACP,QAAQ,QAAQ,IAAI;AACtB;AAEO,M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IAAI,aAAa,OAAO,SAAS,aAAa;AAChD,WAAO,aAAa,OAAO,QAAQ,IAAI,SAAS,EAAE,IAAI,CAAC,CAAC,MAAM,IAAI,OAAO;AAAA,MACvE,IAAI,KAAK;AAAA,MACT,MAAM;AAAA,MACN,UAAU;AAAA,QACR;AAAA,QACA,WAAW,KAAK;AAAA,MAClB;AAAA,IACF,EAAE;AAAA,EACJ;AAEA,SAAO;AACT;AAEA,MAAM,oBAAoB,OAAO,OAAsB,aAAkB;AACvE,MAAI,OAAO,MAAM,UAAU,UAAU;AAEnC,WAAO;AAAA,MACL,MAAM;AAAA,MACN,WAAW;AAAA,QACT,KAAK,MAAM;AAAA,QACX,QAAQ;AAAA,MACV;AAAA,IACF;AAAA,EACF,OAAO;AACL,QAAI,CAAC,MAAM,MAAM,QAAQ,GAAG;AAG1B,UAAI,UAAU,MAAM,MAAM,MAAM,IAAI;AAEpC,UAAI,MAAM,mBAAmB,MAAM,iBAAiB;AAClD,kBAAU,QAAQ,OAAO,MAAM,gBAAgB,MAAM,eAAe;AAAA,MACtE;AAEA,YAAM,MAAM,QAAQ,IAAI,MAAM,QAC3B,KAAK,EACL,SAAS,EACT,KAAK,CAAC,WAAW,OAAO,SAAS,OAAO,CAAC;AAAA,IAC9C;AAEA,WAAO;AAAA,MACL,MAAM;AAAA,MACN,WAAW;AAAA,QACT,KAAK,0BAA0B,MAAM,MAAM,QAAQ,CAAC;AAAA,MACtD;AAAA,IACF;AAAA,EACF;AACF;","names":["llm","c"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=llm.test.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/models.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\n\nexport type ChatModels =\n | 'gpt-4o'\n | 'gpt-4o-2024-05-13'\n | 'gpt-4o-mini'\n | 'gpt-4o-mini-2024-07-18'\n | 'gpt-4-turbo'\n | 'gpt-4-turbo-2024-04-09'\n | 'gpt-4-turbo-preview'\n | 'gpt-4-0125-preview'\n | 'gpt-4-1106-preview'\n | 'gpt-4-vision-preview'\n | 'gpt-4-1106-vision-preview'\n | 'gpt-4'\n | 'gpt-4-0314'\n | 'gpt-4-0613'\n | 'gpt-4-32k'\n | 'gpt-4-32k-0314'\n | 'gpt-4-32k-0613'\n | 'gpt-3.5-turbo'\n | 'gpt-3.5-turbo-16k'\n | 'gpt-3.5-turbo-0301'\n | 'gpt-3.5-turbo-0613'\n | 'gpt-3.5-turbo-1106'\n | 'gpt-3.5-turbo-16k-0613';\n\nexport type WhisperModels = 'whisper-1';\n\nexport type TTSModels = 'tts-1' | 'tts-1-hd' | 'gpt-4o-mini-tts';\n\nexport type TTSVoices =\n | 'alloy'\n | 'ash'\n | 'ballad'\n | 'coral'\n | 'echo'\n | 'fable'\n | 'nova'\n | 'onyx'\n | 'sage'\n | 'shimmer'\n | 'verse';\n\n// adapters for OpenAI-compatible LLMs, TTSs, STTs\n\nexport type TelnyxChatModels =\n | 'meta-llama/Meta-Llama-3.1-8B-Instruct'\n | 'meta-llama/Meta-Llama-3.1-70B-Instruct';\n\nexport type CerebrasChatModels = 'llama3.1-8b' | 'llama3.1-70b';\n\nexport type PerplexityChatModels =\n | 'llama-3.1-sonar-small-128k-online'\n | 'llama-3.1-sonar-small-128k-chat'\n | 'llama-3.1-sonar-large-128k-online'\n | 'llama-3.1-sonar-large-128k-chat'\n | 'llama-3.1-8b-instruct'\n | 'llama-3.1-70b-instruct';\n\nexport type GroqChatModels =\n | 'llama-3.1-405b-reasoning'\n | 'llama-3.1-70b-versatile'\n | 'llama-3.1-8b-instant'\n | 'llama-3.3-70b-versatile'\n | 'llama3-groq-70b-8192-tool-use-preview'\n | 'llama3-groq-8b-8192-tool-use-preview'\n | 'llama-guard-3-8b'\n | 'llama3-70b-8192'\n | 'llama3-8b-8192'\n | 'mixtral-8x7b-32768'\n | 'gemma-7b-it'\n | 'gemma2-9b-it';\n\nexport type GroqAudioModels =\n | 'whisper-large-v3'\n | 'distil-whisper-large-v3-en'\n | 'whisper-large-v3-turbo';\n\nexport type DeepSeekChatModels = 'deepseek-coder' | 'deepseek-chat';\n\nexport type TogetherChatModels =\n | 'garage-bAInd/Platypus2-70B-instruct'\n | 'google/gemma-2-27b-it'\n | 'google/gemma-2-9b-it'\n | 'google/gemma-2b-it'\n | 'google/gemma-7b-it'\n | 'lmsys/vicuna-13b-v1.5'\n | 'lmsys/vicuna-7b-v1.5'\n | 'meta-llama/Llama-2-13b-chat-hf'\n | 'meta-llama/Llama-2-70b-chat-hf'\n | 'meta-llama/Llama-2-7b-chat-hf'\n | 'meta-llama/Llama-3-70b-chat-hf'\n | 'meta-llama/Llama-3-8b-chat-hf'\n | 'meta-llama/Meta-Llama-3-70B-Instruct-Lite'\n | 'meta-llama/Meta-Llama-3-70B-Instruct-Turbo'\n | 'meta-llama/Meta-Llama-3-8B-Instruct-Lite'\n | 'meta-llama/Meta-Llama-3-8B-Instruct-Turbo'\n | 'meta-llama/Meta-Llama-3.1-405B-Instruct-Turbo'\n | 'meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo'\n | 'meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo'\n | 'mistralai/Mistral-7B-Instruct-v0.1'\n | 'mistralai/Mistral-7B-Instruct-v0.2'\n | 'mistralai/Mistral-7B-Instruct-v0.3'\n | 'mistralai/Mixtral-8x22B-Instruct-v0.1'\n | 'mistralai/Mixtral-8x7B-Instruct-v0.1'\n | 'openchat/openchat-3.5-1210'\n | 'snorkelai/Snorkel-Mistral-PairRM-DPO'\n | 'teknium/OpenHermes-2-Mistral-7B'\n | 'teknium/OpenHermes-2p5-Mistral-7B'\n | 'togethercomputer/Llama-2-7B-32K-Instruct'\n | 'togethercomputer/RedPajama-INCITE-7B-Chat'\n | 'togethercomputer/RedPajama-INCITE-Chat-3B-v1'\n | 'togethercomputer/StripedHyena-Nous-7B'\n | 'togethercomputer/alpaca-7b'\n | 'upstage/SOLAR-10.7B-Instruct-v1.0'\n | 'zero-one-ai/Yi-34B-Chat';\n\nexport type OctoChatModels =\n | 'meta-llama-3-70b-instruct'\n | 'meta-llama-3.1-405b-instruct'\n | 'meta-llama-3.1-70b-instruct'\n | 'meta-llama-3.1-8b-instruct'\n | 'mistral-7b-instruct'\n | 'mixtral-8x7b-instruct'\n | 'wizardlm-2-8x22bllamaguard-2-7b';\n\nexport type XAIChatModels = 'grok-2' | 'grok-2-mini' | 'grok-2-mini-public' | 'grok-2-public';\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
1
+ {"version":3,"sources":["../src/models.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\n\nexport type ChatModels =\n | 'gpt-4o'\n | 'gpt-4o-2024-05-13'\n | 'gpt-4o-mini'\n | 'gpt-4o-mini-2024-07-18'\n | 'gpt-4-turbo'\n | 'gpt-4-turbo-2024-04-09'\n | 'gpt-4-turbo-preview'\n | 'gpt-4-0125-preview'\n | 'gpt-4-1106-preview'\n | 'gpt-4-vision-preview'\n | 'gpt-4-1106-vision-preview'\n | 'gpt-4'\n | 'gpt-4-0314'\n | 'gpt-4-0613'\n | 'gpt-4-32k'\n | 'gpt-4-32k-0314'\n | 'gpt-4-32k-0613'\n | 'gpt-3.5-turbo'\n | 'gpt-3.5-turbo-16k'\n | 'gpt-3.5-turbo-0301'\n | 'gpt-3.5-turbo-0613'\n | 'gpt-3.5-turbo-1106'\n | 'gpt-3.5-turbo-16k-0613';\n\nexport type WhisperModels = 'whisper-1';\n\nexport type TTSModels = 'tts-1' | 'tts-1-hd' | 'gpt-4o-mini-tts';\n\nexport type TTSVoices =\n | 'alloy'\n | 'ash'\n | 'ballad'\n | 'coral'\n | 'echo'\n | 'fable'\n | 'nova'\n | 'onyx'\n | 'sage'\n | 'shimmer'\n | 'verse';\n\n// adapters for OpenAI-compatible LLMs, TTSs, STTs\n\nexport type TelnyxChatModels =\n | 'meta-llama/Meta-Llama-3.1-8B-Instruct'\n | 'meta-llama/Meta-Llama-3.1-70B-Instruct';\n\nexport type CerebrasChatModels = 'llama3.1-8b' | 'llama3.1-70b';\n\nexport type PerplexityChatModels =\n | 'llama-3.1-sonar-small-128k-online'\n | 'llama-3.1-sonar-small-128k-chat'\n | 'llama-3.1-sonar-large-128k-online'\n | 'llama-3.1-sonar-large-128k-chat'\n | 'llama-3.1-8b-instruct'\n | 'llama-3.1-70b-instruct';\n\nexport type GroqChatModels =\n | 'llama-3.1-405b-reasoning'\n | 'llama-3.1-70b-versatile'\n | 'llama-3.1-8b-instant'\n | 'llama-3.3-70b-versatile'\n | 'llama3-groq-70b-8192-tool-use-preview'\n | 'llama3-groq-8b-8192-tool-use-preview'\n | 'llama-guard-3-8b'\n | 'llama3-70b-8192'\n | 'llama3-8b-8192'\n | 'mixtral-8x7b-32768'\n | 'gemma-7b-it'\n | 'gemma2-9b-it';\n\nexport type GroqAudioModels =\n | 'whisper-large-v3'\n | 'distil-whisper-large-v3-en'\n | 'whisper-large-v3-turbo';\n\nexport type DeepSeekChatModels = 'deepseek-coder' | 'deepseek-chat';\n\nexport type TogetherChatModels =\n | 'garage-bAInd/Platypus2-70B-instruct'\n | 'google/gemma-2-27b-it'\n | 'google/gemma-2-9b-it'\n | 'google/gemma-2b-it'\n | 'google/gemma-7b-it'\n | 'lmsys/vicuna-13b-v1.5'\n | 'lmsys/vicuna-7b-v1.5'\n | 'meta-llama/Llama-2-13b-chat-hf'\n | 'meta-llama/Llama-2-70b-chat-hf'\n | 'meta-llama/Llama-2-7b-chat-hf'\n | 'meta-llama/Llama-3-70b-chat-hf'\n | 'meta-llama/Llama-3-8b-chat-hf'\n | 'meta-llama/Meta-Llama-3-70B-Instruct-Lite'\n | 'meta-llama/Meta-Llama-3-70B-Instruct-Turbo'\n | 'meta-llama/Meta-Llama-3-8B-Instruct-Lite'\n | 'meta-llama/Meta-Llama-3-8B-Instruct-Turbo'\n | 'meta-llama/Meta-Llama-3.1-405B-Instruct-Turbo'\n | 'meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo'\n | 'meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo'\n | 'mistralai/Mistral-7B-Instruct-v0.1'\n | 'mistralai/Mistral-7B-Instruct-v0.2'\n | 'mistralai/Mistral-7B-Instruct-v0.3'\n | 'mistralai/Mixtral-8x22B-Instruct-v0.1'\n | 'mistralai/Mixtral-8x7B-Instruct-v0.1'\n | 'openchat/openchat-3.5-1210'\n | 'snorkelai/Snorkel-Mistral-PairRM-DPO'\n | 'teknium/OpenHermes-2-Mistral-7B'\n | 'teknium/OpenHermes-2p5-Mistral-7B'\n | 'togethercomputer/Llama-2-7B-32K-Instruct'\n | 'togethercomputer/RedPajama-INCITE-7B-Chat'\n | 'togethercomputer/RedPajama-INCITE-Chat-3B-v1'\n | 'togethercomputer/StripedHyena-Nous-7B'\n | 'togethercomputer/alpaca-7b'\n | 'upstage/SOLAR-10.7B-Instruct-v1.0'\n | 'zero-one-ai/Yi-34B-Chat';\n\nexport type OctoChatModels =\n | 'meta-llama-3-70b-instruct'\n | 'meta-llama-3.1-405b-instruct'\n | 'meta-llama-3.1-70b-instruct'\n | 'meta-llama-3.1-8b-instruct'\n | 'mistral-7b-instruct'\n | 'mixtral-8x7b-instruct'\n | 'wizardlm-2-8x22bllamaguard-2-7b';\n\nexport type XAIChatModels = 'grok-2' | 'grok-2-mini' | 'grok-2-mini-public' | 'grok-2-public';\n\nexport type MetaChatModels =\n | 'Llama-4-Scout-17B-16E-Instruct-FP8'\n | 'Llama-4-Maverick-17B-128E-Instruct-FP8'\n | 'Llama-3.3-70B-Instruct'\n | 'Llama-3.3-8B-Instruct';\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -0,0 +1,15 @@
1
+ export type ChatModels = 'gpt-4o' | 'gpt-4o-2024-05-13' | 'gpt-4o-mini' | 'gpt-4o-mini-2024-07-18' | 'gpt-4-turbo' | 'gpt-4-turbo-2024-04-09' | 'gpt-4-turbo-preview' | 'gpt-4-0125-preview' | 'gpt-4-1106-preview' | 'gpt-4-vision-preview' | 'gpt-4-1106-vision-preview' | 'gpt-4' | 'gpt-4-0314' | 'gpt-4-0613' | 'gpt-4-32k' | 'gpt-4-32k-0314' | 'gpt-4-32k-0613' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-16k' | 'gpt-3.5-turbo-0301' | 'gpt-3.5-turbo-0613' | 'gpt-3.5-turbo-1106' | 'gpt-3.5-turbo-16k-0613';
2
+ export type WhisperModels = 'whisper-1';
3
+ export type TTSModels = 'tts-1' | 'tts-1-hd' | 'gpt-4o-mini-tts';
4
+ export type TTSVoices = 'alloy' | 'ash' | 'ballad' | 'coral' | 'echo' | 'fable' | 'nova' | 'onyx' | 'sage' | 'shimmer' | 'verse';
5
+ export type TelnyxChatModels = 'meta-llama/Meta-Llama-3.1-8B-Instruct' | 'meta-llama/Meta-Llama-3.1-70B-Instruct';
6
+ export type CerebrasChatModels = 'llama3.1-8b' | 'llama3.1-70b';
7
+ export type PerplexityChatModels = 'llama-3.1-sonar-small-128k-online' | 'llama-3.1-sonar-small-128k-chat' | 'llama-3.1-sonar-large-128k-online' | 'llama-3.1-sonar-large-128k-chat' | 'llama-3.1-8b-instruct' | 'llama-3.1-70b-instruct';
8
+ export type GroqChatModels = 'llama-3.1-405b-reasoning' | 'llama-3.1-70b-versatile' | 'llama-3.1-8b-instant' | 'llama-3.3-70b-versatile' | 'llama3-groq-70b-8192-tool-use-preview' | 'llama3-groq-8b-8192-tool-use-preview' | 'llama-guard-3-8b' | 'llama3-70b-8192' | 'llama3-8b-8192' | 'mixtral-8x7b-32768' | 'gemma-7b-it' | 'gemma2-9b-it';
9
+ export type GroqAudioModels = 'whisper-large-v3' | 'distil-whisper-large-v3-en' | 'whisper-large-v3-turbo';
10
+ export type DeepSeekChatModels = 'deepseek-coder' | 'deepseek-chat';
11
+ export type TogetherChatModels = 'garage-bAInd/Platypus2-70B-instruct' | 'google/gemma-2-27b-it' | 'google/gemma-2-9b-it' | 'google/gemma-2b-it' | 'google/gemma-7b-it' | 'lmsys/vicuna-13b-v1.5' | 'lmsys/vicuna-7b-v1.5' | 'meta-llama/Llama-2-13b-chat-hf' | 'meta-llama/Llama-2-70b-chat-hf' | 'meta-llama/Llama-2-7b-chat-hf' | 'meta-llama/Llama-3-70b-chat-hf' | 'meta-llama/Llama-3-8b-chat-hf' | 'meta-llama/Meta-Llama-3-70B-Instruct-Lite' | 'meta-llama/Meta-Llama-3-70B-Instruct-Turbo' | 'meta-llama/Meta-Llama-3-8B-Instruct-Lite' | 'meta-llama/Meta-Llama-3-8B-Instruct-Turbo' | 'meta-llama/Meta-Llama-3.1-405B-Instruct-Turbo' | 'meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo' | 'meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo' | 'mistralai/Mistral-7B-Instruct-v0.1' | 'mistralai/Mistral-7B-Instruct-v0.2' | 'mistralai/Mistral-7B-Instruct-v0.3' | 'mistralai/Mixtral-8x22B-Instruct-v0.1' | 'mistralai/Mixtral-8x7B-Instruct-v0.1' | 'openchat/openchat-3.5-1210' | 'snorkelai/Snorkel-Mistral-PairRM-DPO' | 'teknium/OpenHermes-2-Mistral-7B' | 'teknium/OpenHermes-2p5-Mistral-7B' | 'togethercomputer/Llama-2-7B-32K-Instruct' | 'togethercomputer/RedPajama-INCITE-7B-Chat' | 'togethercomputer/RedPajama-INCITE-Chat-3B-v1' | 'togethercomputer/StripedHyena-Nous-7B' | 'togethercomputer/alpaca-7b' | 'upstage/SOLAR-10.7B-Instruct-v1.0' | 'zero-one-ai/Yi-34B-Chat';
12
+ export type OctoChatModels = 'meta-llama-3-70b-instruct' | 'meta-llama-3.1-405b-instruct' | 'meta-llama-3.1-70b-instruct' | 'meta-llama-3.1-8b-instruct' | 'mistral-7b-instruct' | 'mixtral-8x7b-instruct' | 'wizardlm-2-8x22bllamaguard-2-7b';
13
+ export type XAIChatModels = 'grok-2' | 'grok-2-mini' | 'grok-2-mini-public' | 'grok-2-public';
14
+ export type MetaChatModels = 'Llama-4-Scout-17B-16E-Instruct-FP8' | 'Llama-4-Maverick-17B-128E-Instruct-FP8' | 'Llama-3.3-70B-Instruct' | 'Llama-3.3-8B-Instruct';
15
+ //# sourceMappingURL=models.d.ts.map
package/dist/models.d.ts CHANGED
@@ -11,4 +11,5 @@ export type DeepSeekChatModels = 'deepseek-coder' | 'deepseek-chat';
11
11
  export type TogetherChatModels = 'garage-bAInd/Platypus2-70B-instruct' | 'google/gemma-2-27b-it' | 'google/gemma-2-9b-it' | 'google/gemma-2b-it' | 'google/gemma-7b-it' | 'lmsys/vicuna-13b-v1.5' | 'lmsys/vicuna-7b-v1.5' | 'meta-llama/Llama-2-13b-chat-hf' | 'meta-llama/Llama-2-70b-chat-hf' | 'meta-llama/Llama-2-7b-chat-hf' | 'meta-llama/Llama-3-70b-chat-hf' | 'meta-llama/Llama-3-8b-chat-hf' | 'meta-llama/Meta-Llama-3-70B-Instruct-Lite' | 'meta-llama/Meta-Llama-3-70B-Instruct-Turbo' | 'meta-llama/Meta-Llama-3-8B-Instruct-Lite' | 'meta-llama/Meta-Llama-3-8B-Instruct-Turbo' | 'meta-llama/Meta-Llama-3.1-405B-Instruct-Turbo' | 'meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo' | 'meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo' | 'mistralai/Mistral-7B-Instruct-v0.1' | 'mistralai/Mistral-7B-Instruct-v0.2' | 'mistralai/Mistral-7B-Instruct-v0.3' | 'mistralai/Mixtral-8x22B-Instruct-v0.1' | 'mistralai/Mixtral-8x7B-Instruct-v0.1' | 'openchat/openchat-3.5-1210' | 'snorkelai/Snorkel-Mistral-PairRM-DPO' | 'teknium/OpenHermes-2-Mistral-7B' | 'teknium/OpenHermes-2p5-Mistral-7B' | 'togethercomputer/Llama-2-7B-32K-Instruct' | 'togethercomputer/RedPajama-INCITE-7B-Chat' | 'togethercomputer/RedPajama-INCITE-Chat-3B-v1' | 'togethercomputer/StripedHyena-Nous-7B' | 'togethercomputer/alpaca-7b' | 'upstage/SOLAR-10.7B-Instruct-v1.0' | 'zero-one-ai/Yi-34B-Chat';
12
12
  export type OctoChatModels = 'meta-llama-3-70b-instruct' | 'meta-llama-3.1-405b-instruct' | 'meta-llama-3.1-70b-instruct' | 'meta-llama-3.1-8b-instruct' | 'mistral-7b-instruct' | 'mixtral-8x7b-instruct' | 'wizardlm-2-8x22bllamaguard-2-7b';
13
13
  export type XAIChatModels = 'grok-2' | 'grok-2-mini' | 'grok-2-mini-public' | 'grok-2-public';
14
+ export type MetaChatModels = 'Llama-4-Scout-17B-16E-Instruct-FP8' | 'Llama-4-Maverick-17B-128E-Instruct-FP8' | 'Llama-3.3-70B-Instruct' | 'Llama-3.3-8B-Instruct';
14
15
  //# sourceMappingURL=models.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,UAAU,GAClB,QAAQ,GACR,mBAAmB,GACnB,aAAa,GACb,wBAAwB,GACxB,aAAa,GACb,wBAAwB,GACxB,qBAAqB,GACrB,oBAAoB,GACpB,oBAAoB,GACpB,sBAAsB,GACtB,2BAA2B,GAC3B,OAAO,GACP,YAAY,GACZ,YAAY,GACZ,WAAW,GACX,gBAAgB,GAChB,gBAAgB,GAChB,eAAe,GACf,mBAAmB,GACnB,oBAAoB,GACpB,oBAAoB,GACpB,oBAAoB,GACpB,wBAAwB,CAAC;AAE7B,MAAM,MAAM,aAAa,GAAG,WAAW,CAAC;AAExC,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,UAAU,GAAG,iBAAiB,CAAC;AAEjE,MAAM,MAAM,SAAS,GACjB,OAAO,GACP,KAAK,GACL,QAAQ,GACR,OAAO,GACP,MAAM,GACN,OAAO,GACP,MAAM,GACN,MAAM,GACN,MAAM,G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GACpB,aAAa,GACb,cAAc,CAAC;AAEnB,MAAM,MAAM,eAAe,GACvB,kBAAkB,GAClB,4BAA4B,GAC5B,wBAAwB,CAAC;AAE7B,MAAM,MAAM,kBAAkB,GAAG,gBAAgB,GAAG,eAAe,CAAC;AAEpE,MAAM,MAAM,kBAAkB,GAC1B,qCAAqC,GACrC,uBAAuB,GACvB,sBAAsB,GACtB,oBAAoB,GACpB,oBAAoB,GACpB,uBAAuB,GACvB,sBAAsB,GACtB,gCAAgC,GAChC,gCAAgC,GAChC,+BAA+B,GAC/B,gCAAgC,GAChC,+BAA+B,GAC/B,2CAA2C,GAC3C,4CAA4C,GAC5C,0CAA0C,GAC1C,2CAA2C,GAC3C,+CAA+C,GAC/C,8CAA8C,GAC9C,6CAA6C,GAC7C,oCAAoC,GACpC,oCAAoC,GACpC,oCAAoC,GACpC,uCAAuC,GACvC,sCAAsC,GACtC,4BAA4B,GAC5B,sCAAsC,GACtC,iCAAiC,GACjC,mCAAmC,GACnC,0CAA0C,GAC1C,2CAA2C,GAC3C,8CAA8C,GAC9C,uCAAuC,GACvC,4BAA4B,GAC5B,mCAAmC,GACnC,yBAAyB,CAAC;AAE9B,MAAM,MAAM,cAAc,GACtB,2BAA2B,GAC3B,8BAA8B,GAC9B,6BAA6B,GAC7B,4BAA4B,GAC5B,qBAAqB,GACrB,uBAAuB,GACvB,iCAAiC,CAAC;AAEtC,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG,aAAa,GAAG,oBAAoB,GAAG,eAAe,CAAC;AAE9F,MAAM,MAAM,cAAc,GACtB,oCAAoC,GACpC,wCAAwC,GACxC,wBAAwB,GACxB,uBAAuB,CAAC"}
@@ -0,0 +1,413 @@
1
+ export declare const SAMPLE_RATE = 24000;
2
+ export declare const NUM_CHANNELS = 1;
3
+ export declare const IN_FRAME_SIZE = 2400;
4
+ export declare const OUT_FRAME_SIZE = 1200;
5
+ export declare const BASE_URL = "wss://api.openai.com/v1";
6
+ export type Model = 'gpt-4o-realtime-preview-2024-10-01' | string;
7
+ export type Voice = 'alloy' | 'shimmer' | 'echo' | 'ash' | 'ballad' | 'coral' | 'sage' | 'verse' | string;
8
+ export type AudioFormat = 'pcm16';
9
+ export type Role = 'system' | 'assistant' | 'user' | 'tool';
10
+ export type GenerationFinishedReason = 'stop' | 'max_tokens' | 'content_filter' | 'interrupt';
11
+ export type InputTranscriptionModel = 'whisper-1' | string;
12
+ export type Modality = 'text' | 'audio';
13
+ export type ToolChoice = 'auto' | 'none' | 'required' | string;
14
+ export type State = 'initializing' | 'listening' | 'thinking' | 'speaking' | string;
15
+ export type ResponseStatus = 'in_progress' | 'completed' | 'incomplete' | 'cancelled' | 'failed' | string;
16
+ export type ClientEventType = 'session.update' | 'input_audio_buffer.append' | 'input_audio_buffer.commit' | 'input_audio_buffer.clear' | 'conversation.item.create' | 'conversation.item.truncate' | 'conversation.item.delete' | 'response.create' | 'response.cancel';
17
+ export type ServerEventType = 'error' | 'session.created' | 'session.updated' | 'conversation.created' | 'input_audio_buffer.committed' | 'input_audio_buffer.cleared' | 'input_audio_buffer.speech_started' | 'input_audio_buffer.speech_stopped' | 'conversation.item.created' | 'conversation.item.input_audio_transcription.completed' | 'conversation.item.input_audio_transcription.failed' | 'conversation.item.truncated' | 'conversation.item.deleted' | 'response.created' | 'response.done' | 'response.output_item.added' | 'response.output_item.done' | 'response.content_part.added' | 'response.content_part.done' | 'response.text.delta' | 'response.text.done' | 'response.audio_transcript.delta' | 'response.audio_transcript.done' | 'response.audio.delta' | 'response.audio.done' | 'response.function_call_arguments.delta' | 'response.function_call_arguments.done' | 'rate_limits.updated';
18
+ export type AudioBase64Bytes = string;
19
+ export interface Tool {
20
+ type: 'function';
21
+ name: string;
22
+ description?: string;
23
+ parameters: {
24
+ type: 'object';
25
+ properties: {
26
+ [prop: string]: {
27
+ [prop: string]: any;
28
+ };
29
+ };
30
+ required: string[];
31
+ };
32
+ }
33
+ export type TurnDetectionType = {
34
+ type: 'server_vad';
35
+ threshold?: number;
36
+ prefix_padding_ms?: number;
37
+ silence_duration_ms?: number;
38
+ };
39
+ export type InputAudioTranscription = {
40
+ model: InputTranscriptionModel;
41
+ };
42
+ export interface InputTextContent {
43
+ type: 'input_text';
44
+ text: string;
45
+ }
46
+ export interface InputAudioContent {
47
+ type: 'input_audio';
48
+ audio: AudioBase64Bytes;
49
+ }
50
+ export interface TextContent {
51
+ type: 'text';
52
+ text: string;
53
+ }
54
+ export interface AudioContent {
55
+ type: 'audio';
56
+ audio: AudioBase64Bytes;
57
+ transcript: string;
58
+ }
59
+ export type Content = InputTextContent | InputAudioContent | TextContent | AudioContent;
60
+ export type ContentPart = {
61
+ type: 'text' | 'audio';
62
+ audio?: AudioBase64Bytes;
63
+ transcript?: string;
64
+ };
65
+ export interface BaseItem {
66
+ id: string;
67
+ object: 'realtime.item';
68
+ type: string;
69
+ }
70
+ export interface SystemItem extends BaseItem {
71
+ type: 'message';
72
+ role: 'system';
73
+ content: InputTextContent;
74
+ }
75
+ export interface UserItem extends BaseItem {
76
+ type: 'message';
77
+ role: 'user';
78
+ content: (InputTextContent | InputAudioContent)[];
79
+ }
80
+ export interface AssistantItem extends BaseItem {
81
+ type: 'message';
82
+ role: 'assistant';
83
+ content: (TextContent | AudioContent)[];
84
+ }
85
+ export interface FunctionCallItem extends BaseItem {
86
+ type: 'function_call';
87
+ call_id: string;
88
+ name: string;
89
+ arguments: string;
90
+ }
91
+ export interface FunctionCallOutputItem extends BaseItem {
92
+ type: 'function_call_output';
93
+ call_id: string;
94
+ output: string;
95
+ }
96
+ export type ItemResource = SystemItem | UserItem | AssistantItem | FunctionCallItem | FunctionCallOutputItem;
97
+ export interface SessionResource {
98
+ id: string;
99
+ object: 'realtime.session';
100
+ model: string;
101
+ modalities: ['text', 'audio'] | ['text'];
102
+ instructions: string;
103
+ voice: Voice;
104
+ input_audio_format: AudioFormat;
105
+ output_audio_format: AudioFormat;
106
+ input_audio_transcription: InputAudioTranscription | null;
107
+ turn_detection: TurnDetectionType | null;
108
+ tools: Tool[];
109
+ tool_choice: ToolChoice;
110
+ temperature: number;
111
+ max_response_output_tokens: number | 'inf';
112
+ expires_at: number;
113
+ }
114
+ export interface ConversationResource {
115
+ id: string;
116
+ object: 'realtime.conversation';
117
+ }
118
+ export type ResponseStatusDetails = {
119
+ type: 'incomplete';
120
+ reason: 'max_output_tokens' | 'content_filter' | string;
121
+ } | {
122
+ type: 'failed';
123
+ error?: {
124
+ code: 'server_error' | 'rate_limit_exceeded' | string;
125
+ message: string;
126
+ };
127
+ } | {
128
+ type: 'cancelled';
129
+ reason: 'turn_detected' | 'client_cancelled' | string;
130
+ };
131
+ export interface ModelUsage {
132
+ total_tokens: number;
133
+ input_tokens: number;
134
+ output_tokens: number;
135
+ input_token_details: {
136
+ text_tokens: number;
137
+ audio_tokens: number;
138
+ cached_tokens: number;
139
+ cached_tokens_details: {
140
+ text_tokens: number;
141
+ audio_tokens: number;
142
+ };
143
+ };
144
+ output_token_details: {
145
+ text_tokens: number;
146
+ audio_tokens: number;
147
+ };
148
+ }
149
+ export interface ResponseResource {
150
+ id: string;
151
+ object: 'realtime.response';
152
+ status: ResponseStatus;
153
+ status_details: ResponseStatusDetails;
154
+ output: ItemResource[];
155
+ usage?: ModelUsage;
156
+ }
157
+ interface BaseClientEvent {
158
+ event_id?: string;
159
+ type: ClientEventType;
160
+ }
161
+ export interface SessionUpdateEvent extends BaseClientEvent {
162
+ type: 'session.update';
163
+ session: Partial<{
164
+ modalities: ['text', 'audio'] | ['text'];
165
+ instructions: string;
166
+ voice: Voice;
167
+ input_audio_format: AudioFormat;
168
+ output_audio_format: AudioFormat;
169
+ input_audio_transcription: InputAudioTranscription | null;
170
+ turn_detection: TurnDetectionType | null;
171
+ tools: Tool[];
172
+ tool_choice: ToolChoice;
173
+ temperature: number;
174
+ max_response_output_tokens?: number | 'inf';
175
+ }>;
176
+ }
177
+ export interface InputAudioBufferAppendEvent extends BaseClientEvent {
178
+ type: 'input_audio_buffer.append';
179
+ audio: AudioBase64Bytes;
180
+ }
181
+ export interface InputAudioBufferCommitEvent extends BaseClientEvent {
182
+ type: 'input_audio_buffer.commit';
183
+ }
184
+ export interface InputAudioBufferClearEvent extends BaseClientEvent {
185
+ type: 'input_audio_buffer.clear';
186
+ }
187
+ export interface UserItemCreate {
188
+ type: 'message';
189
+ role: 'user';
190
+ content: (InputTextContent | InputAudioContent)[];
191
+ }
192
+ export interface AssistantItemCreate {
193
+ type: 'message';
194
+ role: 'assistant';
195
+ content: TextContent[];
196
+ }
197
+ export interface SystemItemCreate {
198
+ type: 'message';
199
+ role: 'system';
200
+ content: InputTextContent[];
201
+ }
202
+ export interface FunctionCallOutputItemCreate {
203
+ type: 'function_call_output';
204
+ call_id: string;
205
+ output: string;
206
+ }
207
+ export type ConversationItemCreateContent = UserItemCreate | AssistantItemCreate | SystemItemCreate | FunctionCallOutputItemCreate;
208
+ export interface ConversationItemCreateEvent extends BaseClientEvent {
209
+ type: 'conversation.item.create';
210
+ previous_item_id?: string;
211
+ item: ConversationItemCreateContent;
212
+ }
213
+ export interface ConversationItemTruncateEvent extends BaseClientEvent {
214
+ type: 'conversation.item.truncate';
215
+ item_id: string;
216
+ content_index: number;
217
+ audio_end_ms: number;
218
+ }
219
+ export interface ConversationItemDeleteEvent extends BaseClientEvent {
220
+ type: 'conversation.item.delete';
221
+ item_id: string;
222
+ }
223
+ export interface ResponseCreateEvent extends BaseClientEvent {
224
+ type: 'response.create';
225
+ response?: Partial<{
226
+ modalities: ['text', 'audio'] | ['text'];
227
+ instructions: string;
228
+ voice: Voice;
229
+ output_audio_format: AudioFormat;
230
+ tools?: Tool[];
231
+ tool_choice: ToolChoice;
232
+ temperature: number;
233
+ max_output_tokens: number | 'inf';
234
+ }>;
235
+ }
236
+ export interface ResponseCancelEvent extends BaseClientEvent {
237
+ type: 'response.cancel';
238
+ }
239
+ export type ClientEvent = SessionUpdateEvent | InputAudioBufferAppendEvent | InputAudioBufferCommitEvent | InputAudioBufferClearEvent | ConversationItemCreateEvent | ConversationItemTruncateEvent | ConversationItemDeleteEvent | ResponseCreateEvent | ResponseCancelEvent;
240
+ interface BaseServerEvent {
241
+ event_id: string;
242
+ type: ServerEventType;
243
+ }
244
+ export interface ErrorEvent extends BaseServerEvent {
245
+ type: 'error';
246
+ error: {
247
+ type: 'invalid_request_error' | 'server_error' | string;
248
+ code?: string;
249
+ message: string;
250
+ param: string;
251
+ event_id: string;
252
+ };
253
+ }
254
+ export interface SessionCreatedEvent extends BaseServerEvent {
255
+ type: 'session.created';
256
+ session: SessionResource;
257
+ }
258
+ export interface SessionUpdatedEvent extends BaseServerEvent {
259
+ type: 'session.updated';
260
+ session: SessionResource;
261
+ }
262
+ export interface ConversationCreatedEvent extends BaseServerEvent {
263
+ type: 'conversation.created';
264
+ conversation: ConversationResource;
265
+ }
266
+ export interface InputAudioBufferCommittedEvent extends BaseServerEvent {
267
+ type: 'input_audio_buffer.committed';
268
+ item_id: string;
269
+ }
270
+ export interface InputAudioBufferClearedEvent extends BaseServerEvent {
271
+ type: 'input_audio_buffer.cleared';
272
+ }
273
+ export interface InputAudioBufferSpeechStartedEvent extends BaseServerEvent {
274
+ type: 'input_audio_buffer.speech_started';
275
+ audio_start_ms: number;
276
+ item_id: string;
277
+ }
278
+ export interface InputAudioBufferSpeechStoppedEvent extends BaseServerEvent {
279
+ type: 'input_audio_buffer.speech_stopped';
280
+ audio_end_ms: number;
281
+ item_id: string;
282
+ }
283
+ export interface ConversationItemCreatedEvent extends BaseServerEvent {
284
+ type: 'conversation.item.created';
285
+ item: ItemResource;
286
+ }
287
+ export interface ConversationItemInputAudioTranscriptionCompletedEvent extends BaseServerEvent {
288
+ type: 'conversation.item.input_audio_transcription.completed';
289
+ item_id: string;
290
+ content_index: number;
291
+ transcript: string;
292
+ }
293
+ export interface ConversationItemInputAudioTranscriptionFailedEvent extends BaseServerEvent {
294
+ type: 'conversation.item.input_audio_transcription.failed';
295
+ item_id: string;
296
+ content_index: number;
297
+ error: {
298
+ type: string;
299
+ code?: string;
300
+ message: string;
301
+ param: null;
302
+ };
303
+ }
304
+ export interface ConversationItemTruncatedEvent extends BaseServerEvent {
305
+ type: 'conversation.item.truncated';
306
+ item_id: string;
307
+ content_index: number;
308
+ audio_end_ms: number;
309
+ }
310
+ export interface ConversationItemDeletedEvent extends BaseServerEvent {
311
+ type: 'conversation.item.deleted';
312
+ item_id: string;
313
+ }
314
+ export interface ResponseCreatedEvent extends BaseServerEvent {
315
+ type: 'response.created';
316
+ response: ResponseResource;
317
+ }
318
+ export interface ResponseDoneEvent extends BaseServerEvent {
319
+ type: 'response.done';
320
+ response: ResponseResource;
321
+ }
322
+ export interface ResponseOutputItemAddedEvent extends BaseServerEvent {
323
+ type: 'response.output_item.added';
324
+ response_id: string;
325
+ output_index: number;
326
+ item: ItemResource;
327
+ }
328
+ export interface ResponseOutputItemDoneEvent extends BaseServerEvent {
329
+ type: 'response.output_item.done';
330
+ response_id: string;
331
+ output_index: number;
332
+ item: ItemResource;
333
+ }
334
+ export interface ResponseContentPartAddedEvent extends BaseServerEvent {
335
+ type: 'response.content_part.added';
336
+ response_id: string;
337
+ item_id: string;
338
+ output_index: number;
339
+ content_index: number;
340
+ part: ContentPart;
341
+ }
342
+ export interface ResponseContentPartDoneEvent extends BaseServerEvent {
343
+ type: 'response.content_part.done';
344
+ response_id: string;
345
+ output_index: number;
346
+ content_index: number;
347
+ part: ContentPart;
348
+ }
349
+ export interface ResponseTextDeltaEvent extends BaseServerEvent {
350
+ type: 'response.text.delta';
351
+ response_id: string;
352
+ output_index: number;
353
+ content_index: number;
354
+ delta: string;
355
+ }
356
+ export interface ResponseTextDoneEvent extends BaseServerEvent {
357
+ type: 'response.text.done';
358
+ response_id: string;
359
+ output_index: number;
360
+ content_index: number;
361
+ text: string;
362
+ }
363
+ export interface ResponseAudioTranscriptDeltaEvent extends BaseServerEvent {
364
+ type: 'response.audio_transcript.delta';
365
+ response_id: string;
366
+ output_index: number;
367
+ content_index: number;
368
+ delta: string;
369
+ }
370
+ export interface ResponseAudioTranscriptDoneEvent extends BaseServerEvent {
371
+ type: 'response.audio_transcript.done';
372
+ response_id: string;
373
+ output_index: number;
374
+ content_index: number;
375
+ transcript: string;
376
+ }
377
+ export interface ResponseAudioDeltaEvent extends BaseServerEvent {
378
+ type: 'response.audio.delta';
379
+ response_id: string;
380
+ output_index: number;
381
+ content_index: number;
382
+ delta: AudioBase64Bytes;
383
+ }
384
+ export interface ResponseAudioDoneEvent extends BaseServerEvent {
385
+ type: 'response.audio.done';
386
+ response_id: string;
387
+ output_index: number;
388
+ content_index: number;
389
+ }
390
+ export interface ResponseFunctionCallArgumentsDeltaEvent extends BaseServerEvent {
391
+ type: 'response.function_call_arguments.delta';
392
+ response_id: string;
393
+ output_index: number;
394
+ delta: string;
395
+ }
396
+ export interface ResponseFunctionCallArgumentsDoneEvent extends BaseServerEvent {
397
+ type: 'response.function_call_arguments.done';
398
+ response_id: string;
399
+ output_index: number;
400
+ arguments: string;
401
+ }
402
+ export interface RateLimitsUpdatedEvent extends BaseServerEvent {
403
+ type: 'rate_limits.updated';
404
+ rate_limits: {
405
+ name: 'requests' | 'tokens' | 'input_tokens' | 'output_tokens' | string;
406
+ limit: number;
407
+ remaining: number;
408
+ reset_seconds: number;
409
+ }[];
410
+ }
411
+ export type ServerEvent = ErrorEvent | SessionCreatedEvent | SessionUpdatedEvent | ConversationCreatedEvent | InputAudioBufferCommittedEvent | InputAudioBufferClearedEvent | InputAudioBufferSpeechStartedEvent | InputAudioBufferSpeechStoppedEvent | ConversationItemCreatedEvent | ConversationItemInputAudioTranscriptionCompletedEvent | ConversationItemInputAudioTranscriptionFailedEvent | ConversationItemTruncatedEvent | ConversationItemDeletedEvent | ResponseCreatedEvent | ResponseDoneEvent | ResponseOutputItemAddedEvent | ResponseOutputItemDoneEvent | ResponseContentPartAddedEvent | ResponseContentPartDoneEvent | ResponseTextDeltaEvent | ResponseTextDoneEvent | ResponseAudioTranscriptDeltaEvent | ResponseAudioTranscriptDoneEvent | ResponseAudioDeltaEvent | ResponseAudioDoneEvent | ResponseFunctionCallArgumentsDeltaEvent | ResponseFunctionCallArgumentsDoneEvent | RateLimitsUpdatedEvent;
412
+ export {};
413
+ //# sourceMappingURL=api_proto.d.ts.map
@@ -0,0 +1,3 @@
1
+ export * from './api_proto.js';
2
+ export * from './realtime_model.js';
3
+ //# sourceMappingURL=index.d.ts.map