Skip to content
Closed
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 @@ -63,14 +63,15 @@ public ChatCompletionChunk merge(ChatCompletionChunk previous, ChatCompletionChu
String id = (current.requestId() != null ? current.requestId() : previous.requestId());
TokenUsage usage = (current.usage() != null ? current.usage() : previous.usage());

Choice previousChoice0 = previous.output() == null ? null : previous.output().choices().get(0);
Choice currentChoice0 = current.output() == null ? null : current.output().choices().get(0);
Choice previousChoice0 = previous.output() == null ? null
: CollectionUtils.isEmpty(previous.output().choices()) ? null : previous.output().choices().get(0);
Choice currentChoice0 = current.output() == null ? null
: CollectionUtils.isEmpty(current.output().choices()) ? null : current.output().choices().get(0);

// 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);
return new ChatCompletionChunk(id, new ChatCompletionOutput(null, List.of()), usage);
}
else {
return new ChatCompletionChunk(id, new ChatCompletionOutput(null, List.of(currentChoice0)), usage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,8 @@
*/
package com.alibaba.cloud.ai.dashscope.api;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.List;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import com.alibaba.cloud.ai.dashscope.api.DashScopeApi.ChatCompletionChunk;
import com.alibaba.cloud.ai.dashscope.api.DashScopeApi.ChatCompletionFinishReason;
import com.alibaba.cloud.ai.dashscope.api.DashScopeApi.ChatCompletionMessage;
Expand All @@ -35,6 +26,10 @@
import com.alibaba.cloud.ai.dashscope.api.DashScopeApi.ChatCompletionOutput;
import com.alibaba.cloud.ai.dashscope.api.DashScopeApi.ChatCompletionOutput.Choice;
import com.alibaba.cloud.ai.dashscope.api.DashScopeApi.TokenUsage;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

/**
* Tests for DashScopeAiStreamFunctionCallingHelper class functionality
Expand Down Expand Up @@ -146,7 +141,8 @@ void testChunkToChatCompletion() {
void testMergeWithNonIncrementalOutput() {
// Test merging in non-incremental output mode
ChatCompletionChunk previous = createChunkWithToolCall("request-1", "tool-1", "function-1", "{\"param");
ChatCompletionChunk current = createChunkWithToolCall("request-1", "tool-1", "function-1", "\":\"value\"}");
ChatCompletionChunk current = createChunkWithToolCall("request-1", "tool-1", "function-1",
"{\"param\":\"value\"}");

// Use helper with non-incremental output
ChatCompletionChunk result = helper.merge(previous, current);
Expand All @@ -156,16 +152,15 @@ void testMergeWithNonIncrementalOutput() {
assertNotNull(result);
assertEquals("request-1", result.requestId());
assertNotNull(result.output().choices());
assertEquals(1, result.output().choices().size());
assertNull(result.output().choices().get(0).message());
assertEquals(0, result.output().choices().size());
}

@Test
void testMergeWithNonIncrementalOutputFinished() {
// Test merging of finished tool calls in non-incremental output mode
ChatCompletionChunk previous = createChunkWithToolCall("request-1", "tool-1", "function-1", "{\"param");
ChatCompletionChunk current = createChunkWithToolCall("request-1", "tool-1", "function-1", "\":\"value\"}",
ChatCompletionFinishReason.TOOL_CALLS);
ChatCompletionChunk current = createChunkWithToolCall("request-1", "tool-1", "function-1",
"{\"param\":\"value\"}", ChatCompletionFinishReason.TOOL_CALLS);

// Use helper with non-incremental output
ChatCompletionChunk result = helper.merge(previous, current);
Expand All @@ -182,7 +177,7 @@ void testMergeWithNonIncrementalOutputFinished() {
assertEquals(1, toolCalls.size());
assertEquals("tool-1", toolCalls.get(0).id());
assertEquals("function-1", toolCalls.get(0).function().name());
assertEquals("\":\"value\"}", toolCalls.get(0).function().arguments());
assertEquals("{\"param\":\"value\"}", toolCalls.get(0).function().arguments());
}

@Test
Expand Down
3 changes: 2 additions & 1 deletion spring-ai-alibaba-graph/spring-ai-alibaba-graph-core/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<!--
Copyright 2025-2026 the original author or authors.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,26 @@
*/
package com.alibaba.cloud.ai.graph.checkpoint.savers;

import com.alibaba.cloud.ai.graph.RunnableConfig;
import com.alibaba.cloud.ai.graph.checkpoint.BaseCheckpointSaver;
import com.alibaba.cloud.ai.graph.checkpoint.Checkpoint;

import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.stream.IntStream;

import com.alibaba.cloud.ai.graph.RunnableConfig;
import com.alibaba.cloud.ai.graph.checkpoint.BaseCheckpointSaver;
import com.alibaba.cloud.ai.graph.checkpoint.Checkpoint;

import static java.lang.String.format;
import static java.util.Collections.unmodifiableCollection;

public class MemorySaver implements BaseCheckpointSaver {

private final Map<String, LinkedList<Checkpoint>> _checkpointsByThread = new HashMap<>();
private final Map<String, LinkedList<Checkpoint>> _checkpointsByThread = new ConcurrentHashMap<>();

private final LinkedList<Checkpoint> _defaultCheckpoints = new LinkedList<>();

Expand Down
Loading