@llamaindex/core
Advanced tools
Comparing version 0.4.8 to 0.4.9
@@ -8,3 +8,3 @@ import { BaseChatEngine, NonStreamingChatEngineParams, StreamingChatEngineParams } from '../../chat-engine/dist/index.js'; | ||
type AgentTaskContext<Model extends LLM, Store extends object = object, AdditionalMessageOptions extends object = Model extends LLM<object, infer AdditionalMessageOptions> ? AdditionalMessageOptions : never> = { | ||
type AgentTaskContext<Model extends LLM, Store extends object = object, AdditionalMessageOptions extends object = Model extends LLM<object, infer AdditionalMessageOptions> ? AdditionalMessageOptions : never, AdditionalChatOptions extends object = object> = { | ||
readonly stream: boolean; | ||
@@ -14,2 +14,3 @@ readonly toolCallCount: number; | ||
readonly getTools: (input: MessageContent) => BaseToolWithCall[] | Promise<BaseToolWithCall[]>; | ||
readonly additionalChatOptions: Partial<AdditionalChatOptions>; | ||
shouldContinue: (taskStep: Readonly<TaskStep<Model, Store, AdditionalMessageOptions>>) => boolean; | ||
@@ -22,14 +23,14 @@ store: { | ||
}; | ||
type TaskStep<Model extends LLM = LLM, Store extends object = object, AdditionalMessageOptions extends object = Model extends LLM<object, infer AdditionalMessageOptions> ? AdditionalMessageOptions : never> = { | ||
type TaskStep<Model extends LLM = LLM, Store extends object = object, AdditionalMessageOptions extends object = Model extends LLM<object, infer AdditionalMessageOptions> ? AdditionalMessageOptions : never, AdditionalChatOptions extends object = object> = { | ||
id: UUID; | ||
context: AgentTaskContext<Model, Store, AdditionalMessageOptions>; | ||
prevStep: TaskStep<Model, Store, AdditionalMessageOptions> | null; | ||
nextSteps: Set<TaskStep<Model, Store, AdditionalMessageOptions>>; | ||
context: AgentTaskContext<Model, Store, AdditionalMessageOptions, AdditionalChatOptions>; | ||
prevStep: TaskStep<Model, Store, AdditionalMessageOptions, AdditionalChatOptions> | null; | ||
nextSteps: Set<TaskStep<Model, Store, AdditionalMessageOptions, AdditionalChatOptions>>; | ||
}; | ||
type TaskStepOutput<Model extends LLM, Store extends object = object, AdditionalMessageOptions extends object = Model extends LLM<object, infer AdditionalMessageOptions> ? AdditionalMessageOptions : never> = { | ||
taskStep: TaskStep<Model, Store, AdditionalMessageOptions>; | ||
type TaskStepOutput<Model extends LLM, Store extends object = object, AdditionalMessageOptions extends object = Model extends LLM<object, infer AdditionalMessageOptions> ? AdditionalMessageOptions : never, AdditionalChatOptions extends object = object> = { | ||
taskStep: TaskStep<Model, Store, AdditionalMessageOptions, AdditionalChatOptions>; | ||
output: ChatResponse<AdditionalMessageOptions> | ReadableStream<ChatResponseChunk<AdditionalMessageOptions>>; | ||
isLast: boolean; | ||
}; | ||
type TaskHandler<Model extends LLM, Store extends object = object, AdditionalMessageOptions extends object = Model extends LLM<object, infer AdditionalMessageOptions> ? AdditionalMessageOptions : never> = (step: TaskStep<Model, Store, AdditionalMessageOptions>, enqueueOutput: (taskOutput: TaskStepOutput<Model, Store, AdditionalMessageOptions>) => void) => Promise<void>; | ||
type TaskHandler<Model extends LLM, Store extends object = object, AdditionalMessageOptions extends object = Model extends LLM<object, infer AdditionalMessageOptions> ? AdditionalMessageOptions : never, AdditionalChatOptions extends object = object> = (step: TaskStep<Model, Store, AdditionalMessageOptions, AdditionalChatOptions>, enqueueOutput: (taskOutput: TaskStepOutput<Model, Store, AdditionalMessageOptions, AdditionalChatOptions>) => void) => Promise<void>; | ||
type AgentStartEvent = { | ||
@@ -42,11 +43,11 @@ startStep: TaskStep; | ||
type AgentRunnerParams<AI extends LLM, Store extends object = object, AdditionalMessageOptions extends object = AI extends LLM<object, infer AdditionalMessageOptions> ? AdditionalMessageOptions : never> = { | ||
type AgentRunnerParams<AI extends LLM, Store extends object = object, AdditionalMessageOptions extends object = AI extends LLM<object, infer AdditionalMessageOptions> ? AdditionalMessageOptions : never, AdditionalChatOptions extends object = object> = { | ||
llm: AI; | ||
chatHistory: ChatMessage<AdditionalMessageOptions>[]; | ||
systemPrompt: MessageContent | null; | ||
runner: AgentWorker<AI, Store, AdditionalMessageOptions>; | ||
runner: AgentWorker<AI, Store, AdditionalMessageOptions, AdditionalChatOptions>; | ||
tools: BaseToolWithCall[] | ((query: MessageContent) => Promise<BaseToolWithCall[]>); | ||
verbose: boolean; | ||
}; | ||
type AgentParamsBase<AI extends LLM, AdditionalMessageOptions extends object = AI extends LLM<object, infer AdditionalMessageOptions> ? AdditionalMessageOptions : never> = { | ||
type AgentParamsBase<AI extends LLM, AdditionalMessageOptions extends object = AI extends LLM<object, infer AdditionalMessageOptions> ? AdditionalMessageOptions : never, AdditionalChatOptions extends object = object> = { | ||
llm?: AI; | ||
@@ -57,2 +58,3 @@ chatHistory?: ChatMessage<AdditionalMessageOptions>[]; | ||
tools: BaseToolWithCall[]; | ||
additionalChatOptions?: AdditionalChatOptions; | ||
} | { | ||
@@ -64,2 +66,3 @@ llm?: AI; | ||
toolRetriever: ObjectRetriever<BaseToolWithCall>; | ||
additionalChatOptions?: AdditionalChatOptions; | ||
}; | ||
@@ -69,6 +72,6 @@ /** | ||
*/ | ||
declare abstract class AgentWorker<AI extends LLM, Store extends object = object, AdditionalMessageOptions extends object = AI extends LLM<object, infer AdditionalMessageOptions> ? AdditionalMessageOptions : never> { | ||
declare abstract class AgentWorker<AI extends LLM, Store extends object = object, AdditionalMessageOptions extends object = AI extends LLM<object, infer AdditionalMessageOptions> ? AdditionalMessageOptions : never, AdditionalChatOptions extends object = object> { | ||
#private; | ||
abstract taskHandler: TaskHandler<AI, Store, AdditionalMessageOptions>; | ||
createTask(query: MessageContent, context: AgentTaskContext<AI, Store, AdditionalMessageOptions>): ReadableStream<TaskStepOutput<AI, Store, AdditionalMessageOptions>>; | ||
abstract taskHandler: TaskHandler<AI, Store, AdditionalMessageOptions, AdditionalChatOptions>; | ||
createTask(query: MessageContent, context: AgentTaskContext<AI, Store, AdditionalMessageOptions, AdditionalChatOptions>): ReadableStream<TaskStepOutput<AI, Store, AdditionalMessageOptions, AdditionalChatOptions>>; | ||
[Symbol.toStringTag]: string; | ||
@@ -79,3 +82,3 @@ } | ||
*/ | ||
declare abstract class AgentRunner<AI extends LLM, Store extends object = object, AdditionalMessageOptions extends object = AI extends LLM<object, infer AdditionalMessageOptions> ? AdditionalMessageOptions : never> extends BaseChatEngine { | ||
declare abstract class AgentRunner<AI extends LLM, Store extends object = object, AdditionalMessageOptions extends object = AI extends LLM<object, infer AdditionalMessageOptions> ? AdditionalMessageOptions : never, AdditionalChatOptions extends object = object> extends BaseChatEngine { | ||
#private; | ||
@@ -85,3 +88,3 @@ abstract createStore(): Store; | ||
static defaultTaskHandler: TaskHandler<LLM>; | ||
protected constructor(params: AgentRunnerParams<AI, Store, AdditionalMessageOptions>); | ||
protected constructor(params: AgentRunnerParams<AI, Store, AdditionalMessageOptions, AdditionalChatOptions>); | ||
get llm(): AI; | ||
@@ -93,15 +96,15 @@ get chatHistory(): ChatMessage<AdditionalMessageOptions>[]; | ||
static shouldContinue<AI extends LLM, Store extends object = object, AdditionalMessageOptions extends object = AI extends LLM<object, infer AdditionalMessageOptions> ? AdditionalMessageOptions : never>(task: Readonly<TaskStep<AI, Store, AdditionalMessageOptions>>): boolean; | ||
createTask(message: MessageContent, stream?: boolean, verbose?: boolean | undefined, chatHistory?: ChatMessage<AdditionalMessageOptions>[]): ReadableStream<TaskStepOutput<AI, Store, AdditionalMessageOptions>>; | ||
chat(params: NonStreamingChatEngineParams): Promise<EngineResponse>; | ||
chat(params: StreamingChatEngineParams): Promise<ReadableStream<EngineResponse>>; | ||
createTask(message: MessageContent, stream?: boolean, verbose?: boolean | undefined, chatHistory?: ChatMessage<AdditionalMessageOptions>[], additionalChatOptions?: AdditionalChatOptions): ReadableStream<TaskStepOutput<AI, Store, AdditionalMessageOptions, AdditionalChatOptions>>; | ||
chat(params: NonStreamingChatEngineParams<AdditionalMessageOptions, AdditionalChatOptions>): Promise<EngineResponse>; | ||
chat(params: StreamingChatEngineParams<AdditionalMessageOptions, AdditionalChatOptions>): Promise<ReadableStream<EngineResponse>>; | ||
} | ||
type LLMParamsBase = AgentParamsBase<LLM>; | ||
type LLMParamsWithTools = LLMParamsBase & { | ||
type LLMParamsBase<AI extends LLM, AdditionalMessageOptions extends object = AI extends LLM<object, infer AdditionalMessageOptions> ? AdditionalMessageOptions : never, AdditionalChatOptions extends object = object> = AgentParamsBase<AI, AdditionalMessageOptions, AdditionalChatOptions>; | ||
type LLMParamsWithTools<AI extends LLM, AdditionalMessageOptions extends object = AI extends LLM<object, infer AdditionalMessageOptions> ? AdditionalMessageOptions : never, AdditionalChatOptions extends object = object> = LLMParamsBase<AI, AdditionalMessageOptions, AdditionalChatOptions> & { | ||
tools: BaseToolWithCall[]; | ||
}; | ||
type LLMParamsWithToolRetriever = LLMParamsBase & { | ||
type LLMParamsWithToolRetriever<AI extends LLM, AdditionalMessageOptions extends object = AI extends LLM<object, infer AdditionalMessageOptions> ? AdditionalMessageOptions : never, AdditionalChatOptions extends object = object> = LLMParamsBase<AI, AdditionalMessageOptions, AdditionalChatOptions> & { | ||
toolRetriever: ObjectRetriever<BaseToolWithCall>; | ||
}; | ||
type LLMAgentParams = LLMParamsWithTools | LLMParamsWithToolRetriever; | ||
type LLMAgentParams<AI extends LLM, AdditionalMessageOptions extends object = AI extends LLM<object, infer AdditionalMessageOptions> ? AdditionalMessageOptions : never, AdditionalChatOptions extends object = object> = LLMParamsWithTools<AI, AdditionalMessageOptions, AdditionalChatOptions> | LLMParamsWithToolRetriever<AI, AdditionalMessageOptions, AdditionalChatOptions>; | ||
declare class LLMAgentWorker extends AgentWorker<LLM> { | ||
@@ -111,3 +114,3 @@ taskHandler: TaskHandler<LLM<object, object>>; | ||
declare class LLMAgent extends AgentRunner<LLM> { | ||
constructor(params: LLMAgentParams); | ||
constructor(params: LLMAgentParams<LLM>); | ||
createStore: typeof AgentRunner.defaultCreateStore; | ||
@@ -114,0 +117,0 @@ taskHandler: TaskHandler<LLM<object, object>>; |
@@ -732,3 +732,3 @@ import { emptyLogger, consoleLogger, randomUUID } from '@llamaindex/env'; | ||
this.defaultTaskHandler = async (step, enqueueOutput)=>{ | ||
const { llm, getTools, stream } = step.context; | ||
const { llm, getTools, stream, additionalChatOptions } = step.context; | ||
const lastMessage = step.context.store.messages.at(-1).content; | ||
@@ -742,3 +742,4 @@ const tools = await getTools(lastMessage); | ||
...step.context.store.messages | ||
] | ||
], | ||
additionalChatOptions | ||
}); | ||
@@ -757,3 +758,4 @@ await stepTools({ | ||
...step.context.store.messages | ||
] | ||
], | ||
additionalChatOptions | ||
}); | ||
@@ -799,3 +801,3 @@ await stepToolsStreaming({ | ||
} | ||
createTask(message, stream = false, verbose = undefined, chatHistory) { | ||
createTask(message, stream = false, verbose = undefined, chatHistory, additionalChatOptions) { | ||
const initialMessages = [ | ||
@@ -818,2 +820,3 @@ ...chatHistory ?? this.#chatHistory | ||
llm: this.#llm, | ||
additionalChatOptions: additionalChatOptions ?? {}, | ||
getTools: (message)=>this.getTools(message), | ||
@@ -837,3 +840,3 @@ store: { | ||
} | ||
const task = this.createTask(params.message, !!params.stream, false, chatHistory); | ||
const task = this.createTask(params.message, !!params.stream, false, chatHistory, params.chatOptions); | ||
for await (const stepOutput of task){ | ||
@@ -840,0 +843,0 @@ // update chat history for each round |
@@ -16,7 +16,9 @@ import * as ___llms from '../../llms/dist/index.js'; | ||
} | ||
interface StreamingChatEngineParams<AdditionalMessageOptions extends object = object> extends BaseChatEngineParams<AdditionalMessageOptions> { | ||
interface StreamingChatEngineParams<AdditionalMessageOptions extends object = object, AdditionalChatOptions extends object = object> extends BaseChatEngineParams<AdditionalMessageOptions> { | ||
stream: true; | ||
chatOptions?: AdditionalChatOptions; | ||
} | ||
interface NonStreamingChatEngineParams<AdditionalMessageOptions extends object = object> extends BaseChatEngineParams<AdditionalMessageOptions> { | ||
interface NonStreamingChatEngineParams<AdditionalMessageOptions extends object = object, AdditionalChatOptions extends object = object> extends BaseChatEngineParams<AdditionalMessageOptions> { | ||
stream?: false; | ||
chatOptions?: AdditionalChatOptions; | ||
} | ||
@@ -23,0 +25,0 @@ declare abstract class BaseChatEngine { |
{ | ||
"name": "@llamaindex/core", | ||
"type": "module", | ||
"version": "0.4.8", | ||
"version": "0.4.9", | ||
"description": "LlamaIndex Core Module", | ||
@@ -6,0 +6,0 @@ "exports": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
720426
15891