Skip to content

Commit 22fc51b

Browse files
committed
Add tests
1 parent 95a7d78 commit 22fc51b

File tree

8 files changed

+95
-1
lines changed

8 files changed

+95
-1
lines changed

pom.xml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>io.github.alexcheng1982</groupId>
88
<artifactId>spring-ai-dashscope-client</artifactId>
9-
<version>0.1.1</version>
9+
<version>0.2.0</version>
1010

1111
<name>Aliyun Dashscope Spring AI Client</name>
1212
<description>Aliyun Dashscope Spring AI Client</description>
@@ -65,10 +65,25 @@
6565
<artifactId>dashscope-sdk-java</artifactId>
6666
<version>${dashscope-sdk.version}</version>
6767
</dependency>
68+
69+
<dependency>
70+
<groupId>org.junit.jupiter</groupId>
71+
<artifactId>junit-jupiter-api</artifactId>
72+
<version>5.10.2</version>
73+
<scope>test</scope>
74+
</dependency>
6875
</dependencies>
6976

7077
<build>
7178
<plugins>
79+
<plugin>
80+
<groupId>org.apache.maven.plugins</groupId>
81+
<artifactId>maven-surefire-plugin</artifactId>
82+
<version>3.2.5</version>
83+
<configuration>
84+
<excludedGroups>manual</excludedGroups>
85+
</configuration>
86+
</plugin>
7287
<plugin>
7388
<groupId>org.sonatype.central</groupId>
7489
<artifactId>central-publishing-maven-plugin</artifactId>

src/main/java/io/github/alexcheng1982/springai/dashscope/DashscopeChatClient.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
import org.springframework.util.Assert;
3131
import org.springframework.util.CollectionUtils;
3232

33+
/**
34+
* Spring AI {@linkplain ChatClient} for Aliyun Dashscope
35+
*/
3336
public class DashscopeChatClient extends
3437
AbstractFunctionCallSupport<Message, ChatCompletionRequest, GenerationResult> implements
3538
ChatClient {
@@ -59,6 +62,15 @@ public DashscopeChatClient(DashscopeApi dashscopeApi,
5962
this.defaultOptions = options;
6063
}
6164

65+
/**
66+
* Create a {@linkplain DashscopeChatClient} with default options
67+
*
68+
* @return A {@linkplain DashscopeChatClient}
69+
*/
70+
public static DashscopeChatClient createDefault() {
71+
return new DashscopeChatClient(new DashscopeApi());
72+
}
73+
6274
@Override
6375
public ChatResponse call(Prompt prompt) {
6476
var generationResult = callWithFunctionSupport(createRequest(prompt));

src/main/java/io/github/alexcheng1982/springai/dashscope/DashscopeChatOptions.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
import org.springframework.ai.model.function.FunctionCallingOptions;
1111
import org.springframework.util.Assert;
1212

13+
/**
14+
* {@linkplain ChatOptions} of Aliyun Dashscope
15+
*
16+
* @see DashscopeChatClient
17+
*/
1318
public class DashscopeChatOptions implements FunctionCallingOptions,
1419
ChatOptions {
1520

src/main/java/io/github/alexcheng1982/springai/dashscope/api/DashscopeApi.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
import java.util.Objects;
1414
import java.util.Optional;
1515

16+
/**
17+
* Dashscope API
18+
*/
1619
public class DashscopeApi {
1720

1821
private final Generation generation;

src/main/java/io/github/alexcheng1982/springai/dashscope/metadata/DashscopeChatResponseMetadata.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import org.springframework.ai.chat.metadata.ChatResponseMetadata;
55
import org.springframework.ai.chat.metadata.Usage;
66

7+
/**
8+
* {@linkplain ChatResponseMetadata} implementation of Aliyun Dashscope
9+
*/
710
public class DashscopeChatResponseMetadata implements ChatResponseMetadata {
811

912
private final DashscopeUsage usage;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package io.github.alexcheng1982.springai.dashscope;
2+
3+
import static org.junit.jupiter.api.Assertions.assertNotNull;
4+
5+
import org.junit.jupiter.api.Test;
6+
7+
/**
8+
* This test requires a Dashscope API key
9+
*/
10+
@Manual
11+
class DashscopeChatClientTest {
12+
13+
@Test
14+
void smokeTest() {
15+
var client = DashscopeChatClient.createDefault();
16+
var response = client.call("hello");
17+
assertNotNull(response);
18+
}
19+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package io.github.alexcheng1982.springai.dashscope;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import io.github.alexcheng1982.springai.dashscope.api.DashscopeModelName;
6+
import org.junit.jupiter.api.Test;
7+
8+
class DashscopeChatOptionsTest {
9+
10+
@Test
11+
void testChatOptions() {
12+
var options = DashscopeChatOptions.builder()
13+
.withModel(DashscopeModelName.QWEN_MAX)
14+
.withTemperature(0.2f)
15+
.build();
16+
assertEquals(DashscopeModelName.QWEN_MAX, options.getModel());
17+
assertEquals(0.2f, options.getTemperature());
18+
options = DashscopeChatOptions.builder(options)
19+
.withTemperature(0.7f)
20+
.build();
21+
assertEquals(0.7f, options.getTemperature());
22+
}
23+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package io.github.alexcheng1982.springai.dashscope;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
import org.junit.jupiter.api.Tag;
8+
9+
@Target({ElementType.TYPE, ElementType.METHOD})
10+
@Retention(RetentionPolicy.RUNTIME)
11+
@Tag("manual")
12+
public @interface Manual {
13+
14+
}

0 commit comments

Comments
 (0)