@@ -16,7 +16,7 @@ import { GPTMessages2Chats } from '@fastgpt/global/core/chat/adapt';
1616import type { AIChatItemType } from '@fastgpt/global/core/chat/type' ;
1717import { formatToolResponse , initToolCallEdges , initToolNodes } from './utils' ;
1818import { computedMaxToken } from '../../../../ai/utils' ;
19- import { sliceStrStartEnd } from '@fastgpt/global/common/string/tools' ;
19+ import { truncateStrRespectingJson } from '@fastgpt/global/common/string/tools' ;
2020import type { WorkflowInteractiveResponseType } from '@fastgpt/global/core/workflow/template/system/interactive/type' ;
2121import { ChatItemValueTypeEnum } from '@fastgpt/global/core/chat/constants' ;
2222import { getErrText } from '@fastgpt/global/common/error/utils' ;
@@ -28,23 +28,23 @@ type ToolRunResponseType = {
2828 toolMsgParams : ChatCompletionToolMessageParam ;
2929} [ ] ;
3030
31- /*
31+ /*
3232 调用思路:
3333 先Check 是否是交互节点触发
34-
34+
3535 交互模式:
3636 1. 从缓存中获取工作流运行数据
3737 2. 运行工作流
3838 3. 检测是否有停止信号或交互响应
3939 - 无:汇总结果,递归运行工具
4040 - 有:缓存结果,结束调用
41-
41+
4242 非交互模式:
4343 1. 组合 tools
4444 2. 过滤 messages
4545 3. Load request llm messages: system prompt, histories, human question, (assistant responses, tool responses, assistant responses....)
4646 4. 请求 LLM 获取结果
47-
47+
4848 - 有工具调用
4949 1. 批量运行工具的工作流,获取结果(工作流原生结果,工具执行结果)
5050 2. 合并递归中,所有工具的原生运行结果
@@ -126,7 +126,7 @@ export const runToolCall = async (
126126 toolName : '' ,
127127 toolAvatar : '' ,
128128 params : '' ,
129- response : sliceStrStartEnd ( stringToolResponse , 5000 , 5000 )
129+ response : truncateStrRespectingJson ( stringToolResponse , 5000 , 5000 )
130130 }
131131 }
132132 } ) ;
@@ -407,7 +407,7 @@ export const runToolCall = async (
407407 toolName : '' ,
408408 toolAvatar : '' ,
409409 params : '' ,
410- response : sliceStrStartEnd ( stringToolResponse , 5000 , 5000 )
410+ response : truncateStrRespectingJson ( stringToolResponse , 5000 , 5000 )
411411 }
412412 }
413413 } ) ;
@@ -426,7 +426,7 @@ export const runToolCall = async (
426426 toolName : '' ,
427427 toolAvatar : '' ,
428428 params : '' ,
429- response : sliceStrStartEnd ( err , 5000 , 5000 )
429+ response : truncateStrRespectingJson ( err , 5000 , 5000 )
430430 }
431431 }
432432 } ) ;
@@ -437,7 +437,7 @@ export const runToolCall = async (
437437 tool_call_id : tool . id ,
438438 role : ChatCompletionRequestMessageRoleEnum . Tool ,
439439 name : tool . function . name ,
440- content : sliceStrStartEnd ( err , 5000 , 5000 )
440+ content : truncateStrRespectingJson ( err , 5000 , 5000 )
441441 }
442442 } ) ;
443443 }
@@ -460,7 +460,7 @@ export const runToolCall = async (
460460 : usage . outputTokens ;
461461
462462 if ( toolCalls . length > 0 ) {
463- /*
463+ /*
464464 ...
465465 user
466466 assistant: tool data
@@ -471,7 +471,7 @@ export const runToolCall = async (
471471 ...toolsRunResponse . map ( ( item ) => item ?. toolMsgParams )
472472 ] ;
473473
474- /*
474+ /*
475475 Get tool node assistant response
476476 - history assistant
477477 - current tool assistant
0 commit comments