mirror of
https://github.com/run-llama/LlamaIndexTS.git
synced 2026-07-16 07:14:29 -04:00
feat: openai responses api (#1801)
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
---
|
||||
"@llamaindex/openai": minor
|
||||
"@llamaindex/google": patch
|
||||
"@llamaindex/core": patch
|
||||
"@llamaindex/doc": patch
|
||||
"@llamaindex/examples": patch
|
||||
---
|
||||
|
||||
Add support for openai responses api
|
||||
@@ -46,6 +46,156 @@ or
|
||||
Settings.llm = new OpenAI({ model: "gpt-3.5-turbo", temperature: 0, apiKey: <YOUR_API_KEY>, baseURL: "https://api.scaleway.ai/v1" });
|
||||
```
|
||||
|
||||
## Using OpenAI Responses API
|
||||
|
||||
The OpenAI Responses API provides enhanced functionality for handling complex interactions, including built-in tools, annotations, and streaming responses. Here's how to use it:
|
||||
|
||||
### Basic Setup
|
||||
|
||||
```ts
|
||||
import { openaiResponses } from "@llamaindex/openai";
|
||||
|
||||
const llm = openaiResponses({
|
||||
model: "gpt-4o",
|
||||
temperature: 0.1,
|
||||
maxOutputTokens: 1000
|
||||
});
|
||||
```
|
||||
|
||||
### Message Content Types
|
||||
|
||||
The API supports different types of message content, including text and images:
|
||||
|
||||
```ts
|
||||
const response = await llm.chat({
|
||||
messages: [
|
||||
{
|
||||
role: "user",
|
||||
content: [
|
||||
{
|
||||
type: "input_text",
|
||||
text: "What's in this image?"
|
||||
},
|
||||
{
|
||||
type: "input_image",
|
||||
image_url: "https://example.com/image.jpg",
|
||||
detail: "auto" // Optional: can be "auto", "low", or "high"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
});
|
||||
```
|
||||
|
||||
### Advanced Features
|
||||
|
||||
#### Built-in Tools
|
||||
|
||||
```ts
|
||||
const llm = openaiResponses({
|
||||
model: "gpt-4o",
|
||||
builtInTools: [
|
||||
{
|
||||
type: "function",
|
||||
name: "search_files",
|
||||
description: "Search through available files"
|
||||
}
|
||||
],
|
||||
strict: true // Enable strict mode for tool calls
|
||||
});
|
||||
```
|
||||
|
||||
#### Response Tracking and Storage
|
||||
|
||||
```ts
|
||||
const llm = openaiResponses({
|
||||
trackPreviousResponses: true, // Enable response tracking
|
||||
store: true, // Store responses for future reference
|
||||
user: "user-123", // Associate responses with a user
|
||||
callMetadata: { // Add custom metadata
|
||||
sessionId: "session-123",
|
||||
context: "customer-support"
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
#### Streaming Responses
|
||||
|
||||
```ts
|
||||
const response = await llm.chat({
|
||||
messages: [
|
||||
{
|
||||
role: "user",
|
||||
content: "Generate a long response"
|
||||
}
|
||||
],
|
||||
stream: true // Enable streaming
|
||||
});
|
||||
|
||||
for await (const chunk of response) {
|
||||
console.log(chunk.delta); // Process each chunk of the response
|
||||
}
|
||||
```
|
||||
|
||||
### Configuration Options
|
||||
|
||||
The OpenAI Responses API supports various configuration options:
|
||||
|
||||
```ts
|
||||
const llm = openaiResponses({
|
||||
// Model and basic settings
|
||||
model: "gpt-4o",
|
||||
temperature: 0.1,
|
||||
topP: 1,
|
||||
maxOutputTokens: 1000,
|
||||
|
||||
// API configuration
|
||||
apiKey: "your-api-key",
|
||||
baseURL: "custom-endpoint",
|
||||
maxRetries: 10,
|
||||
timeout: 60000,
|
||||
|
||||
// Response handling
|
||||
trackPreviousResponses: false,
|
||||
store: false,
|
||||
strict: false,
|
||||
|
||||
// Additional options
|
||||
instructions: "Custom instructions for the model",
|
||||
truncation: "auto", // Can be "auto", "disabled", or null
|
||||
include: ["citations", "reasoning"] // Specify what to include in responses
|
||||
});
|
||||
```
|
||||
|
||||
### Response Structure
|
||||
|
||||
The API returns responses with rich metadata and optional annotations:
|
||||
|
||||
```ts
|
||||
interface ResponseStructure {
|
||||
message: {
|
||||
content: string;
|
||||
role: "assistant";
|
||||
options: {
|
||||
built_in_tool_calls: Array<ToolCall>;
|
||||
annotations?: Array<Citation | URLCitation | FilePath>;
|
||||
refusal?: string;
|
||||
reasoning?: ReasoningItem;
|
||||
usage?: ResponseUsage;
|
||||
toolCall?: Array<PartialToolCall>;
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Best Practices
|
||||
|
||||
1. Use `trackPreviousResponses` when you need conversation continuity
|
||||
2. Enable `strict` mode when using tools to ensure accurate function calls
|
||||
3. Set appropriate `maxOutputTokens` to control response length
|
||||
4. Use `annotations` to track citations and references in responses
|
||||
5. Implement error handling for potential API failures and retries
|
||||
|
||||
## Using JSON Response Format
|
||||
|
||||
You can configure OpenAI to return responses in JSON format:
|
||||
@@ -73,6 +223,112 @@ Settings.llm = new OpenAI({
|
||||
});
|
||||
```
|
||||
|
||||
## Response Formats
|
||||
|
||||
The OpenAI LLM supports different response formats to structure the output in specific ways. There are two main approaches to formatting responses:
|
||||
|
||||
### 1. JSON Object Format
|
||||
|
||||
The simplest way to get structured JSON responses is using the `json_object` response format:
|
||||
|
||||
```ts
|
||||
Settings.llm = new OpenAI({
|
||||
model: "gpt-4o",
|
||||
temperature: 0,
|
||||
responseFormat: { type: "json_object" }
|
||||
});
|
||||
|
||||
const response = await llm.chat({
|
||||
messages: [
|
||||
{
|
||||
role: "system",
|
||||
content: "You are a helpful assistant that outputs JSON."
|
||||
},
|
||||
{
|
||||
role: "user",
|
||||
content: "Summarize this meeting transcript"
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
// Response will be valid JSON
|
||||
console.log(response.message.content);
|
||||
```
|
||||
|
||||
### 2. Schema Validation with Zod
|
||||
|
||||
For more robust type safety and validation, you can use Zod schemas to define the expected response structure:
|
||||
|
||||
```ts
|
||||
import { z } from "zod";
|
||||
|
||||
// Define the response schema
|
||||
const meetingSchema = z.object({
|
||||
summary: z.string(),
|
||||
participants: z.array(z.string()),
|
||||
actionItems: z.array(z.string()),
|
||||
nextSteps: z.string()
|
||||
});
|
||||
|
||||
// Configure the LLM with the schema
|
||||
Settings.llm = new OpenAI({
|
||||
model: "gpt-4o",
|
||||
temperature: 0,
|
||||
responseFormat: meetingSchema
|
||||
});
|
||||
|
||||
const response = await llm.chat({
|
||||
messages: [
|
||||
{
|
||||
role: "user",
|
||||
content: "Summarize this meeting transcript"
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
// Response will be typed and validated according to the schema
|
||||
const result = response.message.content;
|
||||
console.log(result.summary);
|
||||
console.log(result.actionItems);
|
||||
```
|
||||
|
||||
### Response Format Options
|
||||
|
||||
The response format can be configured in two ways:
|
||||
|
||||
1. At LLM initialization:
|
||||
```ts
|
||||
const llm = new OpenAI({
|
||||
model: "gpt-4o",
|
||||
responseFormat: { type: "json_object" } // or a Zod schema
|
||||
});
|
||||
```
|
||||
|
||||
2. Per request:
|
||||
```ts
|
||||
const response = await llm.chat({
|
||||
messages: [...],
|
||||
responseFormat: { type: "json_object" } // or a Zod schema
|
||||
});
|
||||
```
|
||||
|
||||
The response format options are:
|
||||
|
||||
- `{ type: "json_object" }` - Returns responses as JSON objects
|
||||
- `zodSchema` - A Zod schema that defines and validates the response structure
|
||||
|
||||
### Best Practices
|
||||
|
||||
1. Use JSON object format for simple structured responses
|
||||
2. Use Zod schemas when you need:
|
||||
- Type safety
|
||||
- Response validation
|
||||
- Complex nested structures
|
||||
- Specific field constraints
|
||||
3. Set a low temperature (e.g. 0) when using structured outputs for more reliable formatting
|
||||
4. Include clear instructions in system or user messages about the expected response format
|
||||
5. Handle potential parsing errors when working with JSON responses
|
||||
|
||||
## Load and index documents
|
||||
|
||||
For this example, we will use a single document. In a real-world scenario, you would have multiple documents to index.
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import { openaiResponses } from "@llamaindex/openai";
|
||||
import { wiki } from "@llamaindex/tools";
|
||||
import { agent, tool } from "llamaindex";
|
||||
import { z } from "zod";
|
||||
|
||||
const workflow = agent({
|
||||
tools: [
|
||||
tool({
|
||||
name: "weather",
|
||||
description: "Get the weather",
|
||||
parameters: z.object({
|
||||
location: z.string().describe("The location to get the weather for"),
|
||||
}),
|
||||
execute: ({ location }) => `The weather in ${location} is sunny`,
|
||||
}),
|
||||
wiki(),
|
||||
],
|
||||
llm: openaiResponses({
|
||||
model: "gpt-4o-mini",
|
||||
}),
|
||||
});
|
||||
|
||||
async function main() {
|
||||
const result = await workflow.run(
|
||||
"What is the weather in New York? What's the history of New York from Wikipedia in 3 sentences?",
|
||||
);
|
||||
console.log(result.data);
|
||||
}
|
||||
|
||||
void main();
|
||||
@@ -0,0 +1,33 @@
|
||||
import { openaiResponses } from "@llamaindex/openai";
|
||||
|
||||
async function main() {
|
||||
const llm = openaiResponses({
|
||||
model: "gpt-4o",
|
||||
maxOutputTokens: 1000,
|
||||
apiKey: process.env.MY_OPENAI_API_KEY,
|
||||
});
|
||||
|
||||
const response = await llm.chat({
|
||||
messages: [
|
||||
{
|
||||
role: "user",
|
||||
content: [
|
||||
{
|
||||
type: "text",
|
||||
text: "What's in this image? Describe it in detail.",
|
||||
},
|
||||
{
|
||||
type: "image_url",
|
||||
image_url: {
|
||||
url: "https://storage.googleapis.com/cloud-samples-data/vision/face/faces.jpeg",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
console.log("Single Image Analysis:", response.message.content);
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
@@ -0,0 +1,22 @@
|
||||
import { openaiResponses } from "@llamaindex/openai";
|
||||
|
||||
async function main() {
|
||||
const llm = openaiResponses({
|
||||
model: "gpt-4o-mini",
|
||||
temperature: 0.1,
|
||||
});
|
||||
|
||||
// Basic chat example
|
||||
const response = await llm.chat({
|
||||
messages: [
|
||||
{
|
||||
role: "user",
|
||||
content: "What is the capital of France?",
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
console.log(response.message.content);
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
@@ -0,0 +1,26 @@
|
||||
import { openaiResponses } from "@llamaindex/openai";
|
||||
|
||||
async function main() {
|
||||
const llm = openaiResponses({
|
||||
model: "gpt-4o-mini",
|
||||
temperature: 0.1,
|
||||
});
|
||||
|
||||
const stream = await llm.chat({
|
||||
messages: [
|
||||
{ content: "You want to talk in rhymes.", role: "system" },
|
||||
{
|
||||
content:
|
||||
"How much wood would a woodchuck chuck if a woodchuck could chuck wood?",
|
||||
role: "user",
|
||||
},
|
||||
],
|
||||
stream: true,
|
||||
});
|
||||
|
||||
for await (const chunk of stream) {
|
||||
process.stdout.write(chunk.delta);
|
||||
}
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
@@ -0,0 +1,37 @@
|
||||
import { openaiResponses } from "@llamaindex/openai";
|
||||
import { tool } from "llamaindex";
|
||||
|
||||
import { z } from "zod";
|
||||
async function main() {
|
||||
const weatherTool = tool({
|
||||
name: "weather",
|
||||
description: "Get the weather",
|
||||
parameters: z.object({
|
||||
location: z.string({
|
||||
description: "The location to get the weather for",
|
||||
}),
|
||||
}),
|
||||
execute: ({ location }) => {
|
||||
return `The weather in ${location} is sunny`;
|
||||
},
|
||||
});
|
||||
|
||||
const llm = openaiResponses({
|
||||
model: "gpt-4o-mini",
|
||||
temperature: 0.1,
|
||||
});
|
||||
|
||||
const response = await llm.chat({
|
||||
messages: [
|
||||
{
|
||||
role: "user",
|
||||
content: "What is the weather in New York?",
|
||||
},
|
||||
],
|
||||
tools: [weatherTool],
|
||||
});
|
||||
|
||||
console.log(response.message.options);
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
@@ -0,0 +1,23 @@
|
||||
import { openaiResponses } from "@llamaindex/openai";
|
||||
|
||||
async function main() {
|
||||
const llm = openaiResponses({
|
||||
model: "gpt-4o",
|
||||
temperature: 0.1,
|
||||
builtInTools: [{ type: "web_search_preview" }],
|
||||
});
|
||||
|
||||
// Streaming chat example
|
||||
const response = await llm.chat({
|
||||
messages: [
|
||||
{
|
||||
role: "user",
|
||||
content: "What are the latest developments in AI?",
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
console.log(response.message.content);
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
+2
-1
@@ -35,7 +35,8 @@
|
||||
"prettier-plugin-tailwindcss": "^0.6.11",
|
||||
"turbo": "^2.4.4",
|
||||
"typescript": "^5.7.3",
|
||||
"typescript-eslint": "^8.18.0"
|
||||
"typescript-eslint": "^8.18.0",
|
||||
"vitest": "^3.1.1"
|
||||
},
|
||||
"packageManager": "pnpm@9.12.3",
|
||||
"lint-staged": {
|
||||
|
||||
@@ -2,7 +2,6 @@ import type { Tokenizers } from "@llamaindex/env/tokenizers";
|
||||
import type { JSONSchemaType } from "ajv";
|
||||
import { z } from "zod";
|
||||
import type { JSONObject, JSONValue } from "../global";
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
@@ -55,7 +54,12 @@ export interface LLM<
|
||||
): Promise<CompletionResponse>;
|
||||
}
|
||||
|
||||
export type MessageType = "user" | "assistant" | "system" | "memory";
|
||||
export type MessageType =
|
||||
| "user"
|
||||
| "assistant"
|
||||
| "system"
|
||||
| "memory"
|
||||
| "developer";
|
||||
|
||||
export type TextChatMessage<AdditionalMessageOptions extends object = object> =
|
||||
{
|
||||
@@ -156,6 +160,7 @@ export type MessageContentTextDetail = {
|
||||
export type MessageContentImageDetail = {
|
||||
type: "image_url";
|
||||
image_url: { url: string };
|
||||
detail?: "high" | "low" | "auto";
|
||||
};
|
||||
|
||||
export type MessageContentDetail =
|
||||
|
||||
@@ -181,7 +181,7 @@ export const mapBaseToolToGeminiFunctionDeclaration = (
|
||||
export class GeminiHelper {
|
||||
// Gemini only has user and model roles. Put the rest in user role.
|
||||
public static readonly ROLES_TO_GEMINI: Record<
|
||||
MessageType,
|
||||
Exclude<MessageType, "developer">,
|
||||
GeminiMessageRole
|
||||
> = {
|
||||
user: "user",
|
||||
@@ -285,7 +285,9 @@ export class GeminiHelper {
|
||||
if (message.options && "toolResult" in message.options) {
|
||||
return "function";
|
||||
}
|
||||
return GeminiHelper.ROLES_TO_GEMINI[message.role];
|
||||
return GeminiHelper.ROLES_TO_GEMINI[
|
||||
message.role as Exclude<MessageType, "developer">
|
||||
];
|
||||
}
|
||||
|
||||
public static chatMessageToGemini(
|
||||
|
||||
@@ -27,7 +27,8 @@
|
||||
},
|
||||
"scripts": {
|
||||
"build": "bunchee",
|
||||
"dev": "bunchee --watch"
|
||||
"dev": "bunchee --watch",
|
||||
"test": "vitest"
|
||||
},
|
||||
"devDependencies": {
|
||||
"bunchee": "6.4.0"
|
||||
@@ -35,7 +36,7 @@
|
||||
"dependencies": {
|
||||
"@llamaindex/core": "workspace:*",
|
||||
"@llamaindex/env": "workspace:*",
|
||||
"openai": "^4.86.0",
|
||||
"openai": "^4.90.0",
|
||||
"zod": "^3.24.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,8 @@ import {
|
||||
} from "@llamaindex/core/agent";
|
||||
import { Settings } from "@llamaindex/core/global";
|
||||
import type { ToolCallLLMMessageOptions } from "@llamaindex/core/llms";
|
||||
import { OpenAI, type OpenAIAdditionalChatOptions } from "./llm";
|
||||
import { OpenAI } from "./llm";
|
||||
import type { OpenAIAdditionalChatOptions } from "./utils";
|
||||
|
||||
// This is likely not necessary anymore but leaving it here just in case it's in use elsewhere
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
export * from "./agent";
|
||||
export * from "./embedding";
|
||||
export * from "./llm";
|
||||
export * from "./responses";
|
||||
|
||||
@@ -4,7 +4,6 @@ import {
|
||||
type ChatMessage,
|
||||
type ChatResponse,
|
||||
type ChatResponseChunk,
|
||||
type LLM,
|
||||
type LLMChatParamsNonStreaming,
|
||||
type LLMChatParamsStreaming,
|
||||
type LLMMetadata,
|
||||
@@ -18,7 +17,6 @@ import { getEnv } from "@llamaindex/env";
|
||||
import { Tokenizers } from "@llamaindex/env/tokenizers";
|
||||
import type {
|
||||
AzureClientOptions,
|
||||
AzureOpenAI as AzureOpenAILLM,
|
||||
ClientOptions as OpenAIClientOptions,
|
||||
OpenAI as OpenAILLM,
|
||||
} from "openai";
|
||||
@@ -45,153 +43,15 @@ import {
|
||||
getAzureModel,
|
||||
shouldUseAzure,
|
||||
} from "./azure.js";
|
||||
|
||||
export const GPT4_MODELS = {
|
||||
"chatgpt-4o-latest": {
|
||||
contextWindow: 128000,
|
||||
},
|
||||
"gpt-4.5-preview": { contextWindow: 128000 },
|
||||
"gpt-4.5-preview-2025-02-27": { contextWindow: 128000 },
|
||||
"gpt-4": { contextWindow: 8192 },
|
||||
"gpt-4-32k": { contextWindow: 32768 },
|
||||
"gpt-4-32k-0613": { contextWindow: 32768 },
|
||||
"gpt-4-turbo": { contextWindow: 128000 },
|
||||
"gpt-4-turbo-preview": { contextWindow: 128000 },
|
||||
"gpt-4-1106-preview": { contextWindow: 128000 },
|
||||
"gpt-4-0125-preview": { contextWindow: 128000 },
|
||||
"gpt-4-vision-preview": { contextWindow: 128000 },
|
||||
"gpt-4o": { contextWindow: 128000 },
|
||||
"gpt-4o-2024-05-13": { contextWindow: 128000 },
|
||||
"gpt-4o-mini": { contextWindow: 128000 },
|
||||
"gpt-4o-mini-2024-07-18": { contextWindow: 128000 },
|
||||
"gpt-4o-2024-08-06": { contextWindow: 128000 },
|
||||
"gpt-4o-2024-09-14": { contextWindow: 128000 },
|
||||
"gpt-4o-2024-10-14": { contextWindow: 128000 },
|
||||
"gpt-4-0613": { contextWindow: 128000 },
|
||||
"gpt-4-turbo-2024-04-09": { contextWindow: 128000 },
|
||||
"gpt-4-0314": { contextWindow: 128000 },
|
||||
"gpt-4-32k-0314": { contextWindow: 32768 },
|
||||
"gpt-4o-realtime-preview": {
|
||||
contextWindow: 128000,
|
||||
},
|
||||
"gpt-4o-realtime-preview-2024-10-01": {
|
||||
contextWindow: 128000,
|
||||
},
|
||||
"gpt-4o-audio-preview": {
|
||||
contextWindow: 128000,
|
||||
},
|
||||
"gpt-4o-audio-preview-2024-10-01": {
|
||||
contextWindow: 128000,
|
||||
},
|
||||
"gpt-4o-2024-11-20": {
|
||||
contextWindow: 128000,
|
||||
},
|
||||
"gpt-4o-audio-preview-2024-12-17": {
|
||||
contextWindow: 128000,
|
||||
},
|
||||
"gpt-4o-mini-audio-preview": {
|
||||
contextWindow: 128000,
|
||||
},
|
||||
"gpt-4o-mini-audio-preview-2024-12-17": {
|
||||
contextWindow: 128000,
|
||||
},
|
||||
};
|
||||
|
||||
// NOTE we don't currently support gpt-3.5-turbo-instruct and don't plan to in the near future
|
||||
export const GPT35_MODELS = {
|
||||
"gpt-3.5-turbo": { contextWindow: 16385 },
|
||||
"gpt-3.5-turbo-0613": { contextWindow: 4096 },
|
||||
"gpt-3.5-turbo-16k": { contextWindow: 16385 },
|
||||
"gpt-3.5-turbo-16k-0613": { contextWindow: 16385 },
|
||||
"gpt-3.5-turbo-1106": { contextWindow: 16385 },
|
||||
"gpt-3.5-turbo-0125": { contextWindow: 16385 },
|
||||
"gpt-3.5-turbo-0301": { contextWindow: 16385 },
|
||||
};
|
||||
|
||||
export const O1_MODELS = {
|
||||
"o1-preview": {
|
||||
contextWindow: 128000,
|
||||
},
|
||||
"o1-preview-2024-09-12": {
|
||||
contextWindow: 128000,
|
||||
},
|
||||
"o1-mini": {
|
||||
contextWindow: 128000,
|
||||
},
|
||||
"o1-mini-2024-09-12": {
|
||||
contextWindow: 128000,
|
||||
},
|
||||
o1: {
|
||||
contextWindow: 128000,
|
||||
},
|
||||
"o1-2024-12-17": {
|
||||
contextWindow: 128000,
|
||||
},
|
||||
};
|
||||
|
||||
export const O3_MODELS = {
|
||||
"o3-mini": {
|
||||
contextWindow: 200000,
|
||||
},
|
||||
"o3-mini-2025-01-31": {
|
||||
contextWindow: 200000,
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* We currently support GPT-3.5 and GPT-4 models
|
||||
*/
|
||||
export const ALL_AVAILABLE_OPENAI_MODELS = {
|
||||
...GPT4_MODELS,
|
||||
...GPT35_MODELS,
|
||||
...O1_MODELS,
|
||||
...O3_MODELS,
|
||||
} satisfies Record<ChatModel, { contextWindow: number }>;
|
||||
|
||||
function isFunctionCallingModel(llm: LLM): llm is OpenAI {
|
||||
let model: string;
|
||||
if (llm instanceof OpenAI) {
|
||||
model = llm.model;
|
||||
} else if ("model" in llm && typeof llm.model === "string") {
|
||||
model = llm.model;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
const isChatModel = Object.keys(ALL_AVAILABLE_OPENAI_MODELS).includes(model);
|
||||
const isOld = model.includes("0314") || model.includes("0301");
|
||||
const isO1 = model.startsWith("o1");
|
||||
return isChatModel && !isOld && !isO1;
|
||||
}
|
||||
|
||||
function isReasoningModel(model: ChatModel | string): boolean {
|
||||
const isO1 = model.startsWith("o1");
|
||||
const isO3 = model.startsWith("o3");
|
||||
return isO1 || isO3;
|
||||
}
|
||||
|
||||
function isTemperatureSupported(model: ChatModel | string): boolean {
|
||||
return !model.startsWith("o3");
|
||||
}
|
||||
|
||||
export type OpenAIAdditionalMetadata = object;
|
||||
|
||||
export type OpenAIAdditionalChatOptions = Omit<
|
||||
Partial<OpenAILLM.Chat.ChatCompletionCreateParams>,
|
||||
| "max_tokens"
|
||||
| "messages"
|
||||
| "model"
|
||||
| "temperature"
|
||||
| "reasoning_effort"
|
||||
| "top_p"
|
||||
| "stream"
|
||||
| "tools"
|
||||
| "toolChoice"
|
||||
>;
|
||||
|
||||
type LLMInstance = Pick<
|
||||
AzureOpenAILLM | OpenAILLM,
|
||||
"chat" | "apiKey" | "baseURL"
|
||||
>;
|
||||
import {
|
||||
ALL_AVAILABLE_OPENAI_MODELS,
|
||||
isFunctionCallingModel,
|
||||
isReasoningModel,
|
||||
isTemperatureSupported,
|
||||
type LLMInstance,
|
||||
type OpenAIAdditionalChatOptions,
|
||||
type OpenAIAdditionalMetadata,
|
||||
} from "./utils.js";
|
||||
|
||||
export class OpenAI extends ToolCallLLM<OpenAIAdditionalChatOptions> {
|
||||
model:
|
||||
@@ -230,6 +90,7 @@ export class OpenAI extends ToolCallLLM<OpenAIAdditionalChatOptions> {
|
||||
},
|
||||
) {
|
||||
super();
|
||||
|
||||
this.model = init?.model ?? "gpt-4o";
|
||||
this.temperature = init?.temperature ?? 0.1;
|
||||
this.reasoningEffort = isReasoningModel(this.model)
|
||||
|
||||
@@ -0,0 +1,774 @@
|
||||
import {
|
||||
ToolCallLLM,
|
||||
type BaseTool,
|
||||
type ChatMessage,
|
||||
type ChatResponse,
|
||||
type ChatResponseChunk,
|
||||
type LLMChatParamsNonStreaming,
|
||||
type LLMChatParamsStreaming,
|
||||
type LLMMetadata,
|
||||
type MessageContent,
|
||||
type MessageType,
|
||||
type PartialToolCall,
|
||||
type ToolCallLLMMessageOptions,
|
||||
type ToolCallOptions,
|
||||
type ToolResultOptions,
|
||||
} from "@llamaindex/core/llms";
|
||||
import type { StoredValue } from "@llamaindex/core/schema";
|
||||
import { extractText } from "@llamaindex/core/utils";
|
||||
import { getEnv } from "@llamaindex/env";
|
||||
import {
|
||||
OpenAI as OpenAILLM,
|
||||
type AzureClientOptions,
|
||||
type ClientOptions as OpenAIClientOptions,
|
||||
} from "openai";
|
||||
|
||||
import { wrapEventCaller } from "@llamaindex/core/decorator";
|
||||
import { Tokenizers } from "@llamaindex/env/tokenizers";
|
||||
import {
|
||||
AzureOpenAIWithUserAgent,
|
||||
getAzureConfigFromEnv,
|
||||
getAzureModel,
|
||||
shouldUseAzure,
|
||||
} from "./azure";
|
||||
import {
|
||||
ALL_AVAILABLE_OPENAI_MODELS,
|
||||
isFunctionCallingModel,
|
||||
isReasoningModel,
|
||||
isTemperatureSupported,
|
||||
type LLMInstance,
|
||||
type OpenAIAdditionalMetadata,
|
||||
type OpenAIResponsesChatOptions,
|
||||
type OpenAIResponsesRole,
|
||||
type ResponseMessageContent,
|
||||
type ResponsesAdditionalOptions,
|
||||
type StreamState,
|
||||
} from "./utils";
|
||||
|
||||
export class OpenAIResponses extends ToolCallLLM<OpenAIResponsesChatOptions> {
|
||||
model: string;
|
||||
temperature: number;
|
||||
topP: number;
|
||||
maxOutputTokens?: number | undefined;
|
||||
additionalChatOptions?: OpenAIResponsesChatOptions | undefined;
|
||||
reasoningEffort?: "low" | "medium" | "high" | undefined;
|
||||
apiKey?: string | undefined;
|
||||
baseURL?: string | undefined;
|
||||
maxRetries: number;
|
||||
timeout?: number;
|
||||
additionalSessionOptions?:
|
||||
| undefined
|
||||
| Omit<Partial<OpenAIClientOptions>, "apiKey" | "maxRetries" | "timeout">;
|
||||
lazySession: () => Promise<LLMInstance>;
|
||||
#session: Promise<LLMInstance> | null = null;
|
||||
|
||||
trackPreviousResponses: boolean;
|
||||
store: boolean;
|
||||
user: string;
|
||||
callMetadata: StoredValue;
|
||||
builtInTools: OpenAILLM.Responses.Tool[] | null;
|
||||
strict: boolean;
|
||||
include: OpenAILLM.Responses.ResponseIncludable[] | null;
|
||||
instructions: string;
|
||||
previousResponseId: string | null;
|
||||
truncation: "auto" | "disabled" | null;
|
||||
|
||||
constructor(
|
||||
init?: Omit<Partial<OpenAIResponses>, "session"> & {
|
||||
session?: LLMInstance | undefined;
|
||||
azure?: AzureClientOptions;
|
||||
},
|
||||
) {
|
||||
super();
|
||||
this.model = init?.model ?? "gpt-4o";
|
||||
this.temperature = init?.temperature ?? 0.1;
|
||||
|
||||
this.reasoningEffort = isReasoningModel(this.model)
|
||||
? init?.reasoningEffort
|
||||
: undefined;
|
||||
|
||||
this.topP = init?.topP ?? 1;
|
||||
this.maxOutputTokens = init?.maxOutputTokens ?? undefined;
|
||||
this.maxRetries = init?.maxRetries ?? 10;
|
||||
|
||||
this.timeout = init?.timeout ?? 60 * 1000;
|
||||
|
||||
this.apiKey =
|
||||
init?.session?.apiKey ?? init?.apiKey ?? getEnv("OPENAI_API_KEY");
|
||||
this.baseURL =
|
||||
init?.session?.baseURL ?? init?.baseURL ?? getEnv("OPENAI_BASE_URL");
|
||||
|
||||
this.additionalSessionOptions = init?.additionalSessionOptions;
|
||||
this.additionalChatOptions = init?.additionalChatOptions;
|
||||
|
||||
this.trackPreviousResponses = init?.trackPreviousResponses ?? false;
|
||||
this.builtInTools = init?.builtInTools ?? null;
|
||||
this.store = init?.store ?? false;
|
||||
this.user = init?.user ?? "";
|
||||
this.callMetadata = init?.callMetadata ?? {};
|
||||
this.strict = init?.strict ?? false;
|
||||
this.include = init?.include ?? null;
|
||||
this.instructions = init?.instructions ?? "";
|
||||
this.previousResponseId = init?.previousResponseId ?? null;
|
||||
this.truncation = init?.truncation ?? null;
|
||||
|
||||
if (init?.azure || shouldUseAzure()) {
|
||||
const azureConfig = {
|
||||
...getAzureConfigFromEnv({
|
||||
model: getAzureModel(this.model),
|
||||
}),
|
||||
...init?.azure,
|
||||
};
|
||||
|
||||
this.lazySession = async () =>
|
||||
init?.session ??
|
||||
import("openai").then(({ AzureOpenAI }) => {
|
||||
AzureOpenAI = AzureOpenAIWithUserAgent(AzureOpenAI);
|
||||
|
||||
return new AzureOpenAI({
|
||||
maxRetries: this.maxRetries,
|
||||
timeout: this.timeout!,
|
||||
...this.additionalSessionOptions,
|
||||
...azureConfig,
|
||||
});
|
||||
});
|
||||
} else {
|
||||
this.lazySession = async () =>
|
||||
init?.session ??
|
||||
import("openai").then(({ OpenAI }) => {
|
||||
return new OpenAI({
|
||||
apiKey: this.apiKey,
|
||||
baseURL: this.baseURL,
|
||||
maxRetries: this.maxRetries,
|
||||
timeout: this.timeout!,
|
||||
...this.additionalSessionOptions,
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
get session() {
|
||||
if (!this.#session) {
|
||||
this.#session = this.lazySession();
|
||||
}
|
||||
return this.#session;
|
||||
}
|
||||
|
||||
get supportToolCall() {
|
||||
return isFunctionCallingModel(this);
|
||||
}
|
||||
|
||||
get metadata(): LLMMetadata & OpenAIAdditionalMetadata {
|
||||
const contextWindow =
|
||||
ALL_AVAILABLE_OPENAI_MODELS[
|
||||
this.model as keyof typeof ALL_AVAILABLE_OPENAI_MODELS
|
||||
]?.contextWindow ?? 1024;
|
||||
|
||||
return {
|
||||
model: this.model,
|
||||
temperature: this.temperature,
|
||||
topP: this.topP,
|
||||
maxTokens: this.maxOutputTokens,
|
||||
contextWindow,
|
||||
tokenizer: Tokenizers.CL100K_BASE,
|
||||
structuredOutput: true,
|
||||
};
|
||||
}
|
||||
|
||||
private createInitialMessage(): ChatMessage<ToolCallLLMMessageOptions> {
|
||||
return {
|
||||
role: "assistant",
|
||||
content: "",
|
||||
};
|
||||
}
|
||||
|
||||
private createInitialOptions(): ResponsesAdditionalOptions {
|
||||
return {
|
||||
built_in_tool_calls: [],
|
||||
};
|
||||
}
|
||||
|
||||
private isBuiltInToolCall(
|
||||
item: OpenAILLM.Responses.ResponseOutputItem,
|
||||
): item is
|
||||
| OpenAILLM.Responses.ResponseFileSearchToolCall
|
||||
| OpenAILLM.Responses.ResponseComputerToolCall
|
||||
| OpenAILLM.Responses.ResponseFunctionWebSearch {
|
||||
return ["file_search_call", "computer_call", "web_search_call"].includes(
|
||||
item.type,
|
||||
);
|
||||
}
|
||||
|
||||
private isReasoning(item: OpenAILLM.Responses.ResponseOutputItem) {
|
||||
return item.type === "reasoning";
|
||||
}
|
||||
|
||||
private isMessageBlock(item: OpenAILLM.Responses.ResponseOutputItem) {
|
||||
return item.type === "message";
|
||||
}
|
||||
|
||||
private isFunctionCall(item: OpenAILLM.Responses.ResponseOutputItem) {
|
||||
return item.type === "function_call";
|
||||
}
|
||||
|
||||
private isResponseCreatedEvent(
|
||||
event: OpenAILLM.Responses.ResponseStreamEvent,
|
||||
): event is OpenAILLM.Responses.ResponseCreatedEvent {
|
||||
return event.type === "response.created";
|
||||
}
|
||||
|
||||
private isResponseOutputItemAddedEvent(
|
||||
event: OpenAILLM.Responses.ResponseStreamEvent,
|
||||
): event is OpenAILLM.Responses.ResponseOutputItemAddedEvent {
|
||||
return event.type === "response.output_item.added";
|
||||
}
|
||||
|
||||
private isToolCallEvent(
|
||||
event: OpenAILLM.Responses.ResponseOutputItemAddedEvent,
|
||||
): event is OpenAILLM.Responses.ResponseOutputItemAddedEvent & {
|
||||
item: OpenAILLM.Responses.ResponseFunctionToolCall;
|
||||
} {
|
||||
return event.item.type === "function_call";
|
||||
}
|
||||
|
||||
private isResponseTextDeltaEvent(
|
||||
event: OpenAILLM.Responses.ResponseStreamEvent,
|
||||
): event is OpenAILLM.Responses.ResponseTextDeltaEvent {
|
||||
return event.type === "response.output_text.delta";
|
||||
}
|
||||
|
||||
private isResponseFunctionCallArgumentsDeltaEvent(
|
||||
event: OpenAILLM.Responses.ResponseStreamEvent,
|
||||
): event is OpenAILLM.Responses.ResponseFunctionCallArgumentsDeltaEvent {
|
||||
return event.type === "response.function_call_arguments.delta";
|
||||
}
|
||||
|
||||
private isResponseFunctionCallDoneEvent(
|
||||
event: OpenAILLM.Responses.ResponseStreamEvent,
|
||||
): event is OpenAILLM.Responses.ResponseFunctionCallArgumentsDoneEvent {
|
||||
return event.type === "response.function_call_arguments.done";
|
||||
}
|
||||
|
||||
private isResponseOutputTextAnnotationAddedEvent(
|
||||
event: OpenAILLM.Responses.ResponseStreamEvent,
|
||||
): event is OpenAILLM.Responses.ResponseTextAnnotationDeltaEvent {
|
||||
return event.type === "response.output_text.annotation.added";
|
||||
}
|
||||
|
||||
private isResponseFileSearchCallCompletedEvent(
|
||||
event: OpenAILLM.Responses.ResponseStreamEvent,
|
||||
): event is OpenAILLM.Responses.ResponseFileSearchCallCompletedEvent {
|
||||
return event.type === "response.file_search_call.completed";
|
||||
}
|
||||
|
||||
private isResponseWebSearchCallCompletedEvent(
|
||||
event: OpenAILLM.Responses.ResponseStreamEvent,
|
||||
): event is OpenAILLM.Responses.ResponseWebSearchCallCompletedEvent {
|
||||
return event.type === "response.web_search_call.completed";
|
||||
}
|
||||
|
||||
private isResponseCompletedEvent(
|
||||
event: OpenAILLM.Responses.ResponseStreamEvent,
|
||||
): event is OpenAILLM.Responses.ResponseCompletedEvent {
|
||||
return event.type === "response.completed";
|
||||
}
|
||||
|
||||
private isTextPresent(
|
||||
part:
|
||||
| OpenAILLM.Responses.ResponseOutputText
|
||||
| OpenAILLM.Responses.ResponseOutputRefusal,
|
||||
) {
|
||||
return "text" in part;
|
||||
}
|
||||
|
||||
private isRefusalPresent(
|
||||
part:
|
||||
| OpenAILLM.Responses.ResponseOutputText
|
||||
| OpenAILLM.Responses.ResponseOutputRefusal,
|
||||
) {
|
||||
return "refusal" in part;
|
||||
}
|
||||
|
||||
private isAnnotationPresent(
|
||||
part:
|
||||
| OpenAILLM.Responses.ResponseOutputText
|
||||
| OpenAILLM.Responses.ResponseOutputRefusal,
|
||||
) {
|
||||
return "annotations" in part;
|
||||
}
|
||||
|
||||
private handleResponseOutputMessage(
|
||||
item: OpenAILLM.Responses.ResponseOutputMessage,
|
||||
options: ResponsesAdditionalOptions,
|
||||
): string {
|
||||
let outputContent = "";
|
||||
for (const part of item.content) {
|
||||
if (this.isTextPresent(part)) {
|
||||
outputContent += part.text;
|
||||
}
|
||||
if (this.isAnnotationPresent(part)) {
|
||||
options.annotations = part.annotations;
|
||||
}
|
||||
if (this.isRefusalPresent(part)) {
|
||||
options.refusal = part.refusal;
|
||||
}
|
||||
}
|
||||
return outputContent;
|
||||
}
|
||||
|
||||
private extractToolCalls(
|
||||
response: OpenAILLM.Responses.ResponseOutputItem[],
|
||||
): PartialToolCall[] {
|
||||
return response
|
||||
.filter((item): item is OpenAILLM.Responses.ResponseFunctionToolCall =>
|
||||
this.isFunctionCall(item),
|
||||
)
|
||||
.map((item) => {
|
||||
return {
|
||||
name: item.name,
|
||||
id: item.call_id,
|
||||
input: item.arguments,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
private parseResponseOutput(
|
||||
response: OpenAILLM.Responses.ResponseOutputItem[],
|
||||
): ChatMessage<ToolCallLLMMessageOptions> {
|
||||
const message = this.createInitialMessage();
|
||||
const options = this.createInitialOptions();
|
||||
const toolCall = this.extractToolCalls(response);
|
||||
|
||||
for (const item of response) {
|
||||
if (this.isMessageBlock(item)) {
|
||||
const outputContent = this.handleResponseOutputMessage(item, options);
|
||||
message.content = outputContent;
|
||||
} else if (this.isBuiltInToolCall(item)) {
|
||||
options.built_in_tool_calls.push(item);
|
||||
} else if (this.isReasoning(item)) {
|
||||
options.reasoning = item;
|
||||
}
|
||||
}
|
||||
message.options = {
|
||||
...options,
|
||||
toolCall: toolCall,
|
||||
};
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
private processStreamEvent(
|
||||
event: OpenAILLM.Responses.ResponseStreamEvent,
|
||||
streamState: StreamState,
|
||||
) {
|
||||
switch (true) {
|
||||
case this.isResponseCreatedEvent(event):
|
||||
this.handleResponseCreatedEvent(event, streamState);
|
||||
break;
|
||||
case this.isResponseOutputItemAddedEvent(event):
|
||||
this.handleOutputItemAddedEvent(event, streamState);
|
||||
break;
|
||||
case this.isResponseTextDeltaEvent(event):
|
||||
this.handleTextDeltaEvent(event, streamState);
|
||||
break;
|
||||
case this.isResponseFunctionCallArgumentsDeltaEvent(event):
|
||||
this.handleFunctionCallArgumentsDeltaEvent(event, streamState);
|
||||
break;
|
||||
case this.isResponseFunctionCallDoneEvent(event):
|
||||
this.handleFunctionCallArgumentsDoneEvent(event, streamState);
|
||||
break;
|
||||
case this.isResponseOutputTextAnnotationAddedEvent(event):
|
||||
this.handleOutputTextAnnotationAddedEvent(event, streamState);
|
||||
break;
|
||||
case this.isResponseFileSearchCallCompletedEvent(event):
|
||||
case this.isResponseWebSearchCallCompletedEvent(event):
|
||||
this.handleBuiltInToolCallCompletedEvent(event, streamState);
|
||||
break;
|
||||
case this.isResponseCompletedEvent(event):
|
||||
this.handleCompletedEvent(event, streamState);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private handleResponseCreatedEvent(
|
||||
event: OpenAILLM.Responses.ResponseCreatedEvent,
|
||||
streamState: StreamState,
|
||||
) {
|
||||
if (this.trackPreviousResponses) {
|
||||
streamState.previousResponseId = event.response.id;
|
||||
}
|
||||
}
|
||||
|
||||
private handleOutputItemAddedEvent(
|
||||
event: OpenAILLM.Responses.ResponseOutputItemAddedEvent,
|
||||
streamState: StreamState,
|
||||
) {
|
||||
if (this.isToolCallEvent(event)) {
|
||||
streamState.currentToolCall = {
|
||||
name: event.item.name,
|
||||
id: event.item.call_id,
|
||||
input: event.item.arguments,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private handleTextDeltaEvent(
|
||||
event: OpenAILLM.Responses.ResponseTextDeltaEvent,
|
||||
streamState: StreamState,
|
||||
) {
|
||||
streamState.delta = event.delta;
|
||||
}
|
||||
|
||||
private handleFunctionCallArgumentsDeltaEvent(
|
||||
event: OpenAILLM.Responses.ResponseFunctionCallArgumentsDeltaEvent,
|
||||
streamState: StreamState,
|
||||
) {
|
||||
if (streamState.currentToolCall) {
|
||||
streamState.currentToolCall!.input += event.delta;
|
||||
}
|
||||
}
|
||||
|
||||
private handleFunctionCallArgumentsDoneEvent(
|
||||
event: OpenAILLM.Responses.ResponseFunctionCallArgumentsDoneEvent,
|
||||
streamState: StreamState,
|
||||
) {
|
||||
if (streamState.currentToolCall) {
|
||||
streamState.currentToolCall.input = event.arguments;
|
||||
}
|
||||
|
||||
streamState.shouldEmitToolCall = {
|
||||
...streamState.currentToolCall!,
|
||||
input: JSON.parse(streamState.currentToolCall!.input),
|
||||
};
|
||||
}
|
||||
|
||||
private handleOutputTextAnnotationAddedEvent(
|
||||
event: OpenAILLM.Responses.ResponseTextAnnotationDeltaEvent,
|
||||
streamState: StreamState,
|
||||
) {
|
||||
if (!streamState.options.annotations) {
|
||||
streamState.options.annotations = [];
|
||||
}
|
||||
streamState.options.annotations.push(event.annotation);
|
||||
}
|
||||
|
||||
private handleBuiltInToolCallCompletedEvent(
|
||||
event:
|
||||
| OpenAILLM.Responses.ResponseFileSearchCallCompletedEvent
|
||||
| OpenAILLM.Responses.ResponseWebSearchCallCompletedEvent,
|
||||
streamState: StreamState,
|
||||
) {
|
||||
streamState.options.built_in_tool_calls.push(event);
|
||||
}
|
||||
|
||||
private handleCompletedEvent(
|
||||
event: OpenAILLM.Responses.ResponseCompletedEvent,
|
||||
streamState: StreamState,
|
||||
) {
|
||||
if (event.response.usage) {
|
||||
streamState.options.usage = event.response.usage;
|
||||
}
|
||||
}
|
||||
|
||||
private createBaseRequestParams(
|
||||
messages: ChatMessage<ToolCallLLMMessageOptions>[],
|
||||
tools: BaseTool[] | undefined,
|
||||
additionalChatOptions: OpenAIResponsesChatOptions | undefined,
|
||||
) {
|
||||
const baseRequestParams = <OpenAILLM.Responses.ResponseCreateParams>{
|
||||
model: this.model,
|
||||
include: this.include,
|
||||
input: this.toOpenAIResponseMessages(messages),
|
||||
tools: this.builtInTools ? [...this.builtInTools] : [],
|
||||
instructions: this.instructions,
|
||||
max_output_tokens: this.maxOutputTokens,
|
||||
previous_response_id: this.previousResponseId,
|
||||
store: this.store,
|
||||
metadata: this.callMetadata,
|
||||
top_p: this.topP,
|
||||
truncation: this.truncation,
|
||||
user: this.user,
|
||||
...Object.assign({}, this.additionalChatOptions, additionalChatOptions),
|
||||
};
|
||||
|
||||
if (tools?.length) {
|
||||
if (!baseRequestParams.tools) {
|
||||
baseRequestParams.tools = [];
|
||||
}
|
||||
baseRequestParams.tools.push(
|
||||
...tools.map(this.toResponsesTool.bind(this)),
|
||||
);
|
||||
}
|
||||
|
||||
return baseRequestParams;
|
||||
}
|
||||
|
||||
chat(
|
||||
params: LLMChatParamsStreaming<
|
||||
OpenAIResponsesChatOptions,
|
||||
ToolCallLLMMessageOptions
|
||||
>,
|
||||
): Promise<AsyncIterable<ChatResponseChunk<ToolCallLLMMessageOptions>>>;
|
||||
chat(
|
||||
params: LLMChatParamsNonStreaming<
|
||||
OpenAIResponsesChatOptions,
|
||||
ToolCallLLMMessageOptions
|
||||
>,
|
||||
): Promise<ChatResponse<ToolCallLLMMessageOptions>>;
|
||||
async chat(
|
||||
params:
|
||||
| LLMChatParamsNonStreaming<
|
||||
OpenAIResponsesChatOptions,
|
||||
ToolCallLLMMessageOptions
|
||||
>
|
||||
| LLMChatParamsStreaming<
|
||||
OpenAIResponsesChatOptions,
|
||||
ToolCallLLMMessageOptions
|
||||
>,
|
||||
): Promise<
|
||||
| ChatResponse<ToolCallLLMMessageOptions>
|
||||
| AsyncIterable<ChatResponseChunk<ToolCallLLMMessageOptions>>
|
||||
> {
|
||||
const { messages, stream, tools, responseFormat, additionalChatOptions } =
|
||||
params;
|
||||
const baseRequestParams = this.createBaseRequestParams(
|
||||
messages,
|
||||
tools,
|
||||
additionalChatOptions,
|
||||
);
|
||||
|
||||
if (
|
||||
Array.isArray(baseRequestParams.tools) &&
|
||||
baseRequestParams.tools.length === 0
|
||||
) {
|
||||
// remove empty tools array to avoid OpenAI error
|
||||
delete baseRequestParams.tools;
|
||||
}
|
||||
|
||||
if (!isTemperatureSupported(baseRequestParams.model))
|
||||
delete baseRequestParams.temperature;
|
||||
|
||||
if (stream) {
|
||||
return this.streamChat(baseRequestParams);
|
||||
}
|
||||
|
||||
const response = await (
|
||||
await this.session
|
||||
).responses.create({
|
||||
...baseRequestParams,
|
||||
stream: false,
|
||||
});
|
||||
|
||||
const message = this.parseResponseOutput(response.output);
|
||||
return {
|
||||
raw: response,
|
||||
message,
|
||||
};
|
||||
}
|
||||
|
||||
private initalizeStreamState(): StreamState {
|
||||
return {
|
||||
delta: "",
|
||||
currentToolCall: null,
|
||||
shouldEmitToolCall: null,
|
||||
options: this.createInitialOptions(),
|
||||
previousResponseId: this.previousResponseId,
|
||||
};
|
||||
}
|
||||
|
||||
private createResponseChunk(
|
||||
event: OpenAILLM.Responses.ResponseStreamEvent,
|
||||
state: StreamState,
|
||||
): ChatResponseChunk<ToolCallLLMMessageOptions> {
|
||||
return {
|
||||
raw: event,
|
||||
delta: state.delta,
|
||||
options: state.shouldEmitToolCall
|
||||
? { toolCall: [state.shouldEmitToolCall] }
|
||||
: state.currentToolCall
|
||||
? { toolCall: [state.currentToolCall] }
|
||||
: {},
|
||||
};
|
||||
}
|
||||
|
||||
@wrapEventCaller
|
||||
protected async *streamChat(
|
||||
baseRequestParams: OpenAILLM.Responses.ResponseCreateParams,
|
||||
): AsyncIterable<ChatResponseChunk<ToolCallLLMMessageOptions>> {
|
||||
const streamState = this.initalizeStreamState();
|
||||
|
||||
const stream = await (
|
||||
await this.session
|
||||
).responses.create({
|
||||
...baseRequestParams,
|
||||
stream: true,
|
||||
});
|
||||
|
||||
for await (const event of stream) {
|
||||
this.processStreamEvent(event, streamState);
|
||||
this.handlePreviousResponseId(streamState);
|
||||
yield this.createResponseChunk(event, streamState);
|
||||
}
|
||||
}
|
||||
|
||||
toOpenAIResponsesRole(messageType: MessageType): OpenAIResponsesRole {
|
||||
switch (messageType) {
|
||||
case "user":
|
||||
return "user";
|
||||
case "assistant":
|
||||
return "assistant";
|
||||
case "system":
|
||||
return "system";
|
||||
case "developer":
|
||||
return "developer";
|
||||
default:
|
||||
return "user";
|
||||
}
|
||||
}
|
||||
|
||||
private isToolResultPresent(
|
||||
options: ToolCallLLMMessageOptions,
|
||||
): options is ToolResultOptions {
|
||||
return "toolResult" in options;
|
||||
}
|
||||
|
||||
private isToolCallPresent(
|
||||
options: ToolCallLLMMessageOptions,
|
||||
): options is ToolCallOptions {
|
||||
return "toolCall" in options;
|
||||
}
|
||||
|
||||
private isUserMessage(message: ChatMessage<ToolCallLLMMessageOptions>) {
|
||||
return message.role === "user";
|
||||
}
|
||||
|
||||
private handlePreviousResponseId(streamState: StreamState) {
|
||||
if (this.trackPreviousResponses) {
|
||||
if (streamState.previousResponseId != this.previousResponseId) {
|
||||
this.previousResponseId = streamState.previousResponseId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private convertToOpenAIToolCallResult(
|
||||
options: ToolResultOptions,
|
||||
content: MessageContent,
|
||||
) {
|
||||
return {
|
||||
type: "function_call_output",
|
||||
call_id: options.toolResult.id,
|
||||
output: extractText(content),
|
||||
} satisfies OpenAILLM.Responses.ResponseInputItem.FunctionCallOutput;
|
||||
}
|
||||
|
||||
private convertToOpenAIToolCalls(options: ToolCallOptions) {
|
||||
return options.toolCall.map((toolCall) => {
|
||||
return {
|
||||
type: "function_call",
|
||||
call_id: toolCall.id,
|
||||
name: toolCall.name,
|
||||
arguments:
|
||||
typeof toolCall.input === "string"
|
||||
? toolCall.input
|
||||
: JSON.stringify(toolCall.input),
|
||||
};
|
||||
}) satisfies OpenAILLM.Responses.ResponseFunctionToolCall[];
|
||||
}
|
||||
|
||||
private processMessageContent(
|
||||
content: MessageContent,
|
||||
): ResponseMessageContent {
|
||||
if (!Array.isArray(content)) {
|
||||
return content;
|
||||
}
|
||||
|
||||
return content.map((item) => {
|
||||
if (item.type === "text") {
|
||||
return {
|
||||
type: "input_text",
|
||||
text: item.text,
|
||||
};
|
||||
}
|
||||
if (item.type === "image_url") {
|
||||
return {
|
||||
type: "input_image",
|
||||
image_url: item.image_url.url,
|
||||
detail: item.detail || "auto",
|
||||
};
|
||||
}
|
||||
throw new Error("Unsupported content type");
|
||||
});
|
||||
}
|
||||
|
||||
private convertToOpenAIUserMessage(
|
||||
message: ChatMessage<ToolCallLLMMessageOptions>,
|
||||
) {
|
||||
const messageContent = this.processMessageContent(message.content);
|
||||
return {
|
||||
role: "user",
|
||||
content: messageContent,
|
||||
} satisfies OpenAILLM.Responses.EasyInputMessage;
|
||||
}
|
||||
|
||||
private defaultOpenAIResponseMessage(
|
||||
message: ChatMessage<ToolCallLLMMessageOptions>,
|
||||
) {
|
||||
const response: OpenAILLM.Responses.ResponseInputItem = {
|
||||
role: this.toOpenAIResponsesRole(message.role),
|
||||
content: extractText(message.content),
|
||||
};
|
||||
return response;
|
||||
}
|
||||
|
||||
toOpenAIResponseMessage(
|
||||
message: ChatMessage<ToolCallLLMMessageOptions>,
|
||||
):
|
||||
| OpenAILLM.Responses.ResponseInputItem
|
||||
| OpenAILLM.Responses.ResponseInputItem[] {
|
||||
const options = message.options ?? {};
|
||||
|
||||
if (this.isToolResultPresent(options)) {
|
||||
return this.convertToOpenAIToolCallResult(options, message.content);
|
||||
} else if (this.isToolCallPresent(options)) {
|
||||
return this.convertToOpenAIToolCalls(options);
|
||||
} else if (this.isUserMessage(message)) {
|
||||
return this.convertToOpenAIUserMessage(message);
|
||||
}
|
||||
|
||||
return this.defaultOpenAIResponseMessage(message);
|
||||
}
|
||||
|
||||
toOpenAIResponseMessages(
|
||||
messages: ChatMessage<ToolCallLLMMessageOptions>[],
|
||||
): OpenAILLM.Responses.ResponseInput {
|
||||
const finalMessages: OpenAILLM.Responses.ResponseInputItem[] = [];
|
||||
for (const message of messages) {
|
||||
const processedMessage = this.toOpenAIResponseMessage(message);
|
||||
if (Array.isArray(processedMessage)) {
|
||||
finalMessages.push(...processedMessage);
|
||||
} else {
|
||||
finalMessages.push(processedMessage);
|
||||
}
|
||||
}
|
||||
return finalMessages;
|
||||
}
|
||||
|
||||
toResponsesTool(tool: BaseTool): OpenAILLM.Responses.Tool {
|
||||
return {
|
||||
type: "function",
|
||||
name: tool.metadata.name,
|
||||
description: tool.metadata.description,
|
||||
parameters: tool.metadata.parameters ?? {},
|
||||
strict: this.strict,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience function to create a new OpenAI instance.
|
||||
* @param init - Optional initialization parameters for the OpenAI instance.
|
||||
* @returns A new OpenAI instance.
|
||||
*/
|
||||
export const openaiResponses = (
|
||||
init?: ConstructorParameters<typeof OpenAIResponses>[0],
|
||||
) => new OpenAIResponses(init);
|
||||
@@ -0,0 +1,213 @@
|
||||
import type { LLM, PartialToolCall } from "@llamaindex/core/llms";
|
||||
import { AzureOpenAI as AzureOpenAILLM, OpenAI as OpenAILLM } from "openai";
|
||||
import type { ChatModel } from "openai/resources.mjs";
|
||||
import { OpenAI } from "./llm";
|
||||
|
||||
export const GPT4_MODELS = {
|
||||
"chatgpt-4o-latest": {
|
||||
contextWindow: 128000,
|
||||
},
|
||||
"gpt-4.5-preview": { contextWindow: 128000 },
|
||||
"gpt-4.5-preview-2025-02-27": { contextWindow: 128000 },
|
||||
"gpt-4": { contextWindow: 8192 },
|
||||
"gpt-4-32k": { contextWindow: 32768 },
|
||||
"gpt-4-32k-0613": { contextWindow: 32768 },
|
||||
"gpt-4-turbo": { contextWindow: 128000 },
|
||||
"gpt-4-turbo-preview": { contextWindow: 128000 },
|
||||
"gpt-4-1106-preview": { contextWindow: 128000 },
|
||||
"gpt-4-0125-preview": { contextWindow: 128000 },
|
||||
"gpt-4-vision-preview": { contextWindow: 128000 },
|
||||
"gpt-4o": { contextWindow: 128000 },
|
||||
"gpt-4o-2024-05-13": { contextWindow: 128000 },
|
||||
"gpt-4o-mini": { contextWindow: 128000 },
|
||||
"gpt-4o-mini-2024-07-18": { contextWindow: 128000 },
|
||||
"gpt-4o-2024-08-06": { contextWindow: 128000 },
|
||||
"gpt-4o-2024-09-14": { contextWindow: 128000 },
|
||||
"gpt-4o-2024-10-14": { contextWindow: 128000 },
|
||||
"gpt-4-0613": { contextWindow: 128000 },
|
||||
"gpt-4-turbo-2024-04-09": { contextWindow: 128000 },
|
||||
"gpt-4-0314": { contextWindow: 128000 },
|
||||
"gpt-4-32k-0314": { contextWindow: 32768 },
|
||||
"gpt-4o-realtime-preview": {
|
||||
contextWindow: 128000,
|
||||
},
|
||||
"gpt-4o-realtime-preview-2024-10-01": {
|
||||
contextWindow: 128000,
|
||||
},
|
||||
"gpt-4o-audio-preview": {
|
||||
contextWindow: 128000,
|
||||
},
|
||||
"gpt-4o-audio-preview-2024-10-01": {
|
||||
contextWindow: 128000,
|
||||
},
|
||||
"gpt-4o-2024-11-20": {
|
||||
contextWindow: 128000,
|
||||
},
|
||||
"gpt-4o-audio-preview-2024-12-17": {
|
||||
contextWindow: 128000,
|
||||
},
|
||||
"gpt-4o-mini-audio-preview": {
|
||||
contextWindow: 128000,
|
||||
},
|
||||
"gpt-4o-mini-audio-preview-2024-12-17": {
|
||||
contextWindow: 128000,
|
||||
},
|
||||
"gpt-4o-search-preview": { contextWindow: 128000 },
|
||||
"gpt-4o-mini-search-preview": { contextWindow: 128000 },
|
||||
"gpt-4o-search-preview-2025-03-11": { contextWindow: 128000 },
|
||||
"gpt-4o-mini-search-preview-2025-03-11": { contextWindow: 128000 },
|
||||
};
|
||||
|
||||
// NOTE we don't currently support gpt-3.5-turbo-instruct and don't plan to in the near future
|
||||
export const GPT35_MODELS = {
|
||||
"gpt-3.5-turbo": { contextWindow: 16385 },
|
||||
"gpt-3.5-turbo-0613": { contextWindow: 4096 },
|
||||
"gpt-3.5-turbo-16k": { contextWindow: 16385 },
|
||||
"gpt-3.5-turbo-16k-0613": { contextWindow: 16385 },
|
||||
"gpt-3.5-turbo-1106": { contextWindow: 16385 },
|
||||
"gpt-3.5-turbo-0125": { contextWindow: 16385 },
|
||||
"gpt-3.5-turbo-0301": { contextWindow: 16385 },
|
||||
};
|
||||
|
||||
export const O1_MODELS = {
|
||||
"o1-preview": {
|
||||
contextWindow: 128000,
|
||||
},
|
||||
"o1-preview-2024-09-12": {
|
||||
contextWindow: 128000,
|
||||
},
|
||||
"o1-mini": {
|
||||
contextWindow: 128000,
|
||||
},
|
||||
"o1-mini-2024-09-12": {
|
||||
contextWindow: 128000,
|
||||
},
|
||||
o1: {
|
||||
contextWindow: 128000,
|
||||
},
|
||||
"o1-2024-12-17": {
|
||||
contextWindow: 128000,
|
||||
},
|
||||
};
|
||||
|
||||
export const O3_MODELS = {
|
||||
"o3-mini": {
|
||||
contextWindow: 200000,
|
||||
},
|
||||
"o3-mini-2025-01-31": {
|
||||
contextWindow: 200000,
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* We currently support GPT-3.5 and GPT-4 models
|
||||
*/
|
||||
export const ALL_AVAILABLE_OPENAI_MODELS = {
|
||||
...GPT4_MODELS,
|
||||
...GPT35_MODELS,
|
||||
...O1_MODELS,
|
||||
...O3_MODELS,
|
||||
} satisfies Record<ChatModel, { contextWindow: number }>;
|
||||
|
||||
export function isFunctionCallingModel(llm: LLM): llm is OpenAI {
|
||||
let model: string;
|
||||
if (llm instanceof OpenAI) {
|
||||
model = llm.model;
|
||||
} else if ("model" in llm && typeof llm.model === "string") {
|
||||
model = llm.model;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
const isChatModel = Object.keys(ALL_AVAILABLE_OPENAI_MODELS).includes(model);
|
||||
const isOld = model.includes("0314") || model.includes("0301");
|
||||
const isO1 = model.startsWith("o1");
|
||||
return isChatModel && !isOld && !isO1;
|
||||
}
|
||||
|
||||
export function isReasoningModel(model: ChatModel | string): boolean {
|
||||
const isO1 = model.startsWith("o1");
|
||||
const isO3 = model.startsWith("o3");
|
||||
return isO1 || isO3;
|
||||
}
|
||||
|
||||
export function isTemperatureSupported(model: ChatModel | string): boolean {
|
||||
return !model.startsWith("o3");
|
||||
}
|
||||
|
||||
export type OpenAIAdditionalMetadata = object;
|
||||
|
||||
export type OpenAIAdditionalChatOptions = Omit<
|
||||
Partial<OpenAILLM.Chat.ChatCompletionCreateParams>,
|
||||
| "max_tokens"
|
||||
| "messages"
|
||||
| "model"
|
||||
| "temperature"
|
||||
| "reasoning_effort"
|
||||
| "top_p"
|
||||
| "stream"
|
||||
| "tools"
|
||||
| "toolChoice"
|
||||
>;
|
||||
|
||||
export type LLMInstance = Pick<
|
||||
AzureOpenAILLM | OpenAILLM,
|
||||
"chat" | "apiKey" | "baseURL" | "responses"
|
||||
>;
|
||||
|
||||
export type OpenAIResponsesChatOptions = Omit<
|
||||
Partial<OpenAILLM.Responses.ResponseCreateParams>,
|
||||
| "model"
|
||||
| "input"
|
||||
| "stream"
|
||||
| "tools"
|
||||
| "toolChoice"
|
||||
| "temperature"
|
||||
| "reasoning_effort"
|
||||
| "top_p"
|
||||
| "max_output_tokens"
|
||||
| "include"
|
||||
>;
|
||||
|
||||
export type ResponsesAdditionalOptions = {
|
||||
built_in_tool_calls: Array<
|
||||
| OpenAILLM.Responses.ResponseFileSearchToolCall
|
||||
| OpenAILLM.Responses.ResponseComputerToolCall
|
||||
| OpenAILLM.Responses.ResponseFunctionWebSearch
|
||||
| OpenAILLM.Responses.ResponseFileSearchCallCompletedEvent
|
||||
| OpenAILLM.Responses.ResponseWebSearchCallCompletedEvent
|
||||
>;
|
||||
annotations?: Array<
|
||||
| OpenAILLM.Responses.ResponseOutputText.FileCitation
|
||||
| OpenAILLM.Responses.ResponseOutputText.URLCitation
|
||||
| OpenAILLM.Responses.ResponseOutputText.FilePath
|
||||
>;
|
||||
refusal?: string;
|
||||
reasoning?: OpenAILLM.Responses.ResponseReasoningItem;
|
||||
usage?: OpenAILLM.Responses.ResponseUsage;
|
||||
};
|
||||
|
||||
export type StreamState = {
|
||||
delta: string;
|
||||
currentToolCall: PartialToolCall | null;
|
||||
shouldEmitToolCall: PartialToolCall | null;
|
||||
options: ResponsesAdditionalOptions;
|
||||
previousResponseId: string | null;
|
||||
};
|
||||
|
||||
export type ResponsesMessageContentTextDetail = {
|
||||
type: "input_text";
|
||||
text: string;
|
||||
};
|
||||
|
||||
export type ResponsesMessageContentImageDetail = {
|
||||
type: "input_image";
|
||||
image_url: string;
|
||||
detail: "high" | "low" | "auto";
|
||||
};
|
||||
export type ResponsesMessageContentDetail =
|
||||
| ResponsesMessageContentTextDetail
|
||||
| ResponsesMessageContentImageDetail;
|
||||
|
||||
export type ResponseMessageContent = string | ResponsesMessageContentDetail[];
|
||||
|
||||
export type OpenAIResponsesRole = "user" | "assistant" | "system" | "developer";
|
||||
@@ -0,0 +1,223 @@
|
||||
import type { BaseTool, ToolCallOptions } from "@llamaindex/core/llms";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { OpenAIResponses } from "../src/responses";
|
||||
|
||||
const API_KEY = process.env.MY_OPENAI_API_KEY;
|
||||
|
||||
describe("OpenAIResponses Integration Tests", () => {
|
||||
if (!API_KEY) {
|
||||
describe.skip("OpenAI API key not found skipping tests");
|
||||
return;
|
||||
}
|
||||
|
||||
const llm = new OpenAIResponses({
|
||||
model: "gpt-4o",
|
||||
apiKey: API_KEY,
|
||||
});
|
||||
|
||||
it("should handle basic text chat", async () => {
|
||||
const response = await llm.chat({
|
||||
messages: [
|
||||
{
|
||||
role: "user",
|
||||
content: "What is 2+2? Answer in one word.",
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
expect(response.message.content).toBe("Four.");
|
||||
expect(response.message.role).toBe("assistant");
|
||||
});
|
||||
|
||||
it("should handle image analysis", async () => {
|
||||
const response = await llm.chat({
|
||||
messages: [
|
||||
{
|
||||
role: "user",
|
||||
content: [
|
||||
{
|
||||
type: "text",
|
||||
text: "What's in this image? Describe in one sentence.",
|
||||
},
|
||||
{
|
||||
type: "image_url",
|
||||
image_url: {
|
||||
url: "https://storage.googleapis.com/cloud-samples-data/vision/face/faces.jpeg",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(response.raw).toHaveProperty("id");
|
||||
});
|
||||
|
||||
it("should handle function calls", async () => {
|
||||
const weatherTool: BaseTool = {
|
||||
metadata: {
|
||||
name: "get_weather",
|
||||
description: "Get current weather for a location",
|
||||
parameters: {
|
||||
type: "object",
|
||||
properties: {
|
||||
location: {
|
||||
type: "string",
|
||||
description: "City name",
|
||||
},
|
||||
},
|
||||
required: ["location"],
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const response = await llm.chat({
|
||||
messages: [
|
||||
{
|
||||
role: "user",
|
||||
content: "What's the weather in London?",
|
||||
},
|
||||
],
|
||||
tools: [weatherTool],
|
||||
});
|
||||
|
||||
expect(
|
||||
(response.message.options as ToolCallOptions)?.toolCall,
|
||||
).toBeDefined();
|
||||
const toolCall = (response.message.options as ToolCallOptions)
|
||||
?.toolCall?.[0];
|
||||
expect(toolCall?.name).toBe("get_weather");
|
||||
expect(
|
||||
typeof toolCall?.input === "string" &&
|
||||
JSON.parse(toolCall?.input || "{}"),
|
||||
).toHaveProperty("location", "London");
|
||||
});
|
||||
});
|
||||
|
||||
describe("OpenAIResponses Unit Tests", () => {
|
||||
// Testing utility functions
|
||||
describe("processMessageContent", () => {
|
||||
const llm = new OpenAIResponses({
|
||||
model: "gpt-4o",
|
||||
apiKey: "test",
|
||||
});
|
||||
|
||||
it("should handle non-array content (string)", () => {
|
||||
const content = "Hello world";
|
||||
// @ts-expect-error accessing private method
|
||||
const result = llm.processMessageContent(content);
|
||||
expect(result).toBe(content);
|
||||
});
|
||||
|
||||
it("should process text content", () => {
|
||||
const content = [
|
||||
{
|
||||
type: "text",
|
||||
text: "Hello world",
|
||||
},
|
||||
];
|
||||
// @ts-expect-error accessing private method
|
||||
const result = llm.processMessageContent(content);
|
||||
expect(result[0]).toEqual({
|
||||
type: "input_text",
|
||||
text: "Hello world",
|
||||
});
|
||||
});
|
||||
|
||||
it("should process image content with default detail", () => {
|
||||
const content = [
|
||||
{
|
||||
type: "image_url",
|
||||
image_url: { url: "https://example.com/image.jpg" },
|
||||
},
|
||||
];
|
||||
// @ts-expect-error accessing private method
|
||||
const result = llm.processMessageContent(content);
|
||||
expect(result[0]).toEqual({
|
||||
type: "input_image",
|
||||
image_url: "https://example.com/image.jpg",
|
||||
detail: "auto",
|
||||
});
|
||||
});
|
||||
|
||||
it("should process image content with specified detail", () => {
|
||||
const content = [
|
||||
{
|
||||
type: "image_url",
|
||||
image_url: { url: "https://example.com/image.jpg" },
|
||||
detail: "high",
|
||||
},
|
||||
];
|
||||
// @ts-expect-error accessing private method
|
||||
const result = llm.processMessageContent(content);
|
||||
expect(result[0]).toEqual({
|
||||
type: "input_image",
|
||||
image_url: "https://example.com/image.jpg",
|
||||
detail: "high",
|
||||
});
|
||||
});
|
||||
|
||||
it("should process mixed content", () => {
|
||||
const content = [
|
||||
{
|
||||
type: "text",
|
||||
text: "What's in this image?",
|
||||
},
|
||||
{
|
||||
type: "image_url",
|
||||
image_url: { url: "https://example.com/image.jpg" },
|
||||
},
|
||||
];
|
||||
// @ts-expect-error accessing private method
|
||||
const result = llm.processMessageContent(content);
|
||||
expect(result).toEqual([
|
||||
{
|
||||
type: "input_text",
|
||||
text: "What's in this image?",
|
||||
},
|
||||
{
|
||||
type: "input_image",
|
||||
image_url: "https://example.com/image.jpg",
|
||||
detail: "auto",
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("isResponseCreatedEvent", () => {
|
||||
const llm = new OpenAIResponses({
|
||||
model: "gpt-4o",
|
||||
apiKey: "test",
|
||||
});
|
||||
|
||||
it("should identify response created events", () => {
|
||||
const event = { type: "response.created", response_id: "123" };
|
||||
// @ts-expect-error accessing private method
|
||||
expect(llm.isResponseCreatedEvent(event)).toBe(true);
|
||||
});
|
||||
|
||||
it("should reject non-created events", () => {
|
||||
const event = { type: "response.other", response_id: "123" };
|
||||
// @ts-expect-error accessing private method
|
||||
expect(llm.isResponseCreatedEvent(event)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("isFunctionCall", () => {
|
||||
const llm = new OpenAIResponses({
|
||||
model: "gpt-4o",
|
||||
apiKey: "test",
|
||||
});
|
||||
|
||||
it("should identify function calls", () => {
|
||||
const item = { type: "function_call", name: "test", arguments: "{}" };
|
||||
// @ts-expect-error accessing private method
|
||||
expect(llm.isFunctionCall(item)).toBe(true);
|
||||
});
|
||||
|
||||
it("should reject non-function calls", () => {
|
||||
const item = { type: "message", content: "test" };
|
||||
// @ts-expect-error accessing private method
|
||||
expect(llm.isFunctionCall(item)).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
Generated
+199
-26
@@ -60,6 +60,9 @@ importers:
|
||||
typescript-eslint:
|
||||
specifier: ^8.18.0
|
||||
version: 8.24.0(eslint@9.22.0(jiti@2.4.2))(typescript@5.7.3)
|
||||
vitest:
|
||||
specifier: ^3.1.1
|
||||
version: 3.1.1(@edge-runtime/vm@4.0.4)(@types/debug@4.1.12)(@types/node@22.13.5)(happy-dom@15.11.7)(lightningcss@1.29.1)(msw@2.7.0(@types/node@22.13.5)(typescript@5.7.3))(terser@5.38.2)
|
||||
|
||||
apps/next:
|
||||
dependencies:
|
||||
@@ -119,7 +122,7 @@ importers:
|
||||
version: 1.6.0(@aws-sdk/credential-provider-web-identity@3.744.0)
|
||||
ai:
|
||||
specifier: ^3.4.33
|
||||
version: 3.4.33(openai@4.86.0(ws@8.18.0(bufferutil@4.0.9))(zod@3.24.2))(react@19.0.0)(sswr@2.1.0(svelte@5.19.10))(svelte@5.19.10)(vue@3.5.13(typescript@5.7.3))(zod@3.24.2)
|
||||
version: 3.4.33(openai@4.90.0(ws@8.18.0(bufferutil@4.0.9))(zod@3.24.2))(react@19.0.0)(sswr@2.1.0(svelte@5.19.10))(svelte@5.19.10)(vue@3.5.13(typescript@5.7.3))(zod@3.24.2)
|
||||
class-variance-authority:
|
||||
specifier: ^0.7.0
|
||||
version: 0.7.1
|
||||
@@ -1340,8 +1343,8 @@ importers:
|
||||
specifier: workspace:*
|
||||
version: link:../../env
|
||||
openai:
|
||||
specifier: ^4.86.0
|
||||
version: 4.86.0(ws@8.18.0(bufferutil@4.0.9))(zod@3.24.2)
|
||||
specifier: ^4.90.0
|
||||
version: 4.90.0(ws@8.18.0(bufferutil@4.0.9))(zod@3.24.2)
|
||||
zod:
|
||||
specifier: ^3.24.2
|
||||
version: 3.24.2
|
||||
@@ -1464,7 +1467,7 @@ importers:
|
||||
version: link:../../../env
|
||||
chromadb:
|
||||
specifier: 1.10.3
|
||||
version: 1.10.3(cohere-ai@7.14.0)(openai@4.86.0(ws@8.18.0(bufferutil@4.0.9))(zod@3.24.2))(voyageai@0.0.3-1)
|
||||
version: 1.10.3(cohere-ai@7.14.0)(openai@4.90.0(ws@8.18.0(bufferutil@4.0.9))(zod@3.24.2))(voyageai@0.0.3-1)
|
||||
chromadb-default-embed:
|
||||
specifier: ^2.13.2
|
||||
version: 2.13.2
|
||||
@@ -6044,6 +6047,9 @@ packages:
|
||||
'@vitest/expect@3.0.9':
|
||||
resolution: {integrity: sha512-5eCqRItYgIML7NNVgJj6TVCmdzE7ZVgJhruW0ziSQV4V7PvLkDL1bBkBdcTs/VuIz0IxPb5da1IDSqc1TR9eig==}
|
||||
|
||||
'@vitest/expect@3.1.1':
|
||||
resolution: {integrity: sha512-q/zjrW9lgynctNbwvFtQkGK9+vvHA5UzVi2V8APrp1C6fG6/MuYYkmlx4FubuqLycCeSdHD5aadWfua/Vr0EUA==}
|
||||
|
||||
'@vitest/mocker@2.1.0':
|
||||
resolution: {integrity: sha512-ZxENovUqhzl+QiOFpagiHUNUuZ1qPd5yYTCYHomGIZOFArzn4mgX2oxZmiAItJWAaXHG6bbpb/DpSPhlk5DgtA==}
|
||||
peerDependencies:
|
||||
@@ -6078,6 +6084,17 @@ packages:
|
||||
vite:
|
||||
optional: true
|
||||
|
||||
'@vitest/mocker@3.1.1':
|
||||
resolution: {integrity: sha512-bmpJJm7Y7i9BBELlLuuM1J1Q6EQ6K5Ye4wcyOpOMXMcePYKSIYlpcrCm4l/O6ja4VJA5G2aMJiuZkZdnxlC3SA==}
|
||||
peerDependencies:
|
||||
msw: ^2.4.9
|
||||
vite: ^5.0.0 || ^6.0.0
|
||||
peerDependenciesMeta:
|
||||
msw:
|
||||
optional: true
|
||||
vite:
|
||||
optional: true
|
||||
|
||||
'@vitest/pretty-format@2.1.0':
|
||||
resolution: {integrity: sha512-7sxf2F3DNYatgmzXXcTh6cq+/fxwB47RIQqZJFoSH883wnVAoccSRT6g+dTKemUBo8Q5N4OYYj1EBXLuRKvp3Q==}
|
||||
|
||||
@@ -6090,6 +6107,9 @@ packages:
|
||||
'@vitest/pretty-format@3.0.9':
|
||||
resolution: {integrity: sha512-OW9F8t2J3AwFEwENg3yMyKWweF7oRJlMyHOMIhO5F3n0+cgQAJZBjNgrF8dLwFTEXl5jUqBLXd9QyyKv8zEcmA==}
|
||||
|
||||
'@vitest/pretty-format@3.1.1':
|
||||
resolution: {integrity: sha512-dg0CIzNx+hMMYfNmSqJlLSXEmnNhMswcn3sXO7Tpldr0LiGmg3eXdLLhwkv2ZqgHb/d5xg5F7ezNFRA1fA13yA==}
|
||||
|
||||
'@vitest/runner@2.1.0':
|
||||
resolution: {integrity: sha512-D9+ZiB8MbMt7qWDRJc4CRNNUlne/8E1X7dcKhZVAbcOKG58MGGYVDqAq19xlhNfMFZsW0bpVKgztBwks38Ko0w==}
|
||||
|
||||
@@ -6099,6 +6119,9 @@ packages:
|
||||
'@vitest/runner@3.0.9':
|
||||
resolution: {integrity: sha512-NX9oUXgF9HPfJSwl8tUZCMP1oGx2+Sf+ru6d05QjzQz4OwWg0psEzwY6VexP2tTHWdOkhKHUIZH+fS6nA7jfOw==}
|
||||
|
||||
'@vitest/runner@3.1.1':
|
||||
resolution: {integrity: sha512-X/d46qzJuEDO8ueyjtKfxffiXraPRfmYasoC4i5+mlLEJ10UvPb0XH5M9C3gWuxd7BAQhpK42cJgJtq53YnWVA==}
|
||||
|
||||
'@vitest/snapshot@2.1.0':
|
||||
resolution: {integrity: sha512-x69CygGMzt9VCO283K2/FYQ+nBrOj66OTKpsPykjCR4Ac3lLV+m85hj9reaIGmjBSsKzVvbxWmjWE3kF5ha3uQ==}
|
||||
|
||||
@@ -6108,6 +6131,9 @@ packages:
|
||||
'@vitest/snapshot@3.0.9':
|
||||
resolution: {integrity: sha512-AiLUiuZ0FuA+/8i19mTYd+re5jqjEc2jZbgJ2up0VY0Ddyyxg/uUtBDpIFAy4uzKaQxOW8gMgBdAJJ2ydhu39A==}
|
||||
|
||||
'@vitest/snapshot@3.1.1':
|
||||
resolution: {integrity: sha512-bByMwaVWe/+1WDf9exFxWWgAixelSdiwo2p33tpqIlM14vW7PRV5ppayVXtfycqze4Qhtwag5sVhX400MLBOOw==}
|
||||
|
||||
'@vitest/spy@2.1.0':
|
||||
resolution: {integrity: sha512-IXX5NkbdgTYTog3F14i2LgnBc+20YmkXMx0IWai84mcxySUDRgm0ihbOfR4L0EVRBDFG85GjmQQEZNNKVVpkZw==}
|
||||
|
||||
@@ -6117,6 +6143,9 @@ packages:
|
||||
'@vitest/spy@3.0.9':
|
||||
resolution: {integrity: sha512-/CcK2UDl0aQ2wtkp3YVWldrpLRNCfVcIOFGlVGKO4R5eajsH393Z1yiXLVQ7vWsj26JOEjeZI0x5sm5P4OGUNQ==}
|
||||
|
||||
'@vitest/spy@3.1.1':
|
||||
resolution: {integrity: sha512-+EmrUOOXbKzLkTDwlsc/xrwOlPDXyVk3Z6P6K4oiCndxz7YLpp/0R0UsWVOKT0IXWjjBJuSMk6D27qipaupcvQ==}
|
||||
|
||||
'@vitest/utils@2.1.0':
|
||||
resolution: {integrity: sha512-rreyfVe0PuNqJfKYUwfPDfi6rrp0VSu0Wgvp5WBqJonP+4NvXHk48X6oBam1Lj47Hy6jbJtnMj3OcRdrkTP0tA==}
|
||||
|
||||
@@ -6126,6 +6155,9 @@ packages:
|
||||
'@vitest/utils@3.0.9':
|
||||
resolution: {integrity: sha512-ilHM5fHhZ89MCp5aAaM9uhfl1c2JdxVxl3McqsdVyVNN6JffnEen8UMCdRTzOhGXNQGo5GNL9QugHrz727Wnng==}
|
||||
|
||||
'@vitest/utils@3.1.1':
|
||||
resolution: {integrity: sha512-1XIjflyaU2k3HMArJ50bwSh3wKWPD6Q47wz/NUSmRV0zNywPc4w79ARjg/i/aNINHwA+mIALhUVqD9/aUvZNgg==}
|
||||
|
||||
'@vladfrangu/async_event_emitter@2.4.6':
|
||||
resolution: {integrity: sha512-RaI5qZo6D2CVS6sTHFKg1v5Ohq/+Bo2LZ5gzUEwZ/WkHhwtGTCB/sVLw8ijOkAUxasZ+WshN/Rzj4ywsABJ5ZA==}
|
||||
engines: {node: '>=v14.0.0', npm: '>=7.0.0'}
|
||||
@@ -7862,6 +7894,10 @@ packages:
|
||||
resolution: {integrity: sha512-bFi65yM+xZgk+u/KRIpekdSYkTB5W1pEf0Lt8Q8Msh7b+eQ7LXVtIB1Bkm4fvclDEL1b2CZkMhv2mOeF8tMdkA==}
|
||||
engines: {node: '>=12.0.0'}
|
||||
|
||||
expect-type@1.2.0:
|
||||
resolution: {integrity: sha512-80F22aiJ3GLyVnS/B3HzgR6RelZVumzj9jkL0Rhz4h0xYbNW9PjlQz5h3J/SShErbXBc295vseR4/MIbVmUbeA==}
|
||||
engines: {node: '>=12.0.0'}
|
||||
|
||||
ext-list@2.2.2:
|
||||
resolution: {integrity: sha512-u+SQgsubraE6zItfVA0tBuCBhfU9ogSRnsvygI7wht9TS510oLkBRXBsqopeUG/GBOIQyKZO9wjTqIu/sf5zFA==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
@@ -10306,8 +10342,8 @@ packages:
|
||||
zod:
|
||||
optional: true
|
||||
|
||||
openai@4.86.0:
|
||||
resolution: {integrity: sha512-ggnH3vm+o9UvVQl/MxzDgpxsH9j7UoD17AeICcLSr1NCNb8PfwgMlp/K56ErQUxpkkcIA5mNkTuJAFSnoHej8A==}
|
||||
openai@4.90.0:
|
||||
resolution: {integrity: sha512-YCuHMMycqtCg1B8G9ezkOF0j8UnBWD3Al/zYaelpuXwU1yhCEv+Y4n9G20MnyGy6cH4GsFwOMrgstQ+bgG1PtA==}
|
||||
hasBin: true
|
||||
peerDependencies:
|
||||
ws: ^8.18.0
|
||||
@@ -11703,6 +11739,9 @@ packages:
|
||||
std-env@3.8.0:
|
||||
resolution: {integrity: sha512-Bc3YwwCB+OzldMxOXJIIvC6cPRWr/LxOp48CdQTOkPyk/t4JWWJbrilwBd7RJzKV8QW7tJkcgAmeuLLJugl5/w==}
|
||||
|
||||
std-env@3.8.1:
|
||||
resolution: {integrity: sha512-vj5lIj3Mwf9D79hBkltk5qmkFI+biIKWS2IBxEyEU3AX1tUf7AoL8nSazCOiiqQsGKIq01SClsKEzweu34uwvA==}
|
||||
|
||||
stdin-discarder@0.2.2:
|
||||
resolution: {integrity: sha512-UhDfHmA92YAlNnCfhmq0VeNL5bDbiZGg7sZ2IvPsXubGkiNa9EC+tUTsjBRsYUAz87btI6/1wf4XoVvQ3uRnmQ==}
|
||||
engines: {node: '>=18'}
|
||||
@@ -12511,6 +12550,11 @@ packages:
|
||||
engines: {node: ^18.0.0 || ^20.0.0 || >=22.0.0}
|
||||
hasBin: true
|
||||
|
||||
vite-node@3.1.1:
|
||||
resolution: {integrity: sha512-V+IxPAE2FvXpTCHXyNem0M+gWm6J7eRyWPR6vYoG/Gl+IscNOjXzztUhimQgTxaAoUoj40Qqimaa0NLIOOAH4w==}
|
||||
engines: {node: ^18.0.0 || ^20.0.0 || >=22.0.0}
|
||||
hasBin: true
|
||||
|
||||
vite-plugin-wasm@3.4.1:
|
||||
resolution: {integrity: sha512-ja3nSo2UCkVeitltJGkS3pfQHAanHv/DqGatdI39ja6McgABlpsZ5hVgl6wuR8Qx5etY3T5qgDQhOWzc5RReZA==}
|
||||
peerDependencies:
|
||||
@@ -12696,6 +12740,34 @@ packages:
|
||||
jsdom:
|
||||
optional: true
|
||||
|
||||
vitest@3.1.1:
|
||||
resolution: {integrity: sha512-kiZc/IYmKICeBAZr9DQ5rT7/6bD9G7uqQEki4fxazi1jdVl2mWGzedtBs5s6llz59yQhVb7FFY2MbHzHCnT79Q==}
|
||||
engines: {node: ^18.0.0 || ^20.0.0 || >=22.0.0}
|
||||
hasBin: true
|
||||
peerDependencies:
|
||||
'@edge-runtime/vm': '*'
|
||||
'@types/debug': ^4.1.12
|
||||
'@types/node': ^18.0.0 || ^20.0.0 || >=22.0.0
|
||||
'@vitest/browser': 3.1.1
|
||||
'@vitest/ui': 3.1.1
|
||||
happy-dom: '*'
|
||||
jsdom: '*'
|
||||
peerDependenciesMeta:
|
||||
'@edge-runtime/vm':
|
||||
optional: true
|
||||
'@types/debug':
|
||||
optional: true
|
||||
'@types/node':
|
||||
optional: true
|
||||
'@vitest/browser':
|
||||
optional: true
|
||||
'@vitest/ui':
|
||||
optional: true
|
||||
happy-dom:
|
||||
optional: true
|
||||
jsdom:
|
||||
optional: true
|
||||
|
||||
voyageai@0.0.3-1:
|
||||
resolution: {integrity: sha512-R3jN/xnILWoMBL3jPY61Ydm1JbpK3J+VmXBoHvlNg1Xz8h0xdX7sEffXeSu+sAEKQaPyWXVQDmM/jpBhPXw58g==}
|
||||
|
||||
@@ -17632,10 +17704,10 @@ snapshots:
|
||||
'@types/node': 22.9.0
|
||||
optional: true
|
||||
|
||||
'@typescript-eslint/eslint-plugin@8.24.0(@typescript-eslint/parser@8.24.0(eslint@9.16.0(jiti@2.4.2))(typescript@5.7.3))(eslint@9.16.0(jiti@2.4.2))(typescript@5.7.3)':
|
||||
'@typescript-eslint/eslint-plugin@8.24.0(@typescript-eslint/parser@8.24.0(eslint@9.22.0(jiti@2.4.2))(typescript@5.7.3))(eslint@9.16.0(jiti@2.4.2))(typescript@5.7.3)':
|
||||
dependencies:
|
||||
'@eslint-community/regexpp': 4.12.1
|
||||
'@typescript-eslint/parser': 8.24.0(eslint@9.16.0(jiti@2.4.2))(typescript@5.7.3)
|
||||
'@typescript-eslint/parser': 8.24.0(eslint@9.22.0(jiti@2.4.2))(typescript@5.7.3)
|
||||
'@typescript-eslint/scope-manager': 8.24.0
|
||||
'@typescript-eslint/type-utils': 8.24.0(eslint@9.16.0(jiti@2.4.2))(typescript@5.7.3)
|
||||
'@typescript-eslint/utils': 8.24.0(eslint@9.16.0(jiti@2.4.2))(typescript@5.7.3)
|
||||
@@ -17820,6 +17892,13 @@ snapshots:
|
||||
chai: 5.2.0
|
||||
tinyrainbow: 2.0.0
|
||||
|
||||
'@vitest/expect@3.1.1':
|
||||
dependencies:
|
||||
'@vitest/spy': 3.1.1
|
||||
'@vitest/utils': 3.1.1
|
||||
chai: 5.2.0
|
||||
tinyrainbow: 2.0.0
|
||||
|
||||
'@vitest/mocker@2.1.0(@vitest/spy@2.1.0)(msw@2.7.0(@types/node@22.13.5)(typescript@5.7.3))(vite@5.4.16(@types/node@22.13.5)(lightningcss@1.29.1)(terser@5.38.2))':
|
||||
dependencies:
|
||||
'@vitest/spy': 2.1.0
|
||||
@@ -17856,6 +17935,15 @@ snapshots:
|
||||
msw: 2.7.0(@types/node@22.13.5)(typescript@5.7.3)
|
||||
vite: 5.4.16(@types/node@22.13.5)(lightningcss@1.29.1)(terser@5.38.2)
|
||||
|
||||
'@vitest/mocker@3.1.1(msw@2.7.0(@types/node@22.13.5)(typescript@5.7.3))(vite@5.4.16(@types/node@22.13.5)(lightningcss@1.29.1)(terser@5.38.2))':
|
||||
dependencies:
|
||||
'@vitest/spy': 3.1.1
|
||||
estree-walker: 3.0.3
|
||||
magic-string: 0.30.17
|
||||
optionalDependencies:
|
||||
msw: 2.7.0(@types/node@22.13.5)(typescript@5.7.3)
|
||||
vite: 5.4.16(@types/node@22.13.5)(lightningcss@1.29.1)(terser@5.38.2)
|
||||
|
||||
'@vitest/pretty-format@2.1.0':
|
||||
dependencies:
|
||||
tinyrainbow: 1.2.0
|
||||
@@ -17872,6 +17960,10 @@ snapshots:
|
||||
dependencies:
|
||||
tinyrainbow: 2.0.0
|
||||
|
||||
'@vitest/pretty-format@3.1.1':
|
||||
dependencies:
|
||||
tinyrainbow: 2.0.0
|
||||
|
||||
'@vitest/runner@2.1.0':
|
||||
dependencies:
|
||||
'@vitest/utils': 2.1.0
|
||||
@@ -17887,6 +17979,11 @@ snapshots:
|
||||
'@vitest/utils': 3.0.9
|
||||
pathe: 2.0.3
|
||||
|
||||
'@vitest/runner@3.1.1':
|
||||
dependencies:
|
||||
'@vitest/utils': 3.1.1
|
||||
pathe: 2.0.3
|
||||
|
||||
'@vitest/snapshot@2.1.0':
|
||||
dependencies:
|
||||
'@vitest/pretty-format': 2.1.0
|
||||
@@ -17905,6 +18002,12 @@ snapshots:
|
||||
magic-string: 0.30.17
|
||||
pathe: 2.0.3
|
||||
|
||||
'@vitest/snapshot@3.1.1':
|
||||
dependencies:
|
||||
'@vitest/pretty-format': 3.1.1
|
||||
magic-string: 0.30.17
|
||||
pathe: 2.0.3
|
||||
|
||||
'@vitest/spy@2.1.0':
|
||||
dependencies:
|
||||
tinyspy: 3.0.2
|
||||
@@ -17917,6 +18020,10 @@ snapshots:
|
||||
dependencies:
|
||||
tinyspy: 3.0.2
|
||||
|
||||
'@vitest/spy@3.1.1':
|
||||
dependencies:
|
||||
tinyspy: 3.0.2
|
||||
|
||||
'@vitest/utils@2.1.0':
|
||||
dependencies:
|
||||
'@vitest/pretty-format': 2.1.0
|
||||
@@ -17935,6 +18042,12 @@ snapshots:
|
||||
loupe: 3.1.3
|
||||
tinyrainbow: 2.0.0
|
||||
|
||||
'@vitest/utils@3.1.1':
|
||||
dependencies:
|
||||
'@vitest/pretty-format': 3.1.1
|
||||
loupe: 3.1.3
|
||||
tinyrainbow: 2.0.0
|
||||
|
||||
'@vladfrangu/async_event_emitter@2.4.6': {}
|
||||
|
||||
'@vue/compiler-core@3.5.13':
|
||||
@@ -18256,7 +18369,7 @@ snapshots:
|
||||
dependencies:
|
||||
humanize-ms: 1.2.1
|
||||
|
||||
ai@3.4.33(openai@4.86.0(ws@8.18.0(bufferutil@4.0.9))(zod@3.24.2))(react@19.0.0)(sswr@2.1.0(svelte@5.19.10))(svelte@5.19.10)(vue@3.5.13(typescript@5.7.3))(zod@3.24.2):
|
||||
ai@3.4.33(openai@4.90.0(ws@8.18.0(bufferutil@4.0.9))(zod@3.24.2))(react@19.0.0)(sswr@2.1.0(svelte@5.19.10))(svelte@5.19.10)(vue@3.5.13(typescript@5.7.3))(zod@3.24.2):
|
||||
dependencies:
|
||||
'@ai-sdk/provider': 0.0.26
|
||||
'@ai-sdk/provider-utils': 1.0.22(zod@3.24.2)
|
||||
@@ -18272,7 +18385,7 @@ snapshots:
|
||||
secure-json-parse: 2.7.0
|
||||
zod-to-json-schema: 3.24.1(zod@3.24.2)
|
||||
optionalDependencies:
|
||||
openai: 4.86.0(ws@8.18.0(bufferutil@4.0.9))(zod@3.24.2)
|
||||
openai: 4.90.0(ws@8.18.0(bufferutil@4.0.9))(zod@3.24.2)
|
||||
react: 19.0.0
|
||||
sswr: 2.1.0(svelte@5.19.10)
|
||||
svelte: 5.19.10
|
||||
@@ -18910,13 +19023,13 @@ snapshots:
|
||||
transitivePeerDependencies:
|
||||
- bare-buffer
|
||||
|
||||
chromadb@1.10.3(cohere-ai@7.14.0)(openai@4.86.0(ws@8.18.0(bufferutil@4.0.9))(zod@3.24.2))(voyageai@0.0.3-1):
|
||||
chromadb@1.10.3(cohere-ai@7.14.0)(openai@4.90.0(ws@8.18.0(bufferutil@4.0.9))(zod@3.24.2))(voyageai@0.0.3-1):
|
||||
dependencies:
|
||||
cliui: 8.0.1
|
||||
isomorphic-fetch: 3.0.0
|
||||
optionalDependencies:
|
||||
cohere-ai: 7.14.0
|
||||
openai: 4.86.0(ws@8.18.0(bufferutil@4.0.9))(zod@3.24.2)
|
||||
openai: 4.90.0(ws@8.18.0(bufferutil@4.0.9))(zod@3.24.2)
|
||||
voyageai: 0.0.3-1
|
||||
transitivePeerDependencies:
|
||||
- encoding
|
||||
@@ -19695,12 +19808,12 @@ snapshots:
|
||||
dependencies:
|
||||
'@next/eslint-plugin-next': 15.1.0
|
||||
'@rushstack/eslint-patch': 1.10.5
|
||||
'@typescript-eslint/eslint-plugin': 8.24.0(@typescript-eslint/parser@8.24.0(eslint@9.16.0(jiti@2.4.2))(typescript@5.7.3))(eslint@9.16.0(jiti@2.4.2))(typescript@5.7.3)
|
||||
'@typescript-eslint/eslint-plugin': 8.24.0(@typescript-eslint/parser@8.24.0(eslint@9.22.0(jiti@2.4.2))(typescript@5.7.3))(eslint@9.16.0(jiti@2.4.2))(typescript@5.7.3)
|
||||
'@typescript-eslint/parser': 8.24.0(eslint@9.16.0(jiti@2.4.2))(typescript@5.7.3)
|
||||
eslint: 9.16.0(jiti@2.4.2)
|
||||
eslint-import-resolver-node: 0.3.9
|
||||
eslint-import-resolver-typescript: 3.7.0(eslint-plugin-import@2.31.0)(eslint@9.16.0(jiti@2.4.2))
|
||||
eslint-plugin-import: 2.31.0(@typescript-eslint/parser@8.24.0(eslint@9.16.0(jiti@2.4.2))(typescript@5.7.3))(eslint-import-resolver-typescript@3.7.0)(eslint@9.16.0(jiti@2.4.2))
|
||||
eslint-import-resolver-typescript: 3.7.0(eslint-plugin-import@2.31.0(@typescript-eslint/parser@8.24.0(eslint@9.22.0(jiti@2.4.2))(typescript@5.7.3))(eslint@9.22.0(jiti@2.4.2)))(eslint@9.16.0(jiti@2.4.2))
|
||||
eslint-plugin-import: 2.31.0(@typescript-eslint/parser@8.24.0(eslint@9.22.0(jiti@2.4.2))(typescript@5.7.3))(eslint-import-resolver-typescript@3.7.0(eslint-plugin-import@2.31.0(@typescript-eslint/parser@8.24.0(eslint@9.22.0(jiti@2.4.2))(typescript@5.7.3))(eslint@9.22.0(jiti@2.4.2)))(eslint@9.16.0(jiti@2.4.2)))(eslint@9.16.0(jiti@2.4.2))
|
||||
eslint-plugin-jsx-a11y: 6.10.2(eslint@9.16.0(jiti@2.4.2))
|
||||
eslint-plugin-react: 7.37.2(eslint@9.16.0(jiti@2.4.2))
|
||||
eslint-plugin-react-hooks: 5.1.0(eslint@9.16.0(jiti@2.4.2))
|
||||
@@ -19769,7 +19882,7 @@ snapshots:
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
|
||||
eslint-import-resolver-typescript@3.7.0(eslint-plugin-import@2.31.0)(eslint@9.16.0(jiti@2.4.2)):
|
||||
eslint-import-resolver-typescript@3.7.0(eslint-plugin-import@2.31.0(@typescript-eslint/parser@8.24.0(eslint@9.22.0(jiti@2.4.2))(typescript@5.7.3))(eslint@9.22.0(jiti@2.4.2)))(eslint@9.16.0(jiti@2.4.2)):
|
||||
dependencies:
|
||||
'@nolyfill/is-core-module': 1.0.39
|
||||
debug: 4.4.0
|
||||
@@ -19781,7 +19894,7 @@ snapshots:
|
||||
is-glob: 4.0.3
|
||||
stable-hash: 0.0.4
|
||||
optionalDependencies:
|
||||
eslint-plugin-import: 2.31.0(@typescript-eslint/parser@8.24.0(eslint@9.16.0(jiti@2.4.2))(typescript@5.7.3))(eslint-import-resolver-typescript@3.7.0)(eslint@9.16.0(jiti@2.4.2))
|
||||
eslint-plugin-import: 2.31.0(@typescript-eslint/parser@8.24.0(eslint@9.22.0(jiti@2.4.2))(typescript@5.7.3))(eslint-import-resolver-typescript@3.7.0)(eslint@9.22.0(jiti@2.4.2))
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
|
||||
@@ -19801,18 +19914,18 @@ snapshots:
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
|
||||
eslint-module-utils@2.12.0(@typescript-eslint/parser@8.24.0(eslint@9.16.0(jiti@2.4.2))(typescript@5.7.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.7.0)(eslint@9.16.0(jiti@2.4.2)):
|
||||
eslint-module-utils@2.12.0(@typescript-eslint/parser@8.24.0(eslint@9.22.0(jiti@2.4.2))(typescript@5.7.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.7.0(eslint-plugin-import@2.31.0(@typescript-eslint/parser@8.24.0(eslint@9.22.0(jiti@2.4.2))(typescript@5.7.3))(eslint@9.22.0(jiti@2.4.2)))(eslint@9.16.0(jiti@2.4.2)))(eslint@9.16.0(jiti@2.4.2)):
|
||||
dependencies:
|
||||
debug: 3.2.7
|
||||
optionalDependencies:
|
||||
'@typescript-eslint/parser': 8.24.0(eslint@9.16.0(jiti@2.4.2))(typescript@5.7.3)
|
||||
'@typescript-eslint/parser': 8.24.0(eslint@9.22.0(jiti@2.4.2))(typescript@5.7.3)
|
||||
eslint: 9.16.0(jiti@2.4.2)
|
||||
eslint-import-resolver-node: 0.3.9
|
||||
eslint-import-resolver-typescript: 3.7.0(eslint-plugin-import@2.31.0)(eslint@9.16.0(jiti@2.4.2))
|
||||
eslint-import-resolver-typescript: 3.7.0(eslint-plugin-import@2.31.0(@typescript-eslint/parser@8.24.0(eslint@9.22.0(jiti@2.4.2))(typescript@5.7.3))(eslint@9.22.0(jiti@2.4.2)))(eslint@9.16.0(jiti@2.4.2))
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
|
||||
eslint-module-utils@2.12.0(@typescript-eslint/parser@8.24.0(eslint@9.22.0(jiti@2.4.2))(typescript@5.7.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.7.0(eslint-plugin-import@2.31.0(@typescript-eslint/parser@8.24.0(eslint@9.22.0(jiti@2.4.2))(typescript@5.7.3))(eslint@9.22.0(jiti@2.4.2)))(eslint@9.22.0(jiti@2.4.2)))(eslint@9.22.0(jiti@2.4.2)):
|
||||
eslint-module-utils@2.12.0(@typescript-eslint/parser@8.24.0(eslint@9.22.0(jiti@2.4.2))(typescript@5.7.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.7.0)(eslint@9.22.0(jiti@2.4.2)):
|
||||
dependencies:
|
||||
debug: 3.2.7
|
||||
optionalDependencies:
|
||||
@@ -19823,7 +19936,7 @@ snapshots:
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
|
||||
eslint-plugin-import@2.31.0(@typescript-eslint/parser@8.24.0(eslint@9.16.0(jiti@2.4.2))(typescript@5.7.3))(eslint-import-resolver-typescript@3.7.0)(eslint@9.16.0(jiti@2.4.2)):
|
||||
eslint-plugin-import@2.31.0(@typescript-eslint/parser@8.24.0(eslint@9.22.0(jiti@2.4.2))(typescript@5.7.3))(eslint-import-resolver-typescript@3.7.0(eslint-plugin-import@2.31.0(@typescript-eslint/parser@8.24.0(eslint@9.22.0(jiti@2.4.2))(typescript@5.7.3))(eslint@9.22.0(jiti@2.4.2)))(eslint@9.16.0(jiti@2.4.2)))(eslint@9.16.0(jiti@2.4.2)):
|
||||
dependencies:
|
||||
'@rtsao/scc': 1.1.0
|
||||
array-includes: 3.1.8
|
||||
@@ -19834,7 +19947,7 @@ snapshots:
|
||||
doctrine: 2.1.0
|
||||
eslint: 9.16.0(jiti@2.4.2)
|
||||
eslint-import-resolver-node: 0.3.9
|
||||
eslint-module-utils: 2.12.0(@typescript-eslint/parser@8.24.0(eslint@9.16.0(jiti@2.4.2))(typescript@5.7.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.7.0)(eslint@9.16.0(jiti@2.4.2))
|
||||
eslint-module-utils: 2.12.0(@typescript-eslint/parser@8.24.0(eslint@9.22.0(jiti@2.4.2))(typescript@5.7.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.7.0(eslint-plugin-import@2.31.0(@typescript-eslint/parser@8.24.0(eslint@9.22.0(jiti@2.4.2))(typescript@5.7.3))(eslint@9.22.0(jiti@2.4.2)))(eslint@9.16.0(jiti@2.4.2)))(eslint@9.16.0(jiti@2.4.2))
|
||||
hasown: 2.0.2
|
||||
is-core-module: 2.16.1
|
||||
is-glob: 4.0.3
|
||||
@@ -19846,7 +19959,7 @@ snapshots:
|
||||
string.prototype.trimend: 1.0.9
|
||||
tsconfig-paths: 3.15.0
|
||||
optionalDependencies:
|
||||
'@typescript-eslint/parser': 8.24.0(eslint@9.16.0(jiti@2.4.2))(typescript@5.7.3)
|
||||
'@typescript-eslint/parser': 8.24.0(eslint@9.22.0(jiti@2.4.2))(typescript@5.7.3)
|
||||
transitivePeerDependencies:
|
||||
- eslint-import-resolver-typescript
|
||||
- eslint-import-resolver-webpack
|
||||
@@ -19863,7 +19976,7 @@ snapshots:
|
||||
doctrine: 2.1.0
|
||||
eslint: 9.22.0(jiti@2.4.2)
|
||||
eslint-import-resolver-node: 0.3.9
|
||||
eslint-module-utils: 2.12.0(@typescript-eslint/parser@8.24.0(eslint@9.22.0(jiti@2.4.2))(typescript@5.7.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.7.0(eslint-plugin-import@2.31.0(@typescript-eslint/parser@8.24.0(eslint@9.22.0(jiti@2.4.2))(typescript@5.7.3))(eslint@9.22.0(jiti@2.4.2)))(eslint@9.22.0(jiti@2.4.2)))(eslint@9.22.0(jiti@2.4.2))
|
||||
eslint-module-utils: 2.12.0(@typescript-eslint/parser@8.24.0(eslint@9.22.0(jiti@2.4.2))(typescript@5.7.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.7.0)(eslint@9.22.0(jiti@2.4.2))
|
||||
hasown: 2.0.2
|
||||
is-core-module: 2.16.1
|
||||
is-glob: 4.0.3
|
||||
@@ -20205,6 +20318,8 @@ snapshots:
|
||||
|
||||
expect-type@1.1.0: {}
|
||||
|
||||
expect-type@1.2.0: {}
|
||||
|
||||
ext-list@2.2.2:
|
||||
dependencies:
|
||||
mime-db: 1.53.0
|
||||
@@ -23533,7 +23648,7 @@ snapshots:
|
||||
transitivePeerDependencies:
|
||||
- encoding
|
||||
|
||||
openai@4.86.0(ws@8.18.0(bufferutil@4.0.9))(zod@3.24.2):
|
||||
openai@4.90.0(ws@8.18.0(bufferutil@4.0.9))(zod@3.24.2):
|
||||
dependencies:
|
||||
'@types/node': 18.19.76
|
||||
'@types/node-fetch': 2.6.12
|
||||
@@ -25238,6 +25353,8 @@ snapshots:
|
||||
|
||||
std-env@3.8.0: {}
|
||||
|
||||
std-env@3.8.1: {}
|
||||
|
||||
stdin-discarder@0.2.2: {}
|
||||
|
||||
stoppable@1.1.0: {}
|
||||
@@ -26217,6 +26334,24 @@ snapshots:
|
||||
- supports-color
|
||||
- terser
|
||||
|
||||
vite-node@3.1.1(@types/node@22.13.5)(lightningcss@1.29.1)(terser@5.38.2):
|
||||
dependencies:
|
||||
cac: 6.7.14
|
||||
debug: 4.4.0
|
||||
es-module-lexer: 1.6.0
|
||||
pathe: 2.0.3
|
||||
vite: 5.4.16(@types/node@22.13.5)(lightningcss@1.29.1)(terser@5.38.2)
|
||||
transitivePeerDependencies:
|
||||
- '@types/node'
|
||||
- less
|
||||
- lightningcss
|
||||
- sass
|
||||
- sass-embedded
|
||||
- stylus
|
||||
- sugarss
|
||||
- supports-color
|
||||
- terser
|
||||
|
||||
vite-plugin-wasm@3.4.1(vite@5.4.16(@types/node@22.13.5)(lightningcss@1.29.1)(terser@5.38.2)):
|
||||
dependencies:
|
||||
vite: 5.4.16(@types/node@22.13.5)(lightningcss@1.29.1)(terser@5.38.2)
|
||||
@@ -26427,6 +26562,44 @@ snapshots:
|
||||
- supports-color
|
||||
- terser
|
||||
|
||||
vitest@3.1.1(@edge-runtime/vm@4.0.4)(@types/debug@4.1.12)(@types/node@22.13.5)(happy-dom@15.11.7)(lightningcss@1.29.1)(msw@2.7.0(@types/node@22.13.5)(typescript@5.7.3))(terser@5.38.2):
|
||||
dependencies:
|
||||
'@vitest/expect': 3.1.1
|
||||
'@vitest/mocker': 3.1.1(msw@2.7.0(@types/node@22.13.5)(typescript@5.7.3))(vite@5.4.16(@types/node@22.13.5)(lightningcss@1.29.1)(terser@5.38.2))
|
||||
'@vitest/pretty-format': 3.1.1
|
||||
'@vitest/runner': 3.1.1
|
||||
'@vitest/snapshot': 3.1.1
|
||||
'@vitest/spy': 3.1.1
|
||||
'@vitest/utils': 3.1.1
|
||||
chai: 5.2.0
|
||||
debug: 4.4.0
|
||||
expect-type: 1.2.0
|
||||
magic-string: 0.30.17
|
||||
pathe: 2.0.3
|
||||
std-env: 3.8.1
|
||||
tinybench: 2.9.0
|
||||
tinyexec: 0.3.2
|
||||
tinypool: 1.0.2
|
||||
tinyrainbow: 2.0.0
|
||||
vite: 5.4.16(@types/node@22.13.5)(lightningcss@1.29.1)(terser@5.38.2)
|
||||
vite-node: 3.1.1(@types/node@22.13.5)(lightningcss@1.29.1)(terser@5.38.2)
|
||||
why-is-node-running: 2.3.0
|
||||
optionalDependencies:
|
||||
'@edge-runtime/vm': 4.0.4
|
||||
'@types/debug': 4.1.12
|
||||
'@types/node': 22.13.5
|
||||
happy-dom: 15.11.7
|
||||
transitivePeerDependencies:
|
||||
- less
|
||||
- lightningcss
|
||||
- msw
|
||||
- sass
|
||||
- sass-embedded
|
||||
- stylus
|
||||
- sugarss
|
||||
- supports-color
|
||||
- terser
|
||||
|
||||
voyageai@0.0.3-1:
|
||||
dependencies:
|
||||
form-data: 4.0.0
|
||||
|
||||
Reference in New Issue
Block a user