toolCall 修改
This commit is contained in:
parent
0670cf8318
commit
515a19f322
@ -10,7 +10,12 @@ export class TaskLoop {
|
||||
private readonly streamingToolCalls: Ref<ToolCall[]>,
|
||||
private readonly messages: ChatMessage[],
|
||||
private readonly onError: (msg: string) => void
|
||||
) {}
|
||||
) {
|
||||
if (!onError) {
|
||||
this.onError = (msg) => {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private handleToolCalls(toolCalls: ToolCall[]) {
|
||||
// 这里预留给调用方实现工具执行逻辑
|
||||
@ -22,6 +27,7 @@ export class TaskLoop {
|
||||
const chunkHandler = this.bridge.addCommandListener('llm/chat/completions/chunk', data => {
|
||||
if (data.code !== 200) {
|
||||
this.onError(data.msg || '请求模型服务时发生错误');
|
||||
|
||||
reject(new Error(data.msg));
|
||||
return;
|
||||
}
|
||||
@ -113,4 +119,10 @@ export class TaskLoop {
|
||||
this.onError(error instanceof Error ? error.message : '未知错误');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// bridge api
|
||||
public async name() {
|
||||
|
||||
}
|
||||
}
|
@ -51,7 +51,7 @@ import { defineComponent, defineProps, watch, ref, computed } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import type { FormInstance, FormRules } from 'element-plus';
|
||||
import { tabs } from '../panel';
|
||||
import { toolsManager, ToolStorage } from './tools';
|
||||
import { callTool, toolsManager, ToolStorage } from './tools';
|
||||
import { CasualRestAPI, ToolCallResponse } from '@/hook/type';
|
||||
import { useMessageBridge } from '@/api/message-bridge';
|
||||
|
||||
@ -111,24 +111,11 @@ const resetForm = () => {
|
||||
tabStorage.lastToolCallResponse = undefined;
|
||||
};
|
||||
|
||||
function handleExecute() {
|
||||
async function handleExecute() {
|
||||
if (!currentTool.value) return;
|
||||
|
||||
const bridge = useMessageBridge();
|
||||
|
||||
bridge.addCommandListener('tools/call', (data: CasualRestAPI<ToolCallResponse>) => {
|
||||
console.log(data.msg);
|
||||
|
||||
tabStorage.lastToolCallResponse = data.msg;
|
||||
}, { once: true });
|
||||
|
||||
bridge.postMessage({
|
||||
command: 'tools/call',
|
||||
data: {
|
||||
toolName: tabStorage.currentToolName,
|
||||
toolArgs: formData.value
|
||||
}
|
||||
});
|
||||
const toolResponse = await callTool(tabStorage.currentToolName, formData.value);
|
||||
tabStorage.lastToolCallResponse = toolResponse;
|
||||
}
|
||||
|
||||
watch(() => tabStorage.currentToolName, () => {
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { ToolsListResponse, ToolCallResponse } from '@/hook/type';
|
||||
import { useMessageBridge } from '@/api/message-bridge';
|
||||
import { ToolsListResponse, ToolCallResponse, CasualRestAPI } from '@/hook/type';
|
||||
import { reactive } from 'vue';
|
||||
|
||||
export const toolsManager = reactive<{
|
||||
@ -10,4 +11,25 @@ export const toolsManager = reactive<{
|
||||
export interface ToolStorage {
|
||||
currentToolName: string;
|
||||
lastToolCallResponse?: ToolCallResponse;
|
||||
}
|
||||
|
||||
const bridge = useMessageBridge();
|
||||
|
||||
export function callTool(toolName: string, toolArgs: Record<string, any>) {
|
||||
return new Promise<ToolCallResponse>((resolve, reject) => {
|
||||
bridge.addCommandListener('tools/call', (data: CasualRestAPI<ToolCallResponse>) => {
|
||||
console.log(data.msg);
|
||||
|
||||
if (data.code !== 200) {
|
||||
reject(new Error(data.msg + ''));
|
||||
} else {
|
||||
resolve(data.msg);
|
||||
}
|
||||
}, { once: true });
|
||||
|
||||
bridge.postMessage({
|
||||
command: 'tools/call',
|
||||
data: { toolName, toolArgs }
|
||||
});
|
||||
});
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"currentIndex": 0,
|
||||
"currentIndex": 1,
|
||||
"tabs": [
|
||||
{
|
||||
"name": "交互测试",
|
||||
@ -43,6 +43,24 @@
|
||||
"systemPrompt": ""
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "工具",
|
||||
"icon": "icon-tool",
|
||||
"type": "blank",
|
||||
"componentIndex": 2,
|
||||
"storage": {
|
||||
"lastToolCallResponse": {
|
||||
"content": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": "4"
|
||||
}
|
||||
],
|
||||
"isError": false
|
||||
},
|
||||
"currentToolName": "add"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user