openai-java
openai-java copied to clipboard
Muti row return
If the result from server is muti row, and I get result with this code: completionResult.getChoices(); I Can not get all result but only first or second row, and rest of them are missing
Just set the timeout to a higher value when you declare your service.
/**
* Creates a new OpenAiService that wraps OpenAiApi
*
* @param token OpenAi token string "sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
* @param timeout http read timeout, Duration.ZERO means no timeout
*/
public OpenAiService(final String token, final Duration timeout) {
this(token, BASE_URL, timeout);
}
To use the new Duration parameter instead of int, just declare it inline.
Duration.ofSeconds(55)
ObjectMapper mapper = defaultObjectMapper();
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 7890));
//set here Duration.ofSeconds
OkHttpClient client = defaultClient(token, Duration.ofSeconds(60))
.newBuilder()
.proxy(proxy)
.build();
Retrofit retrofit = defaultRetrofit(client, mapper);
OpenAiApi api = retrofit.create(OpenAiApi.class);
OpenAiService service = new OpenAiService(api);
ChatCompletionRequest completionRequest = ChatCompletionRequest.builder()
.user("user")
.messages(Collections.singletonList(new ChatMessage("user", message)))
.model("gpt-3.5-turbo-0301")
.temperature(0.2d)
.maxTokens(150)
.stop(Arrays.asList("Human:", "AI:"))
.build();
//Still not all results will be returned here
List<ChatCompletionChoice> result = service.createChatCompletion(completionRequest).getChoices();
There should be a way to loop through to get new replies, but I didn't find it