diff --git a/api/src/main/java/com/theokanning/openai/completion/chat/ChatFunctionCallArgumentsSerializerAndDeserializer.java b/api/src/main/java/com/theokanning/openai/completion/chat/ChatFunctionCallArgumentsSerializerAndDeserializer.java index 960a4c5..ac8a16e 100644 --- a/api/src/main/java/com/theokanning/openai/completion/chat/ChatFunctionCallArgumentsSerializerAndDeserializer.java +++ b/api/src/main/java/com/theokanning/openai/completion/chat/ChatFunctionCallArgumentsSerializerAndDeserializer.java @@ -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; diff --git a/service/src/main/java/com/theokanning/openai/service/OpenAiService.java b/service/src/main/java/com/theokanning/openai/service/OpenAiService.java index 86532ef..d1c85b3 100644 --- a/service/src/main/java/com/theokanning/openai/service/OpenAiService.java +++ b/service/src/main/java/com/theokanning/openai/service/OpenAiService.java @@ -743,15 +743,16 @@ public Flowable mapStreamToAccumulator(Flowable { 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); @@ -783,9 +784,12 @@ public Flowable mapStreamToAccumulator(Flowable