diff --git a/packages/core/package.json b/packages/core/package.json index f87dbf0624ec0fb8a195e2b7be48818279af7d2f..0bbb97a06afee979e47da96f5c6244b995f1ae1c 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -4,6 +4,20 @@ "version": "0.0.2", "description": "LlamaIndex Core Module", "exports": { + "./llms": { + "require": { + "types": "./dist/llms/index.d.cts", + "default": "./dist/llms/index.cjs" + }, + "import": { + "types": "./dist/llms/index.d.ts", + "default": "./dist/llms/index.js" + }, + "default": { + "types": "./dist/llms/index.d.ts", + "default": "./dist/llms/index.js" + } + }, "./decorator": { "require": { "types": "./dist/decorator/index.d.cts", @@ -60,6 +74,7 @@ "url": "https://github.com/himself65/LlamaIndexTS.git" }, "devDependencies": { + "ajv": "^8.16.0", "bunchee": "^5.2.1" }, "dependencies": { diff --git a/packages/core/src/global/type.ts b/packages/core/src/global/type.ts new file mode 100644 index 0000000000000000000000000000000000000000..07df3d6219ad62959195a838e2fc3f56720582ed --- /dev/null +++ b/packages/core/src/global/type.ts @@ -0,0 +1,9 @@ +export type UUID = `${string}-${string}-${string}-${string}-${string}`; + +export type JSONValue = string | number | boolean | JSONObject | JSONArray; + +export type JSONObject = { + [key: string]: JSONValue; +}; + +export type JSONArray = Array<JSONValue>; diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts deleted file mode 100644 index 686fbd9e9f94cf13816c8f1898fc8182cdb36b4d..0000000000000000000000000000000000000000 --- a/packages/core/src/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./schema"; diff --git a/packages/core/src/llms/index.ts b/packages/core/src/llms/index.ts new file mode 100644 index 0000000000000000000000000000000000000000..c387fe0872bb695889a7f0db4f058e0f3cd8c04d --- /dev/null +++ b/packages/core/src/llms/index.ts @@ -0,0 +1,31 @@ +export type { + BaseTool, + BaseToolWithCall, + ChatMessage, + ChatResponse, + ChatResponseChunk, + CompletionResponse, + LLM, + LLMChat, + LLMChatParamsBase, + LLMChatParamsNonStreaming, + LLMChatParamsStreaming, + LLMCompletionParamsBase, + LLMCompletionParamsNonStreaming, + LLMCompletionParamsStreaming, + LLMMetadata, + MessageContent, + MessageContentDetail, + MessageContentImageDetail, + MessageContentTextDetail, + MessageType, + PartialToolCall, + TextChatMessage, + ToolCall, + ToolCallLLMMessageOptions, + ToolCallOptions, + ToolMetadata, + ToolOutput, + ToolResult, + ToolResultOptions, +} from "./type"; diff --git a/packages/core/src/llms/type.ts b/packages/core/src/llms/type.ts new file mode 100644 index 0000000000000000000000000000000000000000..cffe627f8ebdc6dd08af32c836f31ee1a6f91741 --- /dev/null +++ b/packages/core/src/llms/type.ts @@ -0,0 +1,245 @@ +import type { Tokenizers } from "@llamaindex/env"; +import type { JSONSchemaType } from "ajv"; +import type { JSONObject, JSONValue } from "../global/type"; + +/** + * @internal + */ +export interface LLMChat< + AdditionalChatOptions extends object = object, + AdditionalMessageOptions extends object = object, +> { + chat( + params: + | LLMChatParamsStreaming<AdditionalChatOptions> + | LLMChatParamsNonStreaming<AdditionalChatOptions>, + ): Promise< + | ChatResponse<AdditionalMessageOptions> + | AsyncIterable<ChatResponseChunk<AdditionalMessageOptions>> + >; +} + +/** + * Unified language model interface + */ +export interface LLM< + AdditionalChatOptions extends object = object, + AdditionalMessageOptions extends object = object, +> extends LLMChat<AdditionalChatOptions> { + metadata: LLMMetadata; + /** + * Get a chat response from the LLM + */ + chat( + params: LLMChatParamsStreaming< + AdditionalChatOptions, + AdditionalMessageOptions + >, + ): Promise<AsyncIterable<ChatResponseChunk>>; + chat( + params: LLMChatParamsNonStreaming< + AdditionalChatOptions, + AdditionalMessageOptions + >, + ): Promise<ChatResponse<AdditionalMessageOptions>>; + + /** + * Get a prompt completion from the LLM + */ + complete( + params: LLMCompletionParamsStreaming, + ): Promise<AsyncIterable<CompletionResponse>>; + complete( + params: LLMCompletionParamsNonStreaming, + ): Promise<CompletionResponse>; +} + +export type MessageType = "user" | "assistant" | "system" | "memory"; + +export type TextChatMessage<AdditionalMessageOptions extends object = object> = + { + content: string; + role: MessageType; + options?: undefined | AdditionalMessageOptions; + }; + +export type ChatMessage<AdditionalMessageOptions extends object = object> = { + content: MessageContent; + role: MessageType; + options?: undefined | AdditionalMessageOptions; +}; + +export interface ChatResponse< + AdditionalMessageOptions extends object = object, +> { + message: ChatMessage<AdditionalMessageOptions>; + /** + * Raw response from the LLM + * + * If LLM response an iterable of chunks, this will be an array of those chunks + */ + raw: object | null; +} + +export type ChatResponseChunk< + AdditionalMessageOptions extends object = object, +> = { + raw: object | null; + delta: string; + options?: undefined | AdditionalMessageOptions; +}; + +export interface CompletionResponse { + text: string; + /** + * Raw response from the LLM + * + * It's possible that this is `null` if the LLM response an iterable of chunks + */ + raw: object | null; +} + +export type LLMMetadata = { + model: string; + temperature: number; + topP: number; + maxTokens?: number; + contextWindow: number; + tokenizer: Tokenizers | undefined; +}; + +export interface LLMChatParamsBase< + AdditionalChatOptions extends object = object, + AdditionalMessageOptions extends object = object, +> { + messages: ChatMessage<AdditionalMessageOptions>[]; + additionalChatOptions?: AdditionalChatOptions; + tools?: BaseTool[]; +} + +export interface LLMChatParamsStreaming< + AdditionalChatOptions extends object = object, + AdditionalMessageOptions extends object = object, +> extends LLMChatParamsBase<AdditionalChatOptions, AdditionalMessageOptions> { + stream: true; +} + +export interface LLMChatParamsNonStreaming< + AdditionalChatOptions extends object = object, + AdditionalMessageOptions extends object = object, +> extends LLMChatParamsBase<AdditionalChatOptions, AdditionalMessageOptions> { + stream?: false; +} + +export interface LLMCompletionParamsBase { + prompt: MessageContent; +} + +export interface LLMCompletionParamsStreaming extends LLMCompletionParamsBase { + stream: true; +} + +export interface LLMCompletionParamsNonStreaming + extends LLMCompletionParamsBase { + stream?: false | null; +} + +export type MessageContentTextDetail = { + type: "text"; + text: string; +}; + +export type MessageContentImageDetail = { + type: "image_url"; + image_url: { url: string }; +}; + +export type MessageContentDetail = + | MessageContentTextDetail + | MessageContentImageDetail; + +/** + * Extended type for the content of a message that allows for multi-modal messages. + */ +export type MessageContent = string | MessageContentDetail[]; + +export type ToolCall = { + name: string; + input: JSONObject; + id: string; +}; + +// happened in streaming response, the tool call is not ready yet +export type PartialToolCall = { + name: string; + id: string; + // input is not ready yet, JSON.parse(input) will throw an error + input: string; +}; + +export type ToolResult = { + id: string; + result: string; + isError: boolean; +}; + +export type ToolCallOptions = { + toolCall: (ToolCall | PartialToolCall)[]; +}; + +export type ToolResultOptions = { + toolResult: ToolResult; +}; + +export type ToolCallLLMMessageOptions = + | ToolResultOptions + | ToolCallOptions + | {}; + +type Known = + | { [key: string]: Known } + | [Known, ...Known[]] + | Known[] + | number + | string + | boolean + | null; + +export type ToolMetadata< + Parameters extends Record<string, unknown> = Record<string, unknown>, +> = { + description: string; + name: string; + /** + * OpenAI uses JSON Schema to describe the parameters that a tool can take. + * @link https://json-schema.org/understanding-json-schema + */ + parameters?: Parameters; +}; + +/** + * Simple Tool interface. Likely to change. + */ +export interface BaseTool<Input = any> { + /** + * This could be undefined if the implementation is not provided, + * which might be the case when communicating with a llm. + * + * @return {JSONValue | Promise<JSONValue>} The output of the tool. + */ + call?: (input: Input) => JSONValue | Promise<JSONValue>; + metadata: // if user input any, we cannot check the schema + Input extends Known ? ToolMetadata<JSONSchemaType<Input>> : ToolMetadata; +} + +export type BaseToolWithCall<Input = any> = Omit<BaseTool<Input>, "call"> & { + call: NonNullable<Pick<BaseTool<Input>, "call">["call"]>; +}; + +export type ToolOutput = { + tool: BaseTool | undefined; + // all of existing function calling LLMs only support object input + input: JSONObject; + output: JSONValue; + isError: boolean; +}; diff --git a/packages/core/src/schema/zod.ts b/packages/core/src/schema/zod.ts index 8ea21ba3d98687c8c3de170b8e05c07a7a266479..94cd4d2a461657cd6396e01b0e647bd09b411214 100644 --- a/packages/core/src/schema/zod.ts +++ b/packages/core/src/schema/zod.ts @@ -1,5 +1,7 @@ import { z } from "zod"; +export const anyFunctionSchema = z.function(z.tuple([]).rest(z.any()), z.any()); + export const toolMetadataSchema = z.object({ description: z.string(), name: z.string(), @@ -7,7 +9,7 @@ export const toolMetadataSchema = z.object({ }); export const baseToolSchema = z.object({ - call: z.optional(z.function()), + call: anyFunctionSchema.optional(), metadata: toolMetadataSchema, }); diff --git a/packages/llamaindex/e2e/examples/nextjs-agent/src/actions/index.tsx b/packages/llamaindex/e2e/examples/nextjs-agent/src/actions/index.tsx index b092fd0b89a25db02ae64f06b4abf918c0439173..b71e52a928f4241ee28280fa63bce6e9a612c7d1 100644 --- a/packages/llamaindex/e2e/examples/nextjs-agent/src/actions/index.tsx +++ b/packages/llamaindex/e2e/examples/nextjs-agent/src/actions/index.tsx @@ -1,7 +1,7 @@ "use server"; import { createStreamableUI } from "ai/rsc"; +import type { ChatMessage } from "llamaindex"; import { OpenAIAgent } from "llamaindex"; -import type { ChatMessage } from "llamaindex/llm/types"; export async function chatWithAgent( question: string, diff --git a/packages/llamaindex/e2e/fixtures/llm/openai.ts b/packages/llamaindex/e2e/fixtures/llm/openai.ts index 045cc085570845e3049939f12401a875740cf6ab..30d8b2cdb62ce4c926b05accaf9f9304fa870b19 100644 --- a/packages/llamaindex/e2e/fixtures/llm/openai.ts +++ b/packages/llamaindex/e2e/fixtures/llm/openai.ts @@ -7,7 +7,7 @@ import type { LLMChatParamsStreaming, LLMCompletionParamsNonStreaming, LLMCompletionParamsStreaming, -} from "llamaindex/llm/types"; +} from "llamaindex"; import { extractText } from "llamaindex/llm/utils"; import { deepStrictEqual, strictEqual } from "node:assert"; import { llmCompleteMockStorage } from "../../node/utils.js"; diff --git a/packages/llamaindex/src/ChatHistory.ts b/packages/llamaindex/src/ChatHistory.ts index 7d0093e51e8c084f4d43892866969d7b3e6f22f4..c6423b9e8edf03882143229c8a4cf4fe503cd2f1 100644 --- a/packages/llamaindex/src/ChatHistory.ts +++ b/packages/llamaindex/src/ChatHistory.ts @@ -1,8 +1,8 @@ +import type { ChatMessage, LLM, MessageType } from "@llamaindex/core/llms"; import { tokenizers, type Tokenizer } from "@llamaindex/env"; import type { SummaryPrompt } from "./Prompt.js"; import { defaultSummaryPrompt, messagesToHistoryStr } from "./Prompt.js"; import { OpenAI } from "./llm/openai.js"; -import type { ChatMessage, LLM, MessageType } from "./llm/types.js"; import { extractText } from "./llm/utils.js"; /** diff --git a/packages/llamaindex/src/EngineResponse.ts b/packages/llamaindex/src/EngineResponse.ts index dc2a3b4366fde2176c4a6df2e739bc0603b63c59..543f33f6b5d9ac4302fc37d1bfa6a0950e727996 100644 --- a/packages/llamaindex/src/EngineResponse.ts +++ b/packages/llamaindex/src/EngineResponse.ts @@ -1,9 +1,9 @@ -import type { NodeWithScore } from "@llamaindex/core/schema"; import type { ChatMessage, ChatResponse, ChatResponseChunk, -} from "./llm/types.js"; +} from "@llamaindex/core/llms"; +import type { NodeWithScore } from "@llamaindex/core/schema"; import { extractText } from "./llm/utils.js"; export class EngineResponse implements ChatResponse, ChatResponseChunk { diff --git a/packages/llamaindex/src/Prompt.ts b/packages/llamaindex/src/Prompt.ts index ef344bd17f492f61e0ffb858c9e275eca1ac965e..0763df484abc8088e624cf43147aeeeb11f0c653 100644 --- a/packages/llamaindex/src/Prompt.ts +++ b/packages/llamaindex/src/Prompt.ts @@ -1,6 +1,5 @@ +import type { ChatMessage, ToolMetadata } from "@llamaindex/core/llms"; import type { SubQuestion } from "./engines/query/types.js"; -import type { ChatMessage } from "./llm/types.js"; -import type { ToolMetadata } from "./types.js"; /** * A SimplePrompt is a function that takes a dictionary of inputs and returns a string. diff --git a/packages/llamaindex/src/QuestionGenerator.ts b/packages/llamaindex/src/QuestionGenerator.ts index 74c3505641be1ed5dd9e48fa119014f0827453ca..e3a190d4e6881a9d3b2f4dfc350c0a3479b23cb5 100644 --- a/packages/llamaindex/src/QuestionGenerator.ts +++ b/packages/llamaindex/src/QuestionGenerator.ts @@ -1,3 +1,4 @@ +import type { LLM, ToolMetadata } from "@llamaindex/core/llms"; import { SubQuestionOutputParser } from "./OutputParser.js"; import type { SubQuestionPrompt } from "./Prompt.js"; import { buildToolsText, defaultSubQuestionPrompt } from "./Prompt.js"; @@ -6,13 +7,8 @@ import type { SubQuestion, } from "./engines/query/types.js"; import { OpenAI } from "./llm/openai.js"; -import type { LLM } from "./llm/types.js"; import { PromptMixin } from "./prompts/index.js"; -import type { - BaseOutputParser, - StructuredOutput, - ToolMetadata, -} from "./types.js"; +import type { BaseOutputParser, StructuredOutput } from "./types.js"; /** * LLMQuestionGenerator uses the LLM to generate new questions for the LLM using tools and a user query. diff --git a/packages/llamaindex/src/ServiceContext.ts b/packages/llamaindex/src/ServiceContext.ts index 0686d2a0b69a7b198218799e8b1321b0e28d2a14..dfb3f8fa41e0c47431bfe377915a6e6274c490df 100644 --- a/packages/llamaindex/src/ServiceContext.ts +++ b/packages/llamaindex/src/ServiceContext.ts @@ -1,8 +1,8 @@ +import type { LLM } from "@llamaindex/core/llms"; import { PromptHelper } from "./PromptHelper.js"; import { OpenAIEmbedding } from "./embeddings/OpenAIEmbedding.js"; import type { BaseEmbedding } from "./embeddings/types.js"; import { OpenAI } from "./llm/openai.js"; -import type { LLM } from "./llm/types.js"; import { SimpleNodeParser } from "./nodeParsers/SimpleNodeParser.js"; import type { NodeParser } from "./nodeParsers/types.js"; diff --git a/packages/llamaindex/src/Settings.ts b/packages/llamaindex/src/Settings.ts index 32ae2156bbeac7c24e1a933c22989336f5be8555..12513125d5efa067849853d4c8592c5d98758afc 100644 --- a/packages/llamaindex/src/Settings.ts +++ b/packages/llamaindex/src/Settings.ts @@ -5,6 +5,7 @@ import { OpenAI } from "./llm/openai.js"; import { PromptHelper } from "./PromptHelper.js"; import { SimpleNodeParser } from "./nodeParsers/SimpleNodeParser.js"; +import type { LLM } from "@llamaindex/core/llms"; import { AsyncLocalStorage, getEnv } from "@llamaindex/env"; import type { ServiceContext } from "./ServiceContext.js"; import type { BaseEmbedding } from "./embeddings/types.js"; @@ -18,7 +19,6 @@ import { setEmbeddedModel, withEmbeddedModel, } from "./internal/settings/EmbedModel.js"; -import type { LLM } from "./llm/types.js"; import type { NodeParser } from "./nodeParsers/types.js"; export type PromptConfig = { diff --git a/packages/llamaindex/src/agent/base.ts b/packages/llamaindex/src/agent/base.ts index 49692dc856d496cca4b9ba3396267a66714dec8e..7d1eea8a96aa10775e1a58cb00ef0cc9cf2ba353 100644 --- a/packages/llamaindex/src/agent/base.ts +++ b/packages/llamaindex/src/agent/base.ts @@ -1,3 +1,10 @@ +import type { + BaseToolWithCall, + ChatMessage, + LLM, + MessageContent, + ToolOutput, +} from "@llamaindex/core/llms"; import { ReadableStream, TransformStream, randomUUID } from "@llamaindex/env"; import { ChatHistory } from "../ChatHistory.js"; import { EngineResponse } from "../EngineResponse.js"; @@ -11,9 +18,7 @@ import { wrapEventCaller } from "../internal/context/EventCaller.js"; import { consoleLogger, emptyLogger } from "../internal/logger.js"; import { getCallbackManager } from "../internal/settings/CallbackManager.js"; import { isAsyncIterable } from "../internal/utils.js"; -import type { ChatMessage, LLM, MessageContent } from "../llm/index.js"; import { ObjectRetriever } from "../objects/index.js"; -import type { BaseToolWithCall, ToolOutput } from "../types.js"; import type { AgentTaskContext, TaskHandler, @@ -229,13 +234,12 @@ export abstract class AgentRunner< const { llm, getTools, stream } = step.context; const lastMessage = step.context.store.messages.at(-1)!.content; const tools = await getTools(lastMessage); - const response = await llm.chat({ - // @ts-expect-error - stream, - tools, - messages: [...step.context.store.messages], - }); if (!stream) { + const response = await llm.chat({ + stream, + tools, + messages: [...step.context.store.messages], + }); await stepTools<LLM>({ response, tools, @@ -243,6 +247,11 @@ export abstract class AgentRunner< enqueueOutput, }); } else { + const response = await llm.chat({ + stream, + tools, + messages: [...step.context.store.messages], + }); await stepToolsStreaming<LLM>({ response, tools, diff --git a/packages/llamaindex/src/agent/llm.ts b/packages/llamaindex/src/agent/llm.ts index 9e4295cbe8fc3672a0429c79ba49e6eab7180a86..6292c1cd71e4261fada4284765a0178617430f2e 100644 --- a/packages/llamaindex/src/agent/llm.ts +++ b/packages/llamaindex/src/agent/llm.ts @@ -1,7 +1,6 @@ -import type { LLM } from "../llm/index.js"; +import type { BaseToolWithCall, LLM } from "@llamaindex/core/llms"; import { ObjectRetriever } from "../objects/index.js"; import { Settings } from "../Settings.js"; -import type { BaseToolWithCall } from "../types.js"; import { AgentRunner, AgentWorker, type AgentParamsBase } from "./base.js"; import { validateAgentParams } from "./utils.js"; diff --git a/packages/llamaindex/src/agent/react.ts b/packages/llamaindex/src/agent/react.ts index fabef84c456387e70272de1546afdf7307903e04..51ade05bac25c39cdf0ce39b17a15a4df4cf89f7 100644 --- a/packages/llamaindex/src/agent/react.ts +++ b/packages/llamaindex/src/agent/react.ts @@ -1,18 +1,19 @@ +import type { + BaseTool, + ChatMessage, + ChatResponse, + ChatResponseChunk, + LLM, +} from "@llamaindex/core/llms"; import { randomUUID, ReadableStream } from "@llamaindex/env"; import { getReACTAgentSystemHeader } from "../internal/prompt/react.js"; import { isAsyncIterable, stringifyJSONToMessageContent, } from "../internal/utils.js"; -import { - type ChatMessage, - type ChatResponse, - type ChatResponseChunk, - type LLM, -} from "../llm/index.js"; import { extractText } from "../llm/utils.js"; import { Settings } from "../Settings.js"; -import type { BaseTool, JSONObject, JSONValue } from "../types.js"; +import type { JSONObject, JSONValue } from "../types.js"; import { AgentRunner, AgentWorker, type AgentParamsBase } from "./base.js"; import type { TaskHandler } from "./types.js"; import { diff --git a/packages/llamaindex/src/agent/types.ts b/packages/llamaindex/src/agent/types.ts index 22d562c1a88a599cb0d05f44b67b7509cf6f7903..45ec942b6b1af9ad51d85a45a4aef9c8958e5fc7 100644 --- a/packages/llamaindex/src/agent/types.ts +++ b/packages/llamaindex/src/agent/types.ts @@ -1,14 +1,16 @@ -import { ReadableStream } from "@llamaindex/env"; -import type { Logger } from "../internal/logger.js"; -import type { BaseEvent } from "../internal/type.js"; import type { + BaseToolWithCall, ChatMessage, ChatResponse, ChatResponseChunk, LLM, MessageContent, -} from "../llm/types.js"; -import type { BaseToolWithCall, ToolOutput, UUID } from "../types.js"; + ToolOutput, +} from "@llamaindex/core/llms"; +import { ReadableStream } from "@llamaindex/env"; +import type { Logger } from "../internal/logger.js"; +import type { BaseEvent } from "../internal/type.js"; +import type { UUID } from "../types.js"; export type AgentTaskContext< Model extends LLM, diff --git a/packages/llamaindex/src/agent/utils.ts b/packages/llamaindex/src/agent/utils.ts index d3a41b5138e4411db91785595f03f5790805c189..8bf49abc8a72da55603a2b929ce860e53b9fc7c1 100644 --- a/packages/llamaindex/src/agent/utils.ts +++ b/packages/llamaindex/src/agent/utils.ts @@ -1,3 +1,15 @@ +import type { + BaseTool, + ChatMessage, + ChatResponse, + ChatResponseChunk, + LLM, + PartialToolCall, + TextChatMessage, + ToolCall, + ToolCallLLMMessageOptions, + ToolOutput, +} from "@llamaindex/core/llms"; import { baseToolWithCallSchema } from "@llamaindex/core/schema"; import { ReadableStream } from "@llamaindex/env"; import { z } from "zod"; @@ -8,17 +20,7 @@ import { prettifyError, stringifyJSONToMessageContent, } from "../internal/utils.js"; -import type { - ChatMessage, - ChatResponse, - ChatResponseChunk, - LLM, - PartialToolCall, - TextChatMessage, - ToolCall, - ToolCallLLMMessageOptions, -} from "../llm/index.js"; -import type { BaseTool, JSONObject, JSONValue, ToolOutput } from "../types.js"; +import type { JSONObject, JSONValue } from "../types.js"; import type { AgentParamsBase } from "./base.js"; import type { TaskHandler } from "./types.js"; @@ -31,10 +33,12 @@ type StepToolsResponseParams<Model extends LLM> = { >[1]; }; -type StepToolsStreamingResponseParams<Model extends LLM> = - StepToolsResponseParams<Model> & { - response: AsyncIterable<ChatResponseChunk<ToolCallLLMMessageOptions>>; - }; +type StepToolsStreamingResponseParams<Model extends LLM> = Omit< + StepToolsResponseParams<Model>, + "response" +> & { + response: AsyncIterable<ChatResponseChunk<ToolCallLLMMessageOptions>>; +}; // #TODO stepTools and stepToolsStreaming should be moved to a better abstraction @@ -83,7 +87,7 @@ export async function stepToolsStreaming<Model extends LLM>({ } } - // If there are toolCalls but they didn't get read into the stream, used for Gemini + // If there are toolCalls, but they didn't get read into the stream, used for Gemini if (!toolCalls.size && value.options && "toolCall" in value.options) { value.options.toolCall.forEach((toolCall) => { toolCalls.set(toolCall.id, toolCall); diff --git a/packages/llamaindex/src/callbacks/CallbackManager.ts b/packages/llamaindex/src/callbacks/CallbackManager.ts index a304c45fbecb4f2aa821c9cc50c927012a21e5eb..e37617245425f0f74e67ec57567ae3a074de97c1 100644 --- a/packages/llamaindex/src/callbacks/CallbackManager.ts +++ b/packages/llamaindex/src/callbacks/CallbackManager.ts @@ -1,4 +1,5 @@ import type { Anthropic } from "@anthropic-ai/sdk"; +import type { MessageContent } from "@llamaindex/core/llms"; import type { NodeWithScore } from "@llamaindex/core/schema"; import { CustomEvent } from "@llamaindex/env"; import type { AgentEndEvent, AgentStartEvent } from "../agent/types.js"; @@ -12,7 +13,6 @@ import type { LLMStreamEvent, LLMToolCallEvent, LLMToolResultEvent, - MessageContent, RetrievalEndEvent, RetrievalStartEvent, } from "../llm/types.js"; diff --git a/packages/llamaindex/src/embeddings/DeepInfraEmbedding.ts b/packages/llamaindex/src/embeddings/DeepInfraEmbedding.ts index 0cd9366c6c17e96f09689b0b4859a39091466161..c3c03c6fe32c7b75e0f13415eafdb6ac85c369ae 100644 --- a/packages/llamaindex/src/embeddings/DeepInfraEmbedding.ts +++ b/packages/llamaindex/src/embeddings/DeepInfraEmbedding.ts @@ -1,5 +1,5 @@ +import type { MessageContentDetail } from "@llamaindex/core/llms"; import { getEnv } from "@llamaindex/env"; -import type { MessageContentDetail } from "../llm/index.js"; import { extractSingleText } from "../llm/utils.js"; import { BaseEmbedding } from "./types.js"; diff --git a/packages/llamaindex/src/embeddings/MultiModalEmbedding.ts b/packages/llamaindex/src/embeddings/MultiModalEmbedding.ts index 88cd6ca6937425a1cbd63c9e66039c84c520c010..aabc4337289343b791d9feefb5225c304d8433bb 100644 --- a/packages/llamaindex/src/embeddings/MultiModalEmbedding.ts +++ b/packages/llamaindex/src/embeddings/MultiModalEmbedding.ts @@ -1,3 +1,4 @@ +import type { MessageContentDetail } from "@llamaindex/core/llms"; import { ImageNode, MetadataMode, @@ -6,7 +7,6 @@ import { type BaseNode, type ImageType, } from "@llamaindex/core/schema"; -import type { MessageContentDetail } from "../llm/types.js"; import { extractImage, extractSingleText } from "../llm/utils.js"; import { BaseEmbedding, batchEmbeddings } from "./types.js"; diff --git a/packages/llamaindex/src/embeddings/types.ts b/packages/llamaindex/src/embeddings/types.ts index a69e01fec44be78a464c669a710222df833f95d3..de32669e972243fcad62ace704caaef941cf6685 100644 --- a/packages/llamaindex/src/embeddings/types.ts +++ b/packages/llamaindex/src/embeddings/types.ts @@ -1,8 +1,8 @@ +import type { MessageContentDetail } from "@llamaindex/core/llms"; import type { BaseNode } from "@llamaindex/core/schema"; import { MetadataMode } from "@llamaindex/core/schema"; import { type Tokenizers } from "@llamaindex/env"; import type { TransformComponent } from "../ingestion/types.js"; -import type { MessageContentDetail } from "../llm/types.js"; import { extractSingleText } from "../llm/utils.js"; import { truncateMaxTokens } from "./tokenizer.js"; import { SimilarityType, similarity } from "./utils.js"; diff --git a/packages/llamaindex/src/engines/chat/CondenseQuestionChatEngine.ts b/packages/llamaindex/src/engines/chat/CondenseQuestionChatEngine.ts index adf099dcd718b273174de5b9881b5b82e380fddd..357088e978eb6132433b5a6cba7fd0ab26ae9c80 100644 --- a/packages/llamaindex/src/engines/chat/CondenseQuestionChatEngine.ts +++ b/packages/llamaindex/src/engines/chat/CondenseQuestionChatEngine.ts @@ -1,3 +1,4 @@ +import type { ChatMessage, LLM } from "@llamaindex/core/llms"; import type { ChatHistory } from "../../ChatHistory.js"; import { getHistory } from "../../ChatHistory.js"; import type { EngineResponse } from "../../EngineResponse.js"; @@ -9,7 +10,6 @@ import { import type { ServiceContext } from "../../ServiceContext.js"; import { llmFromSettingsOrContext } from "../../Settings.js"; import { wrapEventCaller } from "../../internal/context/EventCaller.js"; -import type { ChatMessage, LLM } from "../../llm/index.js"; import { extractText, streamReducer } from "../../llm/utils.js"; import { PromptMixin } from "../../prompts/index.js"; import type { QueryEngine } from "../../types.js"; diff --git a/packages/llamaindex/src/engines/chat/ContextChatEngine.ts b/packages/llamaindex/src/engines/chat/ContextChatEngine.ts index dcd90d219205d646f786fa0d7264060016d1b2b7..6403c059599a7362839c8708ffb3eb76672ff3fa 100644 --- a/packages/llamaindex/src/engines/chat/ContextChatEngine.ts +++ b/packages/llamaindex/src/engines/chat/ContextChatEngine.ts @@ -1,3 +1,9 @@ +import type { + ChatMessage, + LLM, + MessageContent, + MessageType, +} from "@llamaindex/core/llms"; import type { ChatHistory } from "../../ChatHistory.js"; import { getHistory } from "../../ChatHistory.js"; import { EngineResponse } from "../../EngineResponse.js"; @@ -5,8 +11,6 @@ import type { ContextSystemPrompt } from "../../Prompt.js"; import type { BaseRetriever } from "../../Retriever.js"; import { Settings } from "../../Settings.js"; import { wrapEventCaller } from "../../internal/context/EventCaller.js"; -import type { ChatMessage, LLM } from "../../llm/index.js"; -import type { MessageContent, MessageType } from "../../llm/types.js"; import { extractText, streamConverter, diff --git a/packages/llamaindex/src/engines/chat/DefaultContextGenerator.ts b/packages/llamaindex/src/engines/chat/DefaultContextGenerator.ts index 095bef1743c97fee7c21c942ac159bf562c4d55c..39839080044fe1aeb169c90baa49a27f89a72209 100644 --- a/packages/llamaindex/src/engines/chat/DefaultContextGenerator.ts +++ b/packages/llamaindex/src/engines/chat/DefaultContextGenerator.ts @@ -1,10 +1,10 @@ +import type { MessageContent, MessageType } from "@llamaindex/core/llms"; import { type NodeWithScore } from "@llamaindex/core/schema"; +import type { BaseNodePostprocessor } from "../../postprocessors/index.js"; import type { ContextSystemPrompt } from "../../Prompt.js"; import { defaultContextSystemPrompt } from "../../Prompt.js"; -import type { BaseRetriever } from "../../Retriever.js"; -import type { MessageContent, MessageType } from "../../llm/types.js"; -import type { BaseNodePostprocessor } from "../../postprocessors/index.js"; import { PromptMixin } from "../../prompts/index.js"; +import type { BaseRetriever } from "../../Retriever.js"; import { createMessageContent } from "../../synthesizers/utils.js"; import type { Context, ContextGenerator } from "./types.js"; diff --git a/packages/llamaindex/src/engines/chat/SimpleChatEngine.ts b/packages/llamaindex/src/engines/chat/SimpleChatEngine.ts index 248831e0bbeb742154883cd78c3cc37d646e8344..fcb934e00903840b2d17df3721c196e9bce02c09 100644 --- a/packages/llamaindex/src/engines/chat/SimpleChatEngine.ts +++ b/packages/llamaindex/src/engines/chat/SimpleChatEngine.ts @@ -1,9 +1,9 @@ +import type { LLM } from "@llamaindex/core/llms"; import type { ChatHistory } from "../../ChatHistory.js"; import { getHistory } from "../../ChatHistory.js"; import { EngineResponse } from "../../EngineResponse.js"; import { Settings } from "../../Settings.js"; import { wrapEventCaller } from "../../internal/context/EventCaller.js"; -import type { LLM } from "../../llm/index.js"; import { streamConverter, streamReducer } from "../../llm/utils.js"; import type { ChatEngine, diff --git a/packages/llamaindex/src/engines/chat/types.ts b/packages/llamaindex/src/engines/chat/types.ts index e84128fca7f7dbb2a393b8d2a8021a561aed0041..26286084f4daafd881828d8cb62cc0effc2b5ea4 100644 --- a/packages/llamaindex/src/engines/chat/types.ts +++ b/packages/llamaindex/src/engines/chat/types.ts @@ -1,8 +1,7 @@ +import type { ChatMessage, MessageContent } from "@llamaindex/core/llms"; import type { NodeWithScore } from "@llamaindex/core/schema"; import type { ChatHistory } from "../../ChatHistory.js"; import type { EngineResponse } from "../../EngineResponse.js"; -import type { ChatMessage } from "../../llm/index.js"; -import type { MessageContent } from "../../llm/types.js"; /** * Represents the base parameters for ChatEngine. diff --git a/packages/llamaindex/src/engines/query/SubQuestionQueryEngine.ts b/packages/llamaindex/src/engines/query/SubQuestionQueryEngine.ts index 432a25a45f6c267e9ca411fd1d550d7154d3f841..34f3912efdf6c658606fca8129b2ab1f2b23d930 100644 --- a/packages/llamaindex/src/engines/query/SubQuestionQueryEngine.ts +++ b/packages/llamaindex/src/engines/query/SubQuestionQueryEngine.ts @@ -11,13 +11,12 @@ import { } from "../../synthesizers/index.js"; import type { - BaseTool, QueryEngine, QueryEngineParamsNonStreaming, QueryEngineParamsStreaming, - ToolMetadata, } from "../../types.js"; +import type { BaseTool, ToolMetadata } from "@llamaindex/core/llms"; import { wrapEventCaller } from "../../internal/context/EventCaller.js"; import type { BaseQuestionGenerator, SubQuestion } from "./types.js"; diff --git a/packages/llamaindex/src/engines/query/types.ts b/packages/llamaindex/src/engines/query/types.ts index 88384631689ee3960cd75db1971c655fff4ab10a..e0e27b90c9e1f7eec9c2217d8bdf5f4d91af7301 100644 --- a/packages/llamaindex/src/engines/query/types.ts +++ b/packages/llamaindex/src/engines/query/types.ts @@ -1,4 +1,4 @@ -import type { ToolMetadata } from "../../types.js"; +import type { ToolMetadata } from "@llamaindex/core/llms"; /** * QuestionGenerators generate new questions for the LLM using tools and a user query. diff --git a/packages/llamaindex/src/evaluation/Correctness.ts b/packages/llamaindex/src/evaluation/Correctness.ts index f250959e8a15e70b96e1e230c2560977e096496a..acb177395b243d1d7c5a37372f69ae856da27ff1 100644 --- a/packages/llamaindex/src/evaluation/Correctness.ts +++ b/packages/llamaindex/src/evaluation/Correctness.ts @@ -1,9 +1,9 @@ +import type { ChatMessage, LLM } from "@llamaindex/core/llms"; import { MetadataMode } from "@llamaindex/core/schema"; -import type { ServiceContext } from "../ServiceContext.js"; -import { llmFromSettingsOrContext } from "../Settings.js"; -import type { ChatMessage, LLM } from "../llm/types.js"; import { extractText } from "../llm/utils.js"; import { PromptMixin } from "../prompts/Mixin.js"; +import type { ServiceContext } from "../ServiceContext.js"; +import { llmFromSettingsOrContext } from "../Settings.js"; import type { CorrectnessSystemPrompt } from "./prompts.js"; import { defaultCorrectnessSystemPrompt, diff --git a/packages/llamaindex/src/extractors/MetadataExtractors.ts b/packages/llamaindex/src/extractors/MetadataExtractors.ts index 1492c916305b61721ff903346f2fdc68c408f5de..5ab760209c9a173aa57ebd57900aebed76b06b77 100644 --- a/packages/llamaindex/src/extractors/MetadataExtractors.ts +++ b/packages/llamaindex/src/extractors/MetadataExtractors.ts @@ -1,6 +1,6 @@ +import type { LLM } from "@llamaindex/core/llms"; import type { BaseNode } from "@llamaindex/core/schema"; import { MetadataMode, TextNode } from "@llamaindex/core/schema"; -import type { LLM } from "../llm/index.js"; import { OpenAI } from "../llm/index.js"; import { defaultKeywordExtractorPromptTemplate, diff --git a/packages/llamaindex/src/index.edge.ts b/packages/llamaindex/src/index.edge.ts index acde625236963b302f477659db3b85bf3910f02e..6e060b6030d9680b60d084b57cce0a78d8f88679 100644 --- a/packages/llamaindex/src/index.edge.ts +++ b/packages/llamaindex/src/index.edge.ts @@ -1,3 +1,4 @@ +export * from "@llamaindex/core/llms"; export * from "@llamaindex/core/schema"; export * from "./agent/index.js"; export * from "./callbacks/CallbackManager.js"; diff --git a/packages/llamaindex/src/indices/keyword/index.ts b/packages/llamaindex/src/indices/keyword/index.ts index d06caf56d3bd3943f53d908ee64f34503bfd4ab8..1d8f4f4b2248f146eebd9eaf21aaa7c921025391 100644 --- a/packages/llamaindex/src/indices/keyword/index.ts +++ b/packages/llamaindex/src/indices/keyword/index.ts @@ -31,8 +31,8 @@ import { simpleExtractKeywords, } from "./utils.js"; +import type { LLM } from "@llamaindex/core/llms"; import { llmFromSettingsOrContext } from "../../Settings.js"; -import type { LLM } from "../../llm/types.js"; import { extractText } from "../../llm/utils.js"; export interface KeywordIndexOptions { diff --git a/packages/llamaindex/src/indices/vectorStore/index.ts b/packages/llamaindex/src/indices/vectorStore/index.ts index 92cce3bf44be136b83b0394aa2b1c094f2954f74..4eadc0d367498fdd7fa0c851d75a119bb5bb7e29 100644 --- a/packages/llamaindex/src/indices/vectorStore/index.ts +++ b/packages/llamaindex/src/indices/vectorStore/index.ts @@ -1,3 +1,4 @@ +import type { MessageContent } from "@llamaindex/core/llms"; import { ImageNode, ModalityType, @@ -23,7 +24,6 @@ import { } from "../../ingestion/strategies/index.js"; import { wrapEventCaller } from "../../internal/context/EventCaller.js"; import { getCallbackManager } from "../../internal/settings/CallbackManager.js"; -import type { MessageContent } from "../../llm/types.js"; import type { BaseNodePostprocessor } from "../../postprocessors/types.js"; import type { StorageContext } from "../../storage/StorageContext.js"; import { storageContextFromDefaults } from "../../storage/StorageContext.js"; diff --git a/packages/llamaindex/src/internal/prompt/react.ts b/packages/llamaindex/src/internal/prompt/react.ts index 3f4450b91b3aa781a12c598f0618a3c7e3d303b4..eb36d765a2dd366d2acd6c029f6aa8436a0899e8 100644 --- a/packages/llamaindex/src/internal/prompt/react.ts +++ b/packages/llamaindex/src/internal/prompt/react.ts @@ -1,4 +1,4 @@ -import type { BaseTool } from "../../types.js"; +import type { BaseTool } from "@llamaindex/core/llms"; export const getReACTAgentSystemHeader = (tools: BaseTool[]) => { const description = tools diff --git a/packages/llamaindex/src/llm/anthropic.ts b/packages/llamaindex/src/llm/anthropic.ts index 7ee5362000f0021ecb2bcf2c4be16407847932f2..19aa677cf295e2714232ed1159b109d819084ada 100644 --- a/packages/llamaindex/src/llm/anthropic.ts +++ b/packages/llamaindex/src/llm/anthropic.ts @@ -17,18 +17,18 @@ import type { ImageBlockParam, MessageParam, } from "@anthropic-ai/sdk/resources/messages"; -import { getEnv } from "@llamaindex/env"; -import _ from "lodash"; -import type { BaseTool } from "../types.js"; -import { ToolCallLLM } from "./base.js"; import type { + BaseTool, ChatMessage, ChatResponse, ChatResponseChunk, LLMChatParamsNonStreaming, LLMChatParamsStreaming, ToolCallLLMMessageOptions, -} from "./types.js"; +} from "@llamaindex/core/llms"; +import { getEnv } from "@llamaindex/env"; +import _ from "lodash"; +import { ToolCallLLM } from "./base.js"; import { extractText, wrapLLMEvent } from "./utils.js"; export class AnthropicSession { diff --git a/packages/llamaindex/src/llm/base.ts b/packages/llamaindex/src/llm/base.ts index 8db28bc9b1ac1281b3b9603bd653fc3fb23fd115..e5633667ac8af63456deac79cab8d25602c37ca1 100644 --- a/packages/llamaindex/src/llm/base.ts +++ b/packages/llamaindex/src/llm/base.ts @@ -9,7 +9,7 @@ import type { LLMCompletionParamsStreaming, LLMMetadata, ToolCallLLMMessageOptions, -} from "./types.js"; +} from "@llamaindex/core/llms"; import { extractText, streamConverter } from "./utils.js"; export abstract class BaseLLM< diff --git a/packages/llamaindex/src/llm/gemini/base.ts b/packages/llamaindex/src/llm/gemini/base.ts index 458f631cf0683f9f106c86bb5049f0469f18db99..994a8d821eb393229b31077ea79ed97baf7b74fb 100644 --- a/packages/llamaindex/src/llm/gemini/base.ts +++ b/packages/llamaindex/src/llm/gemini/base.ts @@ -7,8 +7,6 @@ import { type GenerateContentStreamResult as GoogleStreamGenerateContentResult, } from "@google/generative-ai"; -import { getEnv, randomUUID } from "@llamaindex/env"; -import { ToolCallLLM } from "../base.js"; import type { CompletionResponse, LLMCompletionParamsNonStreaming, @@ -16,7 +14,9 @@ import type { LLMMetadata, ToolCall, ToolCallLLMMessageOptions, -} from "../types.js"; +} from "@llamaindex/core/llms"; +import { getEnv, randomUUID } from "@llamaindex/env"; +import { ToolCallLLM } from "../base.js"; import { streamConverter, wrapLLMEvent } from "../utils.js"; import { GEMINI_BACKENDS, diff --git a/packages/llamaindex/src/llm/gemini/types.ts b/packages/llamaindex/src/llm/gemini/types.ts index f602ee83b8950d3fc084d67143bbb60d53e14501..58bc65648b314a0681d73477fada7bcbaa1f3ad3 100644 --- a/packages/llamaindex/src/llm/gemini/types.ts +++ b/packages/llamaindex/src/llm/gemini/types.ts @@ -33,7 +33,7 @@ import type { LLMChatParamsStreaming, ToolCall, ToolCallLLMMessageOptions, -} from "../types.js"; +} from "@llamaindex/core/llms"; export enum GEMINI_BACKENDS { GOOGLE = "google", diff --git a/packages/llamaindex/src/llm/gemini/utils.ts b/packages/llamaindex/src/llm/gemini/utils.ts index fb75cbeab5b8df135e6ff0da39f85f8f1376ea0e..50ad3b1bcae8e7a786b36138faf060b0fd6a43da 100644 --- a/packages/llamaindex/src/llm/gemini/utils.ts +++ b/packages/llamaindex/src/llm/gemini/utils.ts @@ -7,14 +7,14 @@ import { } from "@google/generative-ai"; import { type GenerateContentResponse } from "@google-cloud/vertexai"; -import type { BaseTool } from "../../types.js"; import type { + BaseTool, ChatMessage, MessageContentImageDetail, MessageContentTextDetail, MessageType, ToolCallLLMMessageOptions, -} from "../types.js"; +} from "@llamaindex/core/llms"; import { extractDataUrlComponents } from "../utils.js"; import type { ChatContext, diff --git a/packages/llamaindex/src/llm/gemini/vertex.ts b/packages/llamaindex/src/llm/gemini/vertex.ts index 398a9b1e8bffcd9d4b34b21730ef2a6285c29d5b..96fd6b903211bfb29630d672ab614257bfd207d2 100644 --- a/packages/llamaindex/src/llm/gemini/vertex.ts +++ b/packages/llamaindex/src/llm/gemini/vertex.ts @@ -14,12 +14,12 @@ import type { } from "./types.js"; import type { FunctionCall } from "@google/generative-ai"; -import { getEnv, randomUUID } from "@llamaindex/env"; import type { CompletionResponse, ToolCall, ToolCallLLMMessageOptions, -} from "../types.js"; +} from "@llamaindex/core/llms"; +import { getEnv, randomUUID } from "@llamaindex/env"; import { streamConverter } from "../utils.js"; import { DEFAULT_SAFETY_SETTINGS, getFunctionCalls, getText } from "./utils.js"; diff --git a/packages/llamaindex/src/llm/huggingface.ts b/packages/llamaindex/src/llm/huggingface.ts index 56314e794de132b980e6fe761f313df898693a6f..5965973c37cb523719e317bd9992bfbcd2a770cf 100644 --- a/packages/llamaindex/src/llm/huggingface.ts +++ b/packages/llamaindex/src/llm/huggingface.ts @@ -1,11 +1,4 @@ import { HfInference } from "@huggingface/inference"; -import type { - PreTrainedModel, - PreTrainedTokenizer, - Tensor, -} from "@xenova/transformers"; -import { lazyLoadTransformers } from "../internal/deps/transformers.js"; -import { BaseLLM } from "./base.js"; import type { ChatMessage, ChatResponse, @@ -14,7 +7,14 @@ import type { LLMChatParamsStreaming, LLMMetadata, ToolCallLLMMessageOptions, -} from "./types.js"; +} from "@llamaindex/core/llms"; +import type { + PreTrainedModel, + PreTrainedTokenizer, + Tensor, +} from "@xenova/transformers"; +import { lazyLoadTransformers } from "../internal/deps/transformers.js"; +import { BaseLLM } from "./base.js"; import { streamConverter, wrapLLMEvent } from "./utils.js"; // TODO workaround issue with @huggingface/inference@2.7.0 diff --git a/packages/llamaindex/src/llm/mistral.ts b/packages/llamaindex/src/llm/mistral.ts index d933327b5ae6cabb02a5aaa991e38c2d432623ea..da7be675149793a0f184d266ec3d229aca5e1be6 100644 --- a/packages/llamaindex/src/llm/mistral.ts +++ b/packages/llamaindex/src/llm/mistral.ts @@ -1,14 +1,14 @@ -import { getEnv } from "@llamaindex/env"; -import { Settings } from "../Settings.js"; -import { type StreamCallbackResponse } from "../callbacks/CallbackManager.js"; -import { BaseLLM } from "./base.js"; import type { ChatMessage, ChatResponse, ChatResponseChunk, LLMChatParamsNonStreaming, LLMChatParamsStreaming, -} from "./types.js"; +} from "@llamaindex/core/llms"; +import { getEnv } from "@llamaindex/env"; +import { Settings } from "../Settings.js"; +import { type StreamCallbackResponse } from "../callbacks/CallbackManager.js"; +import { BaseLLM } from "./base.js"; export const ALL_AVAILABLE_MISTRAL_MODELS = { "mistral-tiny": { contextWindow: 32000 }, diff --git a/packages/llamaindex/src/llm/ollama.ts b/packages/llamaindex/src/llm/ollama.ts index 179cb7e58a91e672bf7d41c94ebd2c756804fed6..44e9ede45b29b8032a37f0ab8e6ea56412cff500 100644 --- a/packages/llamaindex/src/llm/ollama.ts +++ b/packages/llamaindex/src/llm/ollama.ts @@ -1,3 +1,14 @@ +import type { + ChatResponse, + ChatResponseChunk, + CompletionResponse, + LLM, + LLMChatParamsNonStreaming, + LLMChatParamsStreaming, + LLMCompletionParamsNonStreaming, + LLMCompletionParamsStreaming, + LLMMetadata, +} from "@llamaindex/core/llms"; import { BaseEmbedding } from "../embeddings/types.js"; import { Ollama as OllamaBase, @@ -19,17 +30,6 @@ import { type ShowResponse, type StatusResponse, } from "../internal/deps/ollama.js"; -import type { - ChatResponse, - ChatResponseChunk, - CompletionResponse, - LLM, - LLMChatParamsNonStreaming, - LLMChatParamsStreaming, - LLMCompletionParamsNonStreaming, - LLMCompletionParamsStreaming, - LLMMetadata, -} from "./types.js"; import { extractText, streamConverter } from "./utils.js"; const messageAccessor = (part: OllamaChatResponse): ChatResponseChunk => { diff --git a/packages/llamaindex/src/llm/openai.ts b/packages/llamaindex/src/llm/openai.ts index 8c0be3ffb9fb013a650450d95e6781b88201cb13..65813b882c6680dc18fe69fdb3dad1023fb16dc8 100644 --- a/packages/llamaindex/src/llm/openai.ts +++ b/packages/llamaindex/src/llm/openai.ts @@ -7,6 +7,19 @@ import type { } from "openai"; import { AzureOpenAI, OpenAI as OrigOpenAI } from "openai"; +import type { + BaseTool, + ChatMessage, + ChatResponse, + ChatResponseChunk, + LLM, + LLMChatParamsNonStreaming, + LLMChatParamsStreaming, + LLMMetadata, + MessageType, + PartialToolCall, + ToolCallLLMMessageOptions, +} from "@llamaindex/core/llms"; import { Tokenizers } from "@llamaindex/env"; import type { ChatCompletionAssistantMessageParam, @@ -20,7 +33,6 @@ import type { import type { ChatCompletionMessageParam } from "openai/resources/index.js"; import { wrapEventCaller } from "../internal/context/EventCaller.js"; import { getCallbackManager } from "../internal/settings/CallbackManager.js"; -import type { BaseTool } from "../types.js"; import type { AzureOpenAIConfig } from "./azure.js"; import { getAzureConfigFromEnv, @@ -28,18 +40,6 @@ import { shouldUseAzure, } from "./azure.js"; import { ToolCallLLM } from "./base.js"; -import type { - ChatMessage, - ChatResponse, - ChatResponseChunk, - LLM, - LLMChatParamsNonStreaming, - LLMChatParamsStreaming, - LLMMetadata, - MessageType, - PartialToolCall, - ToolCallLLMMessageOptions, -} from "./types.js"; import { extractText, wrapLLMEvent } from "./utils.js"; export class OpenAISession { diff --git a/packages/llamaindex/src/llm/portkey.ts b/packages/llamaindex/src/llm/portkey.ts index bb3f47b129e20ca81a9c848a3746e57ff88ba733..3ee36bf134e03011a112b3389f8796fc6f4b9f75 100644 --- a/packages/llamaindex/src/llm/portkey.ts +++ b/packages/llamaindex/src/llm/portkey.ts @@ -1,10 +1,3 @@ -import { getEnv } from "@llamaindex/env"; -import _ from "lodash"; -import type { LLMOptions } from "portkey-ai"; -import { Portkey as OrigPortKey } from "portkey-ai"; -import { type StreamCallbackResponse } from "../callbacks/CallbackManager.js"; -import { getCallbackManager } from "../internal/settings/CallbackManager.js"; -import { BaseLLM } from "./base.js"; import type { ChatMessage, ChatResponse, @@ -13,7 +6,14 @@ import type { LLMChatParamsStreaming, LLMMetadata, MessageType, -} from "./types.js"; +} from "@llamaindex/core/llms"; +import { getEnv } from "@llamaindex/env"; +import _ from "lodash"; +import type { LLMOptions } from "portkey-ai"; +import { Portkey as OrigPortKey } from "portkey-ai"; +import { type StreamCallbackResponse } from "../callbacks/CallbackManager.js"; +import { getCallbackManager } from "../internal/settings/CallbackManager.js"; +import { BaseLLM } from "./base.js"; import { extractText, wrapLLMEvent } from "./utils.js"; interface PortkeyOptions { diff --git a/packages/llamaindex/src/llm/replicate_ai.ts b/packages/llamaindex/src/llm/replicate_ai.ts index 99d5fb332aa80423628707a8ed2eba9f5c457722..091abdb789db17569f3a9ec5d47a19dc65218e92 100644 --- a/packages/llamaindex/src/llm/replicate_ai.ts +++ b/packages/llamaindex/src/llm/replicate_ai.ts @@ -1,6 +1,3 @@ -import { getEnv } from "@llamaindex/env"; -import Replicate from "../internal/deps/replicate.js"; -import { BaseLLM } from "./base.js"; import type { ChatMessage, ChatResponse, @@ -8,7 +5,10 @@ import type { LLMChatParamsNonStreaming, LLMChatParamsStreaming, MessageType, -} from "./types.js"; +} from "@llamaindex/core/llms"; +import { getEnv } from "@llamaindex/env"; +import Replicate from "../internal/deps/replicate.js"; +import { BaseLLM } from "./base.js"; import { extractText, streamCallbacks, diff --git a/packages/llamaindex/src/llm/types.ts b/packages/llamaindex/src/llm/types.ts index a6ad26d9c7ce0ff2ddc517bfdd030498fb315b0f..eee81169dca5fcdf8ef00501a83a7845b50ea9c7 100644 --- a/packages/llamaindex/src/llm/types.ts +++ b/packages/llamaindex/src/llm/types.ts @@ -1,7 +1,14 @@ +import type { + ChatMessage, + ChatResponse, + ChatResponseChunk, + MessageContent, + ToolCall, + ToolOutput, +} from "@llamaindex/core/llms"; import type { NodeWithScore } from "@llamaindex/core/schema"; -import type { Tokenizers } from "@llamaindex/env"; import type { BaseEvent } from "../internal/type.js"; -import type { BaseTool, JSONObject, ToolOutput, UUID } from "../types.js"; +import type { UUID } from "../types.js"; export type RetrievalStartEvent = BaseEvent<{ query: MessageContent; @@ -29,197 +36,3 @@ export type LLMStreamEvent = BaseEvent<{ id: UUID; chunk: ChatResponseChunk; }>; - -/** - * @internal - */ -export interface LLMChat< - AdditionalChatOptions extends object = object, - AdditionalMessageOptions extends object = object, -> { - chat( - params: - | LLMChatParamsStreaming<AdditionalChatOptions> - | LLMChatParamsNonStreaming<AdditionalChatOptions>, - ): Promise< - | ChatResponse<AdditionalMessageOptions> - | AsyncIterable<ChatResponseChunk<AdditionalMessageOptions>> - >; -} - -/** - * Unified language model interface - */ -export interface LLM< - AdditionalChatOptions extends object = object, - AdditionalMessageOptions extends object = object, -> extends LLMChat<AdditionalChatOptions> { - metadata: LLMMetadata; - /** - * Get a chat response from the LLM - */ - chat( - params: LLMChatParamsStreaming< - AdditionalChatOptions, - AdditionalMessageOptions - >, - ): Promise<AsyncIterable<ChatResponseChunk>>; - chat( - params: LLMChatParamsNonStreaming< - AdditionalChatOptions, - AdditionalMessageOptions - >, - ): Promise<ChatResponse<AdditionalMessageOptions>>; - - /** - * Get a prompt completion from the LLM - */ - complete( - params: LLMCompletionParamsStreaming, - ): Promise<AsyncIterable<CompletionResponse>>; - complete( - params: LLMCompletionParamsNonStreaming, - ): Promise<CompletionResponse>; -} - -export type MessageType = "user" | "assistant" | "system" | "memory"; - -export type TextChatMessage<AdditionalMessageOptions extends object = object> = - { - content: string; - role: MessageType; - options?: undefined | AdditionalMessageOptions; - }; - -export type ChatMessage<AdditionalMessageOptions extends object = object> = { - content: MessageContent; - role: MessageType; - options?: undefined | AdditionalMessageOptions; -}; - -export interface ChatResponse< - AdditionalMessageOptions extends object = object, -> { - message: ChatMessage<AdditionalMessageOptions>; - /** - * Raw response from the LLM - * - * If LLM response an iterable of chunks, this will be an array of those chunks - */ - raw: object | null; -} - -export type ChatResponseChunk< - AdditionalMessageOptions extends object = object, -> = { - raw: object | null; - delta: string; - options?: undefined | AdditionalMessageOptions; -}; - -export interface CompletionResponse { - text: string; - /** - * Raw response from the LLM - * - * It's possible that this is `null` if the LLM response an iterable of chunks - */ - raw: object | null; -} - -export type LLMMetadata = { - model: string; - temperature: number; - topP: number; - maxTokens?: number; - contextWindow: number; - tokenizer: Tokenizers | undefined; -}; - -export interface LLMChatParamsBase< - AdditionalChatOptions extends object = object, - AdditionalMessageOptions extends object = object, -> { - messages: ChatMessage<AdditionalMessageOptions>[]; - additionalChatOptions?: AdditionalChatOptions; - tools?: BaseTool[]; -} - -export interface LLMChatParamsStreaming< - AdditionalChatOptions extends object = object, - AdditionalMessageOptions extends object = object, -> extends LLMChatParamsBase<AdditionalChatOptions, AdditionalMessageOptions> { - stream: true; -} - -export interface LLMChatParamsNonStreaming< - AdditionalChatOptions extends object = object, - AdditionalMessageOptions extends object = object, -> extends LLMChatParamsBase<AdditionalChatOptions, AdditionalMessageOptions> { - stream?: false; -} - -export interface LLMCompletionParamsBase { - prompt: MessageContent; -} - -export interface LLMCompletionParamsStreaming extends LLMCompletionParamsBase { - stream: true; -} - -export interface LLMCompletionParamsNonStreaming - extends LLMCompletionParamsBase { - stream?: false | null; -} - -export type MessageContentTextDetail = { - type: "text"; - text: string; -}; - -export type MessageContentImageDetail = { - type: "image_url"; - image_url: { url: string }; -}; - -export type MessageContentDetail = - | MessageContentTextDetail - | MessageContentImageDetail; - -/** - * Extended type for the content of a message that allows for multi-modal messages. - */ -export type MessageContent = string | MessageContentDetail[]; - -export type ToolCall = { - name: string; - input: JSONObject; - id: string; -}; - -// happened in streaming response, the tool call is not ready yet -export type PartialToolCall = { - name: string; - id: string; - // input is not ready yet, JSON.parse(input) will throw an error - input: string; -}; - -export type ToolResult = { - id: string; - result: string; - isError: boolean; -}; - -export type ToolCallOptions = { - toolCall: (ToolCall | PartialToolCall)[]; -}; - -export type ToolResultOptions = { - toolResult: ToolResult; -}; - -export type ToolCallLLMMessageOptions = - | ToolResultOptions - | ToolCallOptions - | {}; diff --git a/packages/llamaindex/src/llm/utils.ts b/packages/llamaindex/src/llm/utils.ts index 8c8dabb33eb19136522ddd049d793d6f54580129..6a640f368ca603d14e84440fe923dcc7a1d69be4 100644 --- a/packages/llamaindex/src/llm/utils.ts +++ b/packages/llamaindex/src/llm/utils.ts @@ -1,6 +1,3 @@ -import type { ImageType } from "@llamaindex/core/schema"; -import { AsyncLocalStorage, randomUUID } from "@llamaindex/env"; -import { getCallbackManager } from "../internal/settings/CallbackManager.js"; import type { ChatResponse, ChatResponseChunk, @@ -9,7 +6,10 @@ import type { MessageContent, MessageContentDetail, MessageContentTextDetail, -} from "./types.js"; +} from "@llamaindex/core/llms"; +import type { ImageType } from "@llamaindex/core/schema"; +import { AsyncLocalStorage, randomUUID } from "@llamaindex/env"; +import { getCallbackManager } from "../internal/settings/CallbackManager.js"; export async function* streamConverter<S, D>( stream: AsyncIterable<S>, diff --git a/packages/llamaindex/src/memory/ChatMemoryBuffer.ts b/packages/llamaindex/src/memory/ChatMemoryBuffer.ts index eda6bbb313c308ec914505b45f4a1a6a3835d7bf..ed4b38760857a6dbc4db788a24e36cbd60350a5d 100644 --- a/packages/llamaindex/src/memory/ChatMemoryBuffer.ts +++ b/packages/llamaindex/src/memory/ChatMemoryBuffer.ts @@ -1,5 +1,5 @@ +import type { ChatMessage, LLM } from "@llamaindex/core/llms"; import type { ChatHistory } from "../ChatHistory.js"; -import type { ChatMessage, LLM } from "../llm/index.js"; import { SimpleChatStore } from "../storage/chatStore/SimpleChatStore.js"; import type { BaseChatStore } from "../storage/chatStore/types.js"; import type { BaseMemory } from "./types.js"; diff --git a/packages/llamaindex/src/memory/types.ts b/packages/llamaindex/src/memory/types.ts index 8af16e5a1de748f8e3ac45080849ce1546947d33..a95e2efea9fa7f5fc8bad2f54cfbdf5ae28fc6aa 100644 --- a/packages/llamaindex/src/memory/types.ts +++ b/packages/llamaindex/src/memory/types.ts @@ -1,4 +1,4 @@ -import type { ChatMessage } from "../llm/index.js"; +import type { ChatMessage } from "@llamaindex/core/llms"; export interface BaseMemory<AdditionalMessageOptions extends object = object> { tokenLimit: number; diff --git a/packages/llamaindex/src/objects/base.ts b/packages/llamaindex/src/objects/base.ts index 6ae73d50a87dd7fe2de1fb10a38c77ce60df7a5c..4b962d26b49c4b1ef722c05a8a347630e47ca9dc 100644 --- a/packages/llamaindex/src/objects/base.ts +++ b/packages/llamaindex/src/objects/base.ts @@ -1,10 +1,9 @@ +import type { BaseTool, MessageContent } from "@llamaindex/core/llms"; import type { BaseNode, Metadata } from "@llamaindex/core/schema"; import { TextNode } from "@llamaindex/core/schema"; import type { BaseRetriever } from "../Retriever.js"; import type { VectorStoreIndex } from "../indices/vectorStore/index.js"; -import type { MessageContent } from "../llm/index.js"; import { extractText } from "../llm/utils.js"; -import type { BaseTool } from "../types.js"; // Assuming that necessary interfaces and classes (like OT, TextNode, BaseNode, etc.) are defined elsewhere // Import statements (e.g., for TextNode, BaseNode) should be added based on your project's structure diff --git a/packages/llamaindex/src/postprocessors/rerankers/CohereRerank.ts b/packages/llamaindex/src/postprocessors/rerankers/CohereRerank.ts index 920c0d0e34a02f1aa515593174b6c3bec691db99..8a630e520dd7fe10b251ca3671acaa699091333e 100644 --- a/packages/llamaindex/src/postprocessors/rerankers/CohereRerank.ts +++ b/packages/llamaindex/src/postprocessors/rerankers/CohereRerank.ts @@ -1,8 +1,8 @@ import { CohereClient } from "cohere-ai"; +import type { MessageContent } from "@llamaindex/core/llms"; import type { NodeWithScore } from "@llamaindex/core/schema"; import { MetadataMode } from "@llamaindex/core/schema"; -import type { MessageContent } from "../../llm/types.js"; import { extractText } from "../../llm/utils.js"; import type { BaseNodePostprocessor } from "../types.js"; diff --git a/packages/llamaindex/src/postprocessors/rerankers/JinaAIReranker.ts b/packages/llamaindex/src/postprocessors/rerankers/JinaAIReranker.ts index aa0a02e4d16a3d794eb39ae31849ed9541a009cb..a1ffb334bfcb0b054b582b82fd13bbbdf3ba4c52 100644 --- a/packages/llamaindex/src/postprocessors/rerankers/JinaAIReranker.ts +++ b/packages/llamaindex/src/postprocessors/rerankers/JinaAIReranker.ts @@ -1,7 +1,7 @@ +import type { MessageContent } from "@llamaindex/core/llms"; import type { NodeWithScore } from "@llamaindex/core/schema"; import { MetadataMode } from "@llamaindex/core/schema"; import { getEnv } from "@llamaindex/env"; -import type { MessageContent } from "../../llm/types.js"; import { extractText } from "../../llm/utils.js"; import type { BaseNodePostprocessor } from "../types.js"; diff --git a/packages/llamaindex/src/postprocessors/types.ts b/packages/llamaindex/src/postprocessors/types.ts index 9650d39e06aa373be7fec983d5d254ad522dc176..8fafb4cfe9a77fbc29f719575294952ac2ee73b8 100644 --- a/packages/llamaindex/src/postprocessors/types.ts +++ b/packages/llamaindex/src/postprocessors/types.ts @@ -1,5 +1,5 @@ +import type { MessageContent } from "@llamaindex/core/llms"; import type { NodeWithScore } from "@llamaindex/core/schema"; -import type { MessageContent } from "../llm/types.js"; export interface BaseNodePostprocessor { /** diff --git a/packages/llamaindex/src/selectors/llmSelectors.ts b/packages/llamaindex/src/selectors/llmSelectors.ts index 5f7349f26a553fbe83b906c116fd94141aa0b779..242b9973a25d95084ec500912cd2fa2c228f9913 100644 --- a/packages/llamaindex/src/selectors/llmSelectors.ts +++ b/packages/llamaindex/src/selectors/llmSelectors.ts @@ -1,4 +1,4 @@ -import type { LLM } from "../llm/index.js"; +import type { LLM } from "@llamaindex/core/llms"; import type { Answer } from "../outputParsers/selectors.js"; import { SelectionOutputParser } from "../outputParsers/selectors.js"; import type { diff --git a/packages/llamaindex/src/storage/chatStore/SimpleChatStore.ts b/packages/llamaindex/src/storage/chatStore/SimpleChatStore.ts index 4f6df4718115704a6f69fb4b00ccb8f562f285f2..b094a961ed133c0262b733174c3bb59a36201421 100644 --- a/packages/llamaindex/src/storage/chatStore/SimpleChatStore.ts +++ b/packages/llamaindex/src/storage/chatStore/SimpleChatStore.ts @@ -1,4 +1,4 @@ -import type { ChatMessage } from "../../llm/index.js"; +import type { ChatMessage } from "@llamaindex/core/llms"; import type { BaseChatStore } from "./types.js"; /** diff --git a/packages/llamaindex/src/storage/chatStore/types.ts b/packages/llamaindex/src/storage/chatStore/types.ts index c809f91becf2312c03fb03b2e13b602a73b55139..2e467276c6fb99a5899de6834207a9bdd765315d 100644 --- a/packages/llamaindex/src/storage/chatStore/types.ts +++ b/packages/llamaindex/src/storage/chatStore/types.ts @@ -1,4 +1,4 @@ -import type { ChatMessage } from "../../llm/index.js"; +import type { ChatMessage } from "@llamaindex/core/llms"; export interface BaseChatStore< AdditionalMessageOptions extends object = object, diff --git a/packages/llamaindex/src/synthesizers/builders.ts b/packages/llamaindex/src/synthesizers/builders.ts index ee0cce07c8cd76da3a24cf2be5cb170cafe8022d..cc8147f673bc4b1a30d4262ab943f87f5939456c 100644 --- a/packages/llamaindex/src/synthesizers/builders.ts +++ b/packages/llamaindex/src/synthesizers/builders.ts @@ -1,4 +1,4 @@ -import type { LLM } from "../llm/index.js"; +import type { LLM } from "@llamaindex/core/llms"; import { streamConverter } from "../llm/utils.js"; import type { RefinePrompt, diff --git a/packages/llamaindex/src/synthesizers/utils.ts b/packages/llamaindex/src/synthesizers/utils.ts index b1e6e19623d202a9622082a665c1340d0e87c4e2..79d465ffe021a32f7ff6013eaed74d037137ee7c 100644 --- a/packages/llamaindex/src/synthesizers/utils.ts +++ b/packages/llamaindex/src/synthesizers/utils.ts @@ -1,3 +1,4 @@ +import type { MessageContentDetail } from "@llamaindex/core/llms"; import { ImageNode, MetadataMode, @@ -7,7 +8,6 @@ import { } from "@llamaindex/core/schema"; import type { SimplePrompt } from "../Prompt.js"; import { imageToDataUrl } from "../embeddings/utils.js"; -import type { MessageContentDetail } from "../llm/types.js"; export async function createMessageContent( prompt: SimplePrompt, diff --git a/packages/llamaindex/src/tools/AzureDynamicSessionTool.node.ts b/packages/llamaindex/src/tools/AzureDynamicSessionTool.node.ts index 2500cd89fe5f3833a70ad9e9df8441fd67e6ca5f..aaf6bb7c58f5d32a1bdbc19371cc6d6149f45114 100644 --- a/packages/llamaindex/src/tools/AzureDynamicSessionTool.node.ts +++ b/packages/llamaindex/src/tools/AzureDynamicSessionTool.node.ts @@ -2,6 +2,7 @@ import { DefaultAzureCredential, getBearerTokenProvider, } from "@azure/identity"; +import type { BaseTool, ToolMetadata } from "@llamaindex/core/llms"; import { Readable, createWriteStream, @@ -11,7 +12,6 @@ import { path, randomUUID, } from "@llamaindex/env"; -import type { BaseTool, ToolMetadata } from "../types.js"; export type InterpreterParameter = { code: string; }; diff --git a/packages/llamaindex/src/tools/QueryEngineTool.ts b/packages/llamaindex/src/tools/QueryEngineTool.ts index d2c03ad938f0908a194c0b57c57a4f65e9318b34..f1118dd673114b9ed156078e3add4517d1d3f94d 100644 --- a/packages/llamaindex/src/tools/QueryEngineTool.ts +++ b/packages/llamaindex/src/tools/QueryEngineTool.ts @@ -1,5 +1,6 @@ +import type { BaseTool, ToolMetadata } from "@llamaindex/core/llms"; import type { JSONSchemaType } from "ajv"; -import type { BaseTool, QueryEngine, ToolMetadata } from "../types.js"; +import type { QueryEngine } from "../types.js"; const DEFAULT_NAME = "query_engine_tool"; const DEFAULT_DESCRIPTION = diff --git a/packages/llamaindex/src/tools/WikipediaTool.ts b/packages/llamaindex/src/tools/WikipediaTool.ts index 6a1ff6904ea25430e7548fea0937bef79bf1de08..f625378de3671ccef9726af66b56cb0549fb0eb6 100644 --- a/packages/llamaindex/src/tools/WikipediaTool.ts +++ b/packages/llamaindex/src/tools/WikipediaTool.ts @@ -1,6 +1,6 @@ +import type { BaseTool, ToolMetadata } from "@llamaindex/core/llms"; import type { JSONSchemaType } from "ajv"; import { default as wiki } from "wikipedia"; -import type { BaseTool, ToolMetadata } from "../types.js"; type WikipediaParameter = { query: string; diff --git a/packages/llamaindex/src/tools/functionTool.ts b/packages/llamaindex/src/tools/functionTool.ts index 128d429cd5fbe78073a7eb44df45b761a78125b9..21ec4995f22c3304931050647853763c523cc1d8 100644 --- a/packages/llamaindex/src/tools/functionTool.ts +++ b/packages/llamaindex/src/tools/functionTool.ts @@ -1,5 +1,6 @@ +import type { BaseTool, ToolMetadata } from "@llamaindex/core/llms"; import type { JSONSchemaType } from "ajv"; -import type { BaseTool, JSONValue, ToolMetadata } from "../types.js"; +import type { JSONValue } from "../types.js"; export class FunctionTool<T, R extends JSONValue | Promise<JSONValue>> implements BaseTool<T> diff --git a/packages/llamaindex/src/types.ts b/packages/llamaindex/src/types.ts index c1f1292827ed790ebf95980297d5e4955b1abd9f..d5b28bf8d0d491f98e94d8e626c8c1d248215a79 100644 --- a/packages/llamaindex/src/types.ts +++ b/packages/llamaindex/src/types.ts @@ -1,7 +1,7 @@ /** * Top level types to avoid circular dependencies */ -import { type JSONSchemaType } from "ajv"; +import type { ToolMetadata } from "@llamaindex/core/llms"; import type { EngineResponse } from "./EngineResponse.js"; /** @@ -33,46 +33,6 @@ export interface QueryEngine { query(params: QueryEngineParamsNonStreaming): Promise<EngineResponse>; } -type Known = - | { [key: string]: Known } - | [Known, ...Known[]] - | Known[] - | number - | string - | boolean - | null; - -export type ToolMetadata< - Parameters extends Record<string, unknown> = Record<string, unknown>, -> = { - description: string; - name: string; - /** - * OpenAI uses JSON Schema to describe the parameters that a tool can take. - * @link https://json-schema.org/understanding-json-schema - */ - parameters?: Parameters; -}; - -/** - * Simple Tool interface. Likely to change. - */ -export interface BaseTool<Input = any> { - /** - * This could be undefined if the implementation is not provided, - * which might be the case when communicating with a llm. - * - * @return {JSONValue | Promise<JSONValue>} The output of the tool. - */ - call?: (input: Input) => JSONValue | Promise<JSONValue>; - metadata: // if user input any, we cannot check the schema - Input extends Known ? ToolMetadata<JSONSchemaType<Input>> : ToolMetadata; -} - -export type BaseToolWithCall<Input = any> = Omit<BaseTool<Input>, "call"> & { - call: NonNullable<Pick<BaseTool<Input>, "call">["call"]>; -}; - /** * An OutputParser is used to extract structured data from the raw output of the LLM. */ @@ -113,11 +73,3 @@ export type JSONObject = { }; type JSONArray = Array<JSONValue>; - -export type ToolOutput = { - tool: BaseTool | undefined; - // all of existing function calling LLMs only support object input - input: JSONObject; - output: JSONValue; - isError: boolean; -}; diff --git a/packages/llamaindex/tests/utility/mockOpenAI.ts b/packages/llamaindex/tests/utility/mockOpenAI.ts index 626f7c90193945d27f174f6b6436706f8b994a15..e2677bb19f3fee8d02a893c4d935b0342c5b1ab9 100644 --- a/packages/llamaindex/tests/utility/mockOpenAI.ts +++ b/packages/llamaindex/tests/utility/mockOpenAI.ts @@ -1,8 +1,8 @@ +import type { LLMChatParamsBase } from "llamaindex"; import { Settings } from "llamaindex"; import type { CallbackManager } from "llamaindex/callbacks/CallbackManager"; import type { OpenAIEmbedding } from "llamaindex/embeddings/index"; import { OpenAI } from "llamaindex/llm/openai"; -import type { LLMChatParamsBase } from "llamaindex/llm/types"; import { vi } from "vitest"; export const DEFAULT_LLM_TEXT_OUTPUT = "MOCK_TOKEN_1-MOCK_TOKEN_2"; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e91f2bbe7734247389ecacca0426d04090a2663e..ea7699622b6a6a3f1fa5fbba5b0232b35d437e5d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -383,6 +383,9 @@ importers: specifier: ^3.23.8 version: 3.23.8 devDependencies: + ajv: + specifier: ^8.16.0 + version: 8.16.0 bunchee: specifier: ^5.2.1 version: 5.2.1(patch_hash=or7rmtlcau3uwknbkedxicrvyi)(typescript@5.5.2) @@ -17160,8 +17163,8 @@ snapshots: '@typescript-eslint/parser': 7.2.0(eslint@8.57.0)(typescript@5.5.2) eslint: 8.57.0 eslint-import-resolver-node: 0.3.9 - eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.2))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1)(eslint@8.57.0) - eslint-plugin-import: 2.29.1(@typescript-eslint/parser@7.8.0(eslint@8.57.0)(typescript@5.5.2))(eslint@8.57.0) + eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.2))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.8.0(eslint@8.57.0)(typescript@5.5.2))(eslint@8.57.0))(eslint@8.57.0) + eslint-plugin-import: 2.29.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.2))(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.2))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.8.0(eslint@8.57.0)(typescript@5.5.2))(eslint@8.57.0))(eslint@8.57.0))(eslint@8.57.0) eslint-plugin-jsx-a11y: 6.8.0(eslint@8.57.0) eslint-plugin-react: 7.34.1(eslint@8.57.0) eslint-plugin-react-hooks: 4.6.2(eslint@8.57.0) @@ -17206,6 +17209,23 @@ snapshots: transitivePeerDependencies: - supports-color + eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.2))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.8.0(eslint@8.57.0)(typescript@5.5.2))(eslint@8.57.0))(eslint@8.57.0): + dependencies: + debug: 4.3.4 + enhanced-resolve: 5.17.0 + eslint: 8.57.0 + eslint-module-utils: 2.8.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.2))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.2))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.8.0(eslint@8.57.0)(typescript@5.5.2))(eslint@8.57.0))(eslint@8.57.0))(eslint@8.57.0) + eslint-plugin-import: 2.29.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.2))(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.2))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.8.0(eslint@8.57.0)(typescript@5.5.2))(eslint@8.57.0))(eslint@8.57.0))(eslint@8.57.0) + fast-glob: 3.3.2 + get-tsconfig: 4.7.5 + is-core-module: 2.13.1 + is-glob: 4.0.3 + transitivePeerDependencies: + - '@typescript-eslint/parser' + - eslint-import-resolver-node + - eslint-import-resolver-webpack + - supports-color + eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.2))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1)(eslint@8.57.0): dependencies: debug: 4.3.4 @@ -17223,6 +17243,17 @@ snapshots: - eslint-import-resolver-webpack - supports-color + eslint-module-utils@2.8.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.2))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.2))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.8.0(eslint@8.57.0)(typescript@5.5.2))(eslint@8.57.0))(eslint@8.57.0))(eslint@8.57.0): + dependencies: + debug: 3.2.7 + optionalDependencies: + '@typescript-eslint/parser': 7.2.0(eslint@8.57.0)(typescript@5.5.2) + eslint: 8.57.0 + eslint-import-resolver-node: 0.3.9 + eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.2))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.8.0(eslint@8.57.0)(typescript@5.5.2))(eslint@8.57.0))(eslint@8.57.0) + transitivePeerDependencies: + - supports-color + eslint-module-utils@2.8.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.2))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.2))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1)(eslint@8.57.0))(eslint@8.57.0): dependencies: debug: 3.2.7 @@ -17234,14 +17265,31 @@ snapshots: transitivePeerDependencies: - supports-color - eslint-module-utils@2.8.1(@typescript-eslint/parser@7.8.0(eslint@8.57.0)(typescript@5.5.2))(eslint-import-resolver-node@0.3.9)(eslint@8.57.0): + eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.2))(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.2))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.8.0(eslint@8.57.0)(typescript@5.5.2))(eslint@8.57.0))(eslint@8.57.0))(eslint@8.57.0): dependencies: + array-includes: 3.1.8 + array.prototype.findlastindex: 1.2.5 + array.prototype.flat: 1.3.2 + array.prototype.flatmap: 1.3.2 debug: 3.2.7 - optionalDependencies: - '@typescript-eslint/parser': 7.8.0(eslint@8.57.0)(typescript@5.5.2) + doctrine: 2.1.0 eslint: 8.57.0 eslint-import-resolver-node: 0.3.9 + eslint-module-utils: 2.8.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.2))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.2))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.8.0(eslint@8.57.0)(typescript@5.5.2))(eslint@8.57.0))(eslint@8.57.0))(eslint@8.57.0) + hasown: 2.0.2 + is-core-module: 2.13.1 + is-glob: 4.0.3 + minimatch: 3.1.2 + object.fromentries: 2.0.8 + object.groupby: 1.0.3 + object.values: 1.2.0 + semver: 6.3.1 + tsconfig-paths: 3.15.0 + optionalDependencies: + '@typescript-eslint/parser': 7.2.0(eslint@8.57.0)(typescript@5.5.2) transitivePeerDependencies: + - eslint-import-resolver-typescript + - eslint-import-resolver-webpack - supports-color eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.8.0(eslint@8.57.0)(typescript@5.5.2))(eslint@8.57.0): @@ -17254,7 +17302,7 @@ snapshots: doctrine: 2.1.0 eslint: 8.57.0 eslint-import-resolver-node: 0.3.9 - eslint-module-utils: 2.8.1(@typescript-eslint/parser@7.8.0(eslint@8.57.0)(typescript@5.5.2))(eslint-import-resolver-node@0.3.9)(eslint@8.57.0) + eslint-module-utils: 2.8.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.2))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.2))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1)(eslint@8.57.0))(eslint@8.57.0) hasown: 2.0.2 is-core-module: 2.13.1 is-glob: 4.0.3