Skip to content

Commit

Permalink
原逻辑入参为非String和非Map时会出现将toolInput强转为Map报错
Browse files Browse the repository at this point in the history
  • Loading branch information
aimacode committed Mar 8, 2024
1 parent 58cad5b commit bd12e16
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,20 @@ public class ChatOutputParser extends AgentOutputParser {

private static final String FINAL_ANSWER_ACTION = "Final Answer:";

private static Gson GSON_JSON = new GsonBuilder()
.setObjectToNumberStrategy(ToNumberPolicy.LONG_OR_DOUBLE)
.create();
@Override
public AgentResult parse(String text) {
boolean includesAnswer = text.contains(FINAL_ANSWER_ACTION);
try {
String action = text.split("```")[1];
Type mapType = new TypeToken<Map<String, Object>>() {
}.getType();
Map<String, Object> response = new Gson().fromJson(action.strip(), mapType);

/*
* 20230308:修复通过GSON反序列化时将long类型的数值错误的转成了double类型科学计数法
* */
Map<String, Object> response = GSON_JSON.fromJson(action.strip(),mapType);
boolean includesAction = response.containsKey("action") && response.containsKey("action_input");
if (includesAnswer && includesAction) {
throw new OutputParserException(
Expand Down

0 comments on commit bd12e16

Please sign in to comment.