Grt1228 / chatgpt-java

ChatGPT Java SDK支持流式输出、Gpt插件、联网。支持OpenAI官方所有接口。ChatGPT的Java客户端。OpenAI GPT-3.5-Turb GPT-4 Api Client for Java
https://chatgpt-java.unfbx.com
Apache License 2.0
3.3k stars 810 forks source link

completions接口返回异常 Caused by: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "warning" (class com.unfbx.chatgpt.entity.completions.CompletionResponse), not marked as ignorable (8 known properties: "usage", "choices", "error", "model", "data", "id", "object", "created"]) at [Source: (okhttp3.ResponseBody$BomAwareReader); line: 2, column: 15] (through reference chain: com.unfbx.chatgpt.entity.completions.CompletionResponse["warning"]) #197

Closed bleachyin closed 1 year ago

bleachyin commented 1 year ago

测试用例中: @Test public void completions() { // CompletionResponse completions = v2.completions("Java Stream list to map"); // Arrays.stream(completions.getChoices()).forEach(System.out::println);

    CompletionResponse completions = v2.completions("我想申请转专业,从计算机专业转到会计学专业,帮我完成一份两百字左右的申请书");
    Arrays.stream(completions.getChoices()).forEach(System.out::println);
}

这段会 抛出异常 at io.reactivex.Single.blockingGet(Single.java:2870) at com.unfbx.chatgpt.OpenAiClient.completions(OpenAiClient.java:226) at OpenAiClientTest.completions(OpenAiClientTest.java:239) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306) at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63) at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329) at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293) at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306) at org.junit.runners.ParentRunner.run(ParentRunner.java:413) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69) at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38) at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11) at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35) at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235) at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54) Caused by: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "warning" (class com.unfbx.chatgpt.entity.completions.CompletionResponse), not marked as ignorable (8 known properties: "usage", "choices", "error", "model", "data", "id", "object", "created"]) at [Source: (okhttp3.ResponseBody$BomAwareReader); line: 2, column: 15] (through reference chain: com.unfbx.chatgpt.entity.completions.CompletionResponse["warning"]) at com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:61) at com.fasterxml.jackson.da

qianmoQ commented 1 year ago

测试用例中: @test public void completions() { // CompletionResponse completions = v2.completions("Java Stream list to map"); // Arrays.stream(completions.getChoices()).forEach(System.out::println);

    CompletionResponse completions = v2.completions("我想申请转专业,从计算机专业转到会计学专业,帮我完成一份两百字左右的申请书");
    Arrays.stream(completions.getChoices()).forEach(System.out::println);
}

这段会 抛出异常 at io.reactivex.Single.blockingGet(Single.java:2870) at com.unfbx.chatgpt.OpenAiClient.completions(OpenAiClient.java:226) at OpenAiClientTest.completions(OpenAiClientTest.java:239) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306) at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63) at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329) at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293) at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306) at org.junit.runners.ParentRunner.run(ParentRunner.java:413) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69) at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38) at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11) at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35) at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235) at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54) Caused by: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "warning" (class com.unfbx.chatgpt.entity.completions.CompletionResponse), not marked as ignorable (8 known properties: "usage", "choices", "error", "model", "data", "id", "object", "created"]) at [Source: (okhttp3.ResponseBody$BomAwareReader); line: 2, column: 15] (through reference chain: com.unfbx.chatgpt.entity.completions.CompletionResponse["warning"]) at com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:61) at com.fasterxml.jackson.da

https://github.com/devlive-community/openai-java-sdk/blob/2582296717f52978049c11bce2d7f6e2c1b653de/src/test/java/org/devlive/sdk/openai/OpenAiClientTest.java#L88

Grt1228 commented 1 year ago

更新最新版 @bleachyin