mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-11 12:07:42 +00:00
[improvement](chat) optimize functionCall result format (#549)
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
package com.tencent.supersonic.chat.parser.sql.llm;
|
package com.tencent.supersonic.chat.parser.sql.llm;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.tencent.supersonic.chat.parser.plugin.function.FunctionResp;
|
import com.tencent.supersonic.chat.parser.plugin.function.FunctionResp;
|
||||||
import com.tencent.supersonic.common.util.JsonUtil;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -114,15 +115,11 @@ public class OutputFormat {
|
|||||||
|
|
||||||
public static FunctionResp functionCallParse(String llmOutput) {
|
public static FunctionResp functionCallParse(String llmOutput) {
|
||||||
try {
|
try {
|
||||||
String[] findResult = llmOutput.split(PATTERN);
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
String result = findResult[0].trim();
|
JsonNode jsonNode = objectMapper.readTree(llmOutput);
|
||||||
|
String selectedTool = jsonNode.get("选择工具").asText();
|
||||||
Map<String, String> resultDict = JsonUtil.toMap(result, String.class, String.class);
|
|
||||||
log.info("result:{},resultDict:{}", result, resultDict);
|
|
||||||
|
|
||||||
String selection = resultDict.get("选择工具");
|
|
||||||
FunctionResp resp = new FunctionResp();
|
FunctionResp resp = new FunctionResp();
|
||||||
resp.setToolSelection(selection);
|
resp.setToolSelection(selectedTool);
|
||||||
return resp;
|
return resp;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("", e);
|
log.error("", e);
|
||||||
|
|||||||
Reference in New Issue
Block a user