From 609737e84a7a6fab09739f99260f279a8e965c19 Mon Sep 17 00:00:00 2001 From: HamaWhite Date: Sat, 5 Aug 2023 11:07:02 +0800 Subject: [PATCH] Fix bug #64: UnrecognizedPropertyException in CompletionResp --- openai-client/src/main/java/com/hw/openai/OpenAiClient.java | 3 +++ .../java/com/hw/openai/entity/completions/CompletionResp.java | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/openai-client/src/main/java/com/hw/openai/OpenAiClient.java b/openai-client/src/main/java/com/hw/openai/OpenAiClient.java index 458648f78..e4b73b76e 100644 --- a/openai-client/src/main/java/com/hw/openai/OpenAiClient.java +++ b/openai-client/src/main/java/com/hw/openai/OpenAiClient.java @@ -18,6 +18,7 @@ package com.hw.openai; +import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.hw.openai.entity.chat.ChatCompletion; import com.hw.openai.entity.chat.ChatCompletionResp; @@ -133,6 +134,8 @@ public OpenAiClient init() { // Used for automatic discovery and registration of Jackson modules ObjectMapper objectMapper = new ObjectMapper(); objectMapper.findAndRegisterModules(); + // Ignore unknown fields + objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); Retrofit retrofit = new Retrofit.Builder() .baseUrl(openaiApiBase) diff --git a/openai-client/src/main/java/com/hw/openai/entity/completions/CompletionResp.java b/openai-client/src/main/java/com/hw/openai/entity/completions/CompletionResp.java index 30522ef02..4057e52a5 100644 --- a/openai-client/src/main/java/com/hw/openai/entity/completions/CompletionResp.java +++ b/openai-client/src/main/java/com/hw/openai/entity/completions/CompletionResp.java @@ -29,8 +29,6 @@ @Data public class CompletionResp { - private String warning; - private String id; private String object;