Skip to content

Commit 012f0be

Browse files
authored
feat: add microsoft translate example (#9)
* feat: add microsoft translate example Signed-off-by: PolarishT <zhangzhenting@corp.netease.com> * reactor catalog Signed-off-by: PolarishT <zhangzhenting@corp.netease.com> * update functions naming Signed-off-by: PolarishT <zhangzhenting@corp.netease.com> * modified module naming Signed-off-by: PolarishT <zhangzhenting@corp.netease.com> --------- Signed-off-by: PolarishT <zhangzhenting@corp.netease.com>
1 parent 55e33dc commit 012f0be

File tree

14 files changed

+229
-476
lines changed

14 files changed

+229
-476
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
<module>spring-ai-alibaba-chat-example</module>
5858
<module>spring-ai-alibaba-Integration-example</module>
5959
<module>spring-ai-alibaba-image-example</module>
60-
<module>spring-ai-alibaba-function-example</module>
60+
<module>spring-ai-alibaba-function-calling-example</module>
6161
<module>spring-ai-alibaba-multi-model-example</module>
6262
<module>spring-ai-alibaba-observability-example</module>
6363
<module>spring-ai-alibaba-plugin-example</module>
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!--
4+
Copyright 2023-2024 the original author or authors.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
https://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
19+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20+
xmlns="http://maven.apache.org/POM/4.0.0"
21+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
22+
<modelVersion>4.0.0</modelVersion>
23+
24+
<parent>
25+
<groupId>com.alibaba.cloud.ai</groupId>
26+
<artifactId>spring-ai-alibaba-examples</artifactId>
27+
<version>${revision}</version>
28+
<relativePath>../pom.xml</relativePath>
29+
</parent>
30+
31+
<version>${revision}</version>
32+
<artifactId>spring-ai-alibaba-function-calling-example</artifactId>
33+
<packaging>pom</packaging>
34+
35+
<description>Spring AI Alibaba Function Calling Example</description>
36+
<name>Spring AI Alibaba Function Calling Examples</name>
37+
38+
<properties>
39+
40+
<junit-jupiter.version>5.10.0</junit-jupiter.version>
41+
42+
<!-- Spring AI Alibaba -->
43+
<spring-ai-alibaba.version>1.0.0-M3.2</spring-ai-alibaba.version>
44+
</properties>
45+
46+
<dependencies>
47+
48+
<dependency>
49+
<groupId>com.alibaba.cloud.ai</groupId>
50+
<artifactId>spring-ai-alibaba-starter</artifactId>
51+
<version>${spring-ai-alibaba.version}</version>
52+
</dependency>
53+
54+
<dependency>
55+
<groupId>com.alibaba.cloud.ai</groupId>
56+
<artifactId>spring-ai-alibaba-starter-functioncalling-microsofttranslate</artifactId>
57+
<version>${spring-ai-alibaba.version}</version>
58+
</dependency>
59+
60+
<dependency>
61+
<groupId>com.alibaba.cloud.ai</groupId>
62+
<artifactId>spring-ai-alibaba-starter-functioncalling-weather-</artifactId>
63+
<version>${spring-ai-alibaba.version}</version>
64+
</dependency>
65+
<dependency>
66+
<groupId>org.junit.jupiter</groupId>
67+
<artifactId>junit-jupiter</artifactId>
68+
<version>${junit-jupiter.version}</version>
69+
</dependency>
70+
71+
</dependencies>
72+
73+
<build>
74+
<plugins>
75+
<plugin>
76+
<groupId>org.apache.maven.plugins</groupId>
77+
<artifactId>maven-deploy-plugin</artifactId>
78+
<version>${maven-deploy-plugin.version}</version>
79+
<configuration>
80+
<skip>true</skip>
81+
</configuration>
82+
</plugin>
83+
</plugins>
84+
</build>
85+
86+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package com.alibaba.cloud.ai.functioncalling;
18+
19+
import org.springframework.boot.SpringApplication;
20+
import org.springframework.boot.autoconfigure.SpringBootApplication;
21+
22+
/**
23+
* @author 北极星
24+
*/
25+
@SpringBootApplication
26+
public class MainApplication {
27+
28+
public static void main (String[] args) {
29+
SpringApplication.run(MainApplication.class, args);
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package com.alibaba.cloud.ai.functioncalling;
18+
19+
import org.jetbrains.annotations.NotNull;
20+
import org.junit.jupiter.api.Test;
21+
import org.slf4j.Logger;
22+
import org.slf4j.LoggerFactory;
23+
import org.springframework.ai.chat.client.ChatClient;
24+
25+
/**
26+
* @author 北极星
27+
*/
28+
public class MicroSoftTranslateTest {
29+
30+
private static final Logger log = LoggerFactory.getLogger(MicroSoftTranslateTest.class);
31+
32+
private final ChatClient chatClient;
33+
34+
public MicroSoftTranslateTest (@NotNull ChatClient.Builder chatClientBuilder) {
35+
this.chatClient = chatClientBuilder.build();
36+
}
37+
38+
/**
39+
* 微软翻译
40+
*
41+
* @link <a href="https://api.cognitive.microsofttranslator.com"/a>
42+
* 版本号 version 3.0
43+
* ApplicationYml spring.ai.alibaba.functioncalling.microsofttranslate 传入 api-key
44+
*/
45+
@Test
46+
protected void microSoftTranslateFunctionCallingTest () {
47+
String text = "你好,spring-ai-alibaba!";
48+
49+
String ans = chatClient.prompt().functions("microSoftTranslateFunction").user(text).call().content();
50+
log.info("translated text -> : ${}", ans);
51+
}
52+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package com.alibaba.cloud.ai.functioncalling;
18+
19+
import org.jetbrains.annotations.NotNull;
20+
import org.junit.jupiter.api.Test;
21+
import org.slf4j.Logger;
22+
import org.slf4j.LoggerFactory;
23+
import org.springframework.ai.chat.client.ChatClient;
24+
25+
/**
26+
* @author 北极星
27+
*/
28+
public class WeatherTest {
29+
private static final Logger log = LoggerFactory.getLogger(MicroSoftTranslateTest.class);
30+
31+
private final ChatClient chatClient;
32+
33+
public WeatherTest (@NotNull ChatClient.Builder chatClientBuilder) {
34+
this.chatClient = chatClientBuilder.build();
35+
}
36+
37+
/**
38+
* 天气服务
39+
*
40+
* @link <a href="https://api.weatherapi.com/v1/forecast.json"/a>
41+
* ApplicationYml spring.ai.alibaba.functioncalling.weather 传入 api-key
42+
*/
43+
@Test
44+
protected void microSoftTranslateFunctionCallingTest () {
45+
String text = "你好,spring-ai-alibaba!";
46+
47+
String ans = chatClient.prompt().functions("getWeatherServiceFunction").user(text).call().content();
48+
log.info("weather text -> : ${}", ans);
49+
}
50+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
spring:
2+
ai:
3+
alibaba:
4+
plugin:
5+
translate:
6+
api-key:${Translate-key}
7+
8+
dashscope:
9+
api-key: ${dashscope-key}

spring-ai-alibaba-function-example/function-calling-example/pom.xml

Lines changed: 0 additions & 129 deletions
This file was deleted.

0 commit comments

Comments
 (0)