feat(chat): update tool listing to include path, key, and parameters in prompts
- Modified tools list to display tool path and key along with descriptions. - Added handling for tool parameters in the prompt. - Updated JSON format in prompts to reflect changes in tool identification. - Changed label from "智能体" to "执行体" for clarity.
This commit is contained in:
@@ -19,8 +19,14 @@ export const Chat = () => {
|
||||
setIsLoading(true);
|
||||
const { routes } = studioStore;
|
||||
let callPrompts = '';
|
||||
const toolsList = routes.map((r, index) =>
|
||||
`${index + 1}. 工具名称: ${r.id}\n 描述: ${r.description}`
|
||||
const toolsList = routes.map((r, index) => {
|
||||
const args = r.metadata?.args || {};
|
||||
let argsDescription = '';
|
||||
if (Object.keys(args).length > 0) {
|
||||
argsDescription = ',参数: ' + JSON.stringify(args);
|
||||
}
|
||||
return `${index + 1}. 工具名称: path: ${r.path} key: ${r.key}\n 描述: ${r.description}${argsDescription}`;
|
||||
}
|
||||
).join('\n\n');
|
||||
|
||||
callPrompts = `你是一个 AI 助手,你可以使用以下工具来帮助用户完成任务:
|
||||
@@ -34,7 +40,8 @@ ${toolsList}
|
||||
## JSON 数据格式
|
||||
\`\`\`json
|
||||
{
|
||||
"id": "工具的id",
|
||||
"path": "工具的path",
|
||||
"key": "工具的key",
|
||||
"payload": {
|
||||
// 工具所需的参数(如果需要)
|
||||
// 例如: "id": "xxx", "name": "xxx"
|
||||
@@ -45,7 +52,7 @@ ${toolsList}
|
||||
注意:
|
||||
- payload 中包含工具执行所需的所有参数
|
||||
- 如果工具不需要参数,payload 可以为空对象 {}
|
||||
- 确保返回的 id 与上述工具列表中的工具名称完全匹配`
|
||||
- 确保返回的 path 和 key 与上述工具列表中的工具名称完全匹配`
|
||||
|
||||
const res = await query.post({
|
||||
path: 'ai',
|
||||
@@ -69,7 +76,7 @@ ${toolsList}
|
||||
// 处理返回结果
|
||||
const payload = res.data?.action;
|
||||
if (payload) {
|
||||
const route = routes.find(r => r.id === payload.id);
|
||||
const route = routes.find(r => r.path === payload.path && r.key === payload.key);
|
||||
const { path, key } = route || {};
|
||||
const { id, ...otherParams } = payload.payload || {};
|
||||
const action = { path, key, ...otherParams }
|
||||
@@ -101,7 +108,7 @@ ${toolsList}
|
||||
}
|
||||
return <div className="h-full flex flex-col border-l border-gray-300 bg-white">
|
||||
<div style={{ height: '3rem' }} className="flex items-center justify-between px-4 border-b border-gray-300 bg-gray-50">
|
||||
<div className="text-sm text-gray-600">智能体</div>
|
||||
<div className="text-sm text-gray-600">执行体</div>
|
||||
</div>
|
||||
<div style={{ height: 'calc(100% - 3rem)' }} className="overflow-auto">
|
||||
<QueryViewMessages type="component" />
|
||||
|
||||
Reference in New Issue
Block a user