Skip to content

Commit

Permalink
Merge pull request #25 from kevinlin09/fix_formatting_violations
Browse files Browse the repository at this point in the history
format: fix formatting violations
  • Loading branch information
kevinlin09 authored Sep 24, 2024
2 parents 8d17cdc + 258032d commit 4823553
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
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

0 comments on commit 4823553

Please sign in to comment.