update task-loop type
This commit is contained in:
parent
2db3ab8888
commit
942755b3e6
@ -39,7 +39,8 @@ export class TaskLoop {
|
||||
private onError: (error: IErrorMssage) => void = (msg) => {};
|
||||
private onChunk: (chunk: ChatCompletionChunk) => void = (chunk) => {};
|
||||
private onDone: () => void = () => {};
|
||||
private onToolCalled: (toolCallResult: ToolCallResult) => void = (toolCall) => {};
|
||||
private onToolCall: (toolCall: ToolCall) => ToolCall = toolCall => toolCall;
|
||||
private onToolCalled: (toolCallResult: ToolCallResult) => ToolCallResult = toolCallResult => toolCallResult;
|
||||
private onEpoch: () => void = () => {};
|
||||
private completionUsage: ChatCompletionChunk['usage'] | undefined;
|
||||
private llmConfig: any;
|
||||
@ -220,6 +221,10 @@ export class TaskLoop {
|
||||
this.streamingToolCalls.value = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 注册 error 发生时触发的回调函数
|
||||
* @param handler
|
||||
*/
|
||||
public registerOnError(handler: (msg: IErrorMssage) => void) {
|
||||
this.onError = handler;
|
||||
}
|
||||
@ -228,15 +233,35 @@ export class TaskLoop {
|
||||
this.onChunk = handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 注册 chat.completion 完成时触发的回调函数
|
||||
* @param handler
|
||||
*/
|
||||
public registerOnDone(handler: () => void) {
|
||||
this.onDone = handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 注册每一个 epoch 开始时触发的回调函数
|
||||
* @param handler
|
||||
*/
|
||||
public registerOnEpoch(handler: () => void) {
|
||||
this.onEpoch = handler;
|
||||
}
|
||||
|
||||
public registerOnToolCalled(handler: (toolCallResult: ToolCallResult) => void) {
|
||||
/**
|
||||
* @description 注册当工具调用前的回调函数,可以拦截并修改 toolcall 的输入
|
||||
* @param handler
|
||||
*/
|
||||
public registerOnToolCall(handler: (toolCall: ToolCall) => ToolCall) {
|
||||
this.onToolCall = handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 注册当工具调用完成时的回调函数,会调用这个方法,可以拦截并修改 toolcall 的输出
|
||||
* @param handler
|
||||
*/
|
||||
public registerOnToolCalled(handler: (toolCallResult: ToolCallResult) => ToolCallResult) {
|
||||
this.onToolCalled = handler;
|
||||
}
|
||||
|
||||
@ -335,6 +360,8 @@ export class TaskLoop {
|
||||
pinkLog('调用工具数量:' + this.streamingToolCalls.value.length);
|
||||
|
||||
for (const toolCall of this.streamingToolCalls.value || []) {
|
||||
|
||||
|
||||
const toolCallResult = await handleToolCalls(toolCall);
|
||||
this.onToolCalled(toolCallResult);
|
||||
|
||||
|
42
resources/openmcp-sdk-release/task-loop.d.ts
vendored
42
resources/openmcp-sdk-release/task-loop.d.ts
vendored
@ -80,15 +80,46 @@ export class TaskLoop {
|
||||
private doConversation;
|
||||
makeChatData(tabStorage: any): ChatCompletionCreateParamsBase | undefined;
|
||||
abort(): void;
|
||||
|
||||
/**
|
||||
* @description 注册 error 发生时触发的回调函数
|
||||
* @param handler
|
||||
*/
|
||||
registerOnError(handler: (msg: IErrorMssage) => void): void;
|
||||
registerOnChunk(handler: (chunk: ChatCompletionChunk) => void): void;
|
||||
|
||||
/**
|
||||
* @description 注册 chat.completion 完成时触发的回调函数
|
||||
* @param handler
|
||||
*/
|
||||
registerOnDone(handler: () => void): void;
|
||||
|
||||
/**
|
||||
* @description 注册每一个 epoch 开始时触发的回调函数
|
||||
* @param handler
|
||||
*/
|
||||
registerOnEpoch(handler: () => void): void;
|
||||
|
||||
/**
|
||||
* @description 注册当工具调用完成时的回调函数,会调用这个方法,可以拦截并修改 toolcall 的输出
|
||||
* @param handler
|
||||
*/
|
||||
registerOnToolCalled(handler: (toolCallResult: ToolCallResult) => void): void;
|
||||
setMaxEpochs(maxEpochs: number): void;
|
||||
|
||||
/**
|
||||
* @description 注册当工具调用前的回调函数,可以拦截并修改 toolcall 的输入
|
||||
* @param handler
|
||||
*/
|
||||
registerOnToolCall(handler: (toolCall: ToolCall) => ToolCall): void;
|
||||
|
||||
/**
|
||||
* @description 获取当前的 LLM 配置
|
||||
*/
|
||||
getLlmConfig(): any;
|
||||
|
||||
/**
|
||||
* @description 设置当前的 LLM 配置,用于 nodejs 环境运行
|
||||
* @param config
|
||||
* @param config
|
||||
* @example
|
||||
* setLlmConfig({
|
||||
* id: 'openai',
|
||||
@ -98,7 +129,12 @@ export class TaskLoop {
|
||||
* })
|
||||
*/
|
||||
setLlmConfig(config: any): void;
|
||||
getLlmConfig(): any;
|
||||
|
||||
/**
|
||||
* @description 设置最大 epoch 次数
|
||||
* @param maxEpochs
|
||||
*/
|
||||
setMaxEpochs(maxEpochs: number): void;
|
||||
bindStreaming(content: Ref<string>, toolCalls: Ref<ToolCall[]>): void;
|
||||
connectToService(): Promise<void>;
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user