Commit a7de2561 authored by alex yao's avatar alex yao

fix: function call 角色匹配

parent 66ac59c1
......@@ -626,6 +626,13 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
throw new I18nMessageException("exception/call.failure");
}
if (StringUtils.isBlank(result.getMessage())
&& StringUtils.isBlank(result.getFunction().getName())
&& StringUtils.isBlank(result.getFunction().getArguments())
&& StringUtils.isBlank(result.getFinish_reason())) {
continue;
}
if (!(result.getFunction() != null && (StringUtils.isNotBlank(result.getFunction().getName()) || StringUtils.isNotBlank(result.getFunction().getArguments()))) && !isFunctionCall) {
bufferedReader.reset();
break;
......@@ -654,7 +661,8 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
if (functionResult != null) {
// 处理function - 1,获取function_call 2. 调用对应function 3. 返回function_call并且调用LLM 4.获取bufferedReader 返回
Message[] sendMessage = buildFunctionMessage(messageArray, functionName.toString(), functionArguments.toString(), functionResult);
String functionRole = largeModelResponse.getModel().startsWith("qwen") ? LLMRoleEnum.FUNCTION.getRole() : LLMRoleEnum.TOOL.getRole();
Message[] sendMessage = buildFunctionMessage(messageArray, functionName.toString(), functionArguments.toString(), functionResult, functionRole);
largeModelResponse.setMessages(sendMessage);
return llmService.chatChunk(largeModelResponse);
}
......@@ -674,7 +682,7 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
* @param functionResult
* @return
*/
private Message[] buildFunctionMessage(Message[] messageArray, String functionName, String functionArguments, String functionResult) {
private Message[] buildFunctionMessage(Message[] messageArray, String functionName, String functionArguments, String functionResult, String functionRole) {
List<FunctionCall> functionCalls = new ArrayList<>();
FunctionCall functionCall = new FunctionCall();
......@@ -688,7 +696,7 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
assistantMessage.setFunction_call(functionCalls);
Message functionMessage = new Message();
functionMessage.setRole(LLMRoleEnum.FUNCTION.getRole());
functionMessage.setRole(functionRole);
functionMessage.setName(functionName);
functionMessage.setContent(functionResult);
......
......@@ -13,6 +13,8 @@ public enum LLMRoleEnum {
FUNCTION("function"),
TOOL("tool"),
;
private String role;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment