Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

format: fix formatting violations #25

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
* @author Ken
*/
public class DashScopeAiStreamFunctionCallingHelper {

private Boolean incrementalOutput = false;

public DashScopeAiStreamFunctionCallingHelper() {
Expand All @@ -64,18 +65,20 @@ public ChatCompletionChunk merge(ChatCompletionChunk previous, ChatCompletionChu
Choice previousChoice0 = previous.output() == null ? null : previous.output().choices().get(0);
Choice currentChoice0 = current.output() == null ? null : current.output().choices().get(0);

//compatibility of incremental_output false for streaming function call
// compatibility of incremental_output false for streaming function call
if (!incrementalOutput && isStreamingToolFunctionCall(current)) {
if (!isStreamingToolFunctionCallFinish(current)) {
return new ChatCompletionChunk(id, new ChatCompletionOutput(null, List.of(new Choice(null, null))), usage);
} else {
return new ChatCompletionChunk(id, new ChatCompletionOutput(null, List.of(new Choice(null, null))),
usage);
}
else {
return new ChatCompletionChunk(id, new ChatCompletionOutput(null, List.of(currentChoice0)), usage);
}
}

Choice choice = merge(previousChoice0, currentChoice0);
List<Choice> chunkChoices = choice == null ? List.of() : List.of(choice);
return new ChatCompletionChunk(id, new ChatCompletionOutput(null, chunkChoices), usage);
return new ChatCompletionChunk(id, new ChatCompletionOutput(null, chunkChoices), usage);
}

private Choice merge(Choice previous, Choice current) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1249,8 +1249,10 @@ public Flux<ChatCompletionChunk> chatCompletionStream(ChatCompletionRequest chat
Assert.isTrue(chatRequest.stream(), "Request must set the stream property to true.");

AtomicBoolean isInsideTool = new AtomicBoolean(false);
boolean incrementalOutput = chatRequest.parameters() != null && chatRequest.parameters().incrementalOutput != null && chatRequest.parameters().incrementalOutput;
DashScopeAiStreamFunctionCallingHelper chunkMerger = new DashScopeAiStreamFunctionCallingHelper(incrementalOutput);
boolean incrementalOutput = chatRequest.parameters() != null
&& chatRequest.parameters().incrementalOutput != null && chatRequest.parameters().incrementalOutput;
DashScopeAiStreamFunctionCallingHelper chunkMerger = new DashScopeAiStreamFunctionCallingHelper(
incrementalOutput);

return this.webClient.post()
.uri("/api/v1/services/aigc/text-generation/generation")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,10 @@ void streamTest() throws InterruptedException, IOException {
.build();

Flux<ChatResponse> response = chatClient.prompt()
.user("如何快速开始百炼?")
.options(DashScopeChatOptions.builder()
.withIncrementalOutput(true)
.build())
.stream()
.chatResponse();
.user("如何快速开始百炼?")
.options(DashScopeChatOptions.builder().withIncrementalOutput(true).build())
.stream()
.chatResponse();

CountDownLatch cdl = new CountDownLatch(1);
response.subscribe(data -> {
Expand Down Expand Up @@ -195,12 +193,10 @@ void streamCallWithFunctionAndRagTest() throws InterruptedException, IOException
.build();

Flux<ChatResponse> response = chatClient.prompt()
.user("上海今天的天气如何?")
.options(DashScopeChatOptions.builder()
.withIncrementalOutput(true)
.build())
.stream()
.chatResponse();
.user("上海今天的天气如何?")
.options(DashScopeChatOptions.builder().withIncrementalOutput(true).build())
.stream()
.chatResponse();

CountDownLatch cdl = new CountDownLatch(1);
response.subscribe(data -> {
Expand Down Expand Up @@ -339,7 +335,8 @@ void embed() {

@Test
void vectorStore() {
DashScopeCloudStore cloudStore = new DashScopeCloudStore(dashscopeChatApi, new DashScopeStoreOptions("诺成SpringAI"));
DashScopeCloudStore cloudStore = new DashScopeCloudStore(dashscopeChatApi,
new DashScopeStoreOptions("诺成SpringAI"));
List<Document> documentList = Arrays.asList(
new Document("file_f0b6b18b14994ed8a0b45648ce5d0da5_10001", "abc", new HashMap<>()),
new Document("file_d3083d64026d4864b4558d18f9ca2a6d_10001", "abc", new HashMap<>()),
Expand Down