openai-java
openai-java copied to clipboard
when i use version 0.11 , i get Unrecognized token 'data': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
I got an error like "Unrecognized token 'data': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')",When I use the stream property of the CompletionRequest object. I My guess is that the openAi service was developed in python. Service support is 'true' instead of true.
CompletionRequest completionRequest = CompletionRequest.builder()
.prompt(question)
.model(openAiChattingBody.getModel())
.maxTokens(DEFAULT_MAX_TOKEN)
.temperature(DEFAULT_TEMPERATURE)
.topP(1.0)
.frequencyPenalty(0.0)
.presencePenalty(0.0)
.stream(Boolean.TRUE)
.echo(false)
.stop(STOPS)
.build();
I want you to take care of it
Confirmed.
CompletionRequest(model=text-davinci-003, prompt=woodchucks?, maxTokens=500, temperature=0.7, topP=1.0, n=null, stream=true, logprobs=null, echo=false, stop=[
, Human:, AI:], presencePenalty=0.0, frequencyPenalty=0.0, bestOf=null, logitBias=null, user=null)
Exception in thread "main" java.lang.RuntimeException: com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'data': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
at [Source: (okhttp3.ResponseBody$BomAwareReader); line: 1, column: 5]
at io.reactivex.internal.util.ExceptionHelper.wrapOrThrow(ExceptionHelper.java:46)
at io.reactivex.internal.observers.BlockingMultiObserver.blockingGet(BlockingMultiObserver.java:93)
at io.reactivex.Single.blockingGet(Single.java:2870)
at com.theokanning.openai.OpenAiService.createCompletion(OpenAiService.java:116)
at CryptoApeBot4.main(CryptoApeBot4.java:181)
Caused by: com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'data': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
at [Source: (okhttp3.ResponseBody$BomAwareReader); line: 1, column: 5]
at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:2418)
I met the same problem and asked for help
The above problem is also encountered. When stream=true is not used, there is no such problem
re.Json
yes
It looks like the stream includes data and data: DONE, so the jackson parser is trying to parse a partial result.
Because stream is set to true, I haven't found a way to handle the sse message returned by stream. I don't know if it is not supported
just for fun, I set it to false and the call succeeded, so I don't think it's a problem w/ the actual value, just how it's handled in the response. I wonder if the way to fix it is just to add a BufferedReader in CompletionResult and depending on the stream boolean, CompletionRequest either return the List of choices of the BodyHandlers.ofInputStream() in the HttpResponse.
BufferedReader data = new BufferedReader(new InputStreamReader(...));
// Receives the response body as an InputStream
HttpResponse<InputStream> response = client
.send(request, BodyHandlers.ofInputStream());
Then if you were expecting a stream, you just read from the stream.
Any progress on this issue? I am facing thew exact same problem.
Thx. Franz
I thought #183 or #186 had a checkin w/ this feature. Take a look at those issues to see if it solves your problem.
0.12.0 is live with streaming support :+1: