这是indexloc提供的服务,不要输入任何密码
Skip to content

删除deserializer中是否为json的判断 #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ public JsonNode deserialize(JsonParser p, DeserializationContext ctxt) throws IO
return null;
}

if (!isValidJson(json)) {
// encode to valid JSON escape otherwise we will lose quotes
json = MAPPER.writeValueAsString(json);
}
json = MAPPER.writeValueAsString(json);

try {
JsonNode node = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -743,15 +743,16 @@ public Flowable<ChatMessageAccumulator> mapStreamToAccumulator(Flowable<ChatComp
return flowable.map(chunk -> {
ChatCompletionChoice firstChoice = chunk.getChoices().get(0);
AssistantMessage messageChunk = firstChoice.getMessage();
ChatFunctionCall chunkFunctionCall = new ChatFunctionCall(null, null);
if (messageChunk.getFunctionCall() != null) {
if (messageChunk.getFunctionCall().getName() != null) {
String namePart = messageChunk.getFunctionCall().getName();
functionCall.setName((functionCall.getName() == null ? "" : functionCall.getName()) + namePart);
chunkFunctionCall.setName((functionCall.getName() == null ? "" : functionCall.getName()) + namePart);
}
if (messageChunk.getFunctionCall().getArguments() != null) {
String argumentsPart = messageChunk.getFunctionCall().getArguments().asText();
if (!argumentsPart.isEmpty()) {
functionCall.setArguments(new TextNode((functionCall.getArguments() == null ? "" : functionCall.getArguments().asText()) + argumentsPart));
chunkFunctionCall.setArguments(new TextNode((functionCall.getArguments() == null ? "" : functionCall.getArguments().asText()) + argumentsPart));
}
}
accumulatedMessage.setFunctionCall(functionCall);
Expand Down Expand Up @@ -783,9 +784,12 @@ public Flowable<ChatMessageAccumulator> mapStreamToAccumulator(Flowable<ChatComp
}

if (firstChoice.getFinishReason() != null) { // last
if ("function_call".equals(firstChoice.getFinishReason()) && functionCall.getArguments() != null) {
functionCall.setArguments(mapper.readTree(functionCall.getArguments().asText()));
accumulatedMessage.setFunctionCall(functionCall);
if ("function_call".equals(firstChoice.getFinishReason())) {
if (chunkFunctionCall.getArguments() != null) {
functionCall.setName(chunkFunctionCall.getName());
functionCall.setArguments(mapper.readTree(chunkFunctionCall.getArguments().asText()));
accumulatedMessage.setFunctionCall(functionCall);
}
}
if ("tool_calls".equals(firstChoice.getFinishReason()) && accumulatedMessage.getToolCalls() != null) {
//按照index重新排序
Expand Down