mirror of
https://github.com/carlrobertoh/ProxyAI.git
synced 2026-05-12 22:31:24 +00:00
Update to latest 233 platform 2023.3.6 (#439)
* Update to latest 233 platform 2023.3.6 * Use first non-blank choice from response
This commit is contained in:
parent
a50e068813
commit
c29d3928db
2 changed files with 20 additions and 3 deletions
|
|
@ -32,9 +32,12 @@ import ee.carlrobert.llm.client.openai.completion.OpenAIChatCompletionEventSourc
|
|||
import ee.carlrobert.llm.client.openai.completion.request.OpenAIChatCompletionRequest;
|
||||
import ee.carlrobert.llm.client.openai.completion.request.OpenAIChatCompletionStandardMessage;
|
||||
import ee.carlrobert.llm.client.openai.completion.response.OpenAIChatCompletionResponse;
|
||||
import ee.carlrobert.llm.client.openai.completion.response.OpenAIChatCompletionResponseChoice;
|
||||
import ee.carlrobert.llm.client.openai.completion.response.OpenAIChatCompletionResponseChoiceDelta;
|
||||
import ee.carlrobert.llm.completion.CompletionEventListener;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.sse.EventSource;
|
||||
|
|
@ -222,11 +225,25 @@ public final class CompletionRequestService {
|
|||
return List.of(LLAMA_CPP, ANTHROPIC, CUSTOM_OPENAI).contains(serviceType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Content of the first choice.
|
||||
* <ul>
|
||||
* <li>Search all choices which are not null</li>
|
||||
* <li>Search all messages which are not null</li>
|
||||
* <li>Use first content which is not null or blank (whitespace)</li>
|
||||
* </ul>
|
||||
*
|
||||
* @return First non-blank content or {@code Optional.empty()}
|
||||
*/
|
||||
private Optional<String> tryExtractContent(OpenAIChatCompletionResponse response) {
|
||||
return response
|
||||
.getChoices()
|
||||
.stream()
|
||||
.findFirst()
|
||||
.map(item -> item.getMessage().getContent());
|
||||
.filter(Objects::nonNull)
|
||||
.map(OpenAIChatCompletionResponseChoice::getMessage)
|
||||
.filter(Objects::nonNull)
|
||||
.map(OpenAIChatCompletionResponseChoiceDelta::getContent)
|
||||
.filter(c -> c != null && !c.isBlank())
|
||||
.findFirst();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue