Skip to content

Commit 753657c

Browse files
committed
Merge branch 'v4.0.5' into 'master'
feat: Add Chatbot and AI Agent. See merge request public-server/server-sdk-java!24
2 parents c578000 + 5652ec9 commit 753657c

32 files changed

Lines changed: 2465 additions & 241 deletions

README-CN.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ RongCloud IM Server SDK in Java.
1111
<dependency>
1212
<groupId>cn.rongcloud.im</groupId>
1313
<artifactId>server-sdk-java</artifactId>
14-
<version>4.0.4</version>
14+
<version>4.0.5</version>
1515
</dependency>
1616
```
1717
* Gradle
1818
```
19-
compile group: 'cn.rongcloud.im', name: 'server-sdk-java', version: '4.0.4'
19+
compile group: 'cn.rongcloud.im', name: 'server-sdk-java', version: '4.0.5'
2020
2121
```
2222
* 基于源码 Meavn 打包构建
@@ -83,6 +83,12 @@ RongCloud IM Server SDK in Java.
8383

8484
###### [超级群模块示例](./src/main/java/io/rong/example/ultragroup)
8585

86+
###### [用户、好友、群组托管示例](src/main/java/io/rong/example/profile)
87+
88+
###### [聊天机器人示例](src/main/java/io/rong/example/chatbot)
89+
90+
###### [AI agent 示例](src/main/java/io/rong/example/agent)
91+
8692

8793
# 版本说明
8894
为方便开发者的接入使用,更好的对融云 Server SDK 进行维护管理,现更新SDK 3.8.0,需强制设置服务器地址。

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ RongCloud IM Server SDK in Java.
1010
<dependency>
1111
<groupId>cn.rongcloud.im</groupId>
1212
<artifactId>server-sdk-java</artifactId>
13-
<version>4.0.4</version>
13+
<version>4.0.5</version>
1414
</dependency>
1515
```
1616
* Gradle
1717
```
18-
compile group: 'cn.rongcloud.im', name: 'server-sdk-java', version: '4.0.4'
18+
compile group: 'cn.rongcloud.im', name: 'server-sdk-java', version: '4.0.5'
1919
```
2020
* Build from source
2121
```

Server SDK Supported Feature Version List.md

Lines changed: 249 additions & 236 deletions
Large diffs are not rendered by default.

pom.xml

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

77
<groupId>cn.rongcloud.im</groupId>
88
<artifactId>server-sdk-java</artifactId>
9-
<version>4.0.4</version>
9+
<version>4.0.5</version>
1010
<packaging>jar</packaging>
1111
<name>RongCloud IM Server SDK</name>
1212
<description>

src/main/java/io/rong/RongCloud.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
*/
88
package io.rong;
99

10+
import io.rong.methods.agent.AIAgent;
11+
import io.rong.methods.chatbot.Chatbot;
1012
import io.rong.methods.chatroom.Chatroom;
1113
import io.rong.methods.conversation.Conversation;
1214
import io.rong.methods.group.Group;
@@ -43,6 +45,8 @@ public class RongCloud {
4345
public EntrustGroup entrustGroup;
4446
public Friend friend;
4547
public EntrustUser entrustUser;
48+
public Chatbot chatbot;
49+
public AIAgent agent;
4650
public final RongCloudConfig config;
4751

4852
public RongCloudConfig getConfig() {
@@ -78,6 +82,8 @@ private RongCloud(String appKey, String appSecret, RongCloudConfig config) {
7882
entrustGroup = new EntrustGroup(appKey, appSecret, this);
7983
friend = new Friend(appKey, appSecret, this);
8084
entrustUser = new EntrustUser(appKey, appSecret, this);
85+
chatbot = new Chatbot(appKey, appSecret, this);
86+
agent = new AIAgent(appKey, appSecret, this);
8187
this.config = config;
8288
}
8389

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
package io.rong.example.agent;
2+
3+
import io.rong.CenterEnum;
4+
import io.rong.RongCloud;
5+
import io.rong.methods.agent.AIAgent;
6+
import io.rong.models.agent.*;
7+
import io.rong.models.response.ChatAgentResult;
8+
import io.rong.models.response.GetAIAgentResult;
9+
import io.rong.models.response.PagingQueryAgentsResult;
10+
import io.rong.models.response.ResponseResult;
11+
12+
/**
13+
* AI agent test example
14+
*
15+
* @author RongCloud
16+
*/
17+
public class AIAgentExample {
18+
19+
20+
/**
21+
* Replace with your App Key
22+
*/
23+
private static final String APP_KEY = "appKey";
24+
/**
25+
* Replace with your App Secret
26+
*/
27+
private static final String APP_SECRET = "secret";
28+
/**
29+
* Initialization
30+
*/
31+
private static AIAgent agent = RongCloud.getInstance(APP_KEY, APP_SECRET, CenterEnum.BJ).agent;
32+
33+
34+
/**
35+
* Local test call
36+
*
37+
* @param args
38+
* @throws Exception
39+
*/
40+
public static void main(String[] args) throws Exception {
41+
// Create agent test
42+
createTest();
43+
// Delete agent test
44+
deleteTest();
45+
// Update agent test
46+
updateTest();
47+
// Get agent test
48+
getTest();
49+
// Query agent list test
50+
queryListTest();
51+
52+
// Test chat
53+
chatTest();
54+
}
55+
56+
private static void chatTest() throws Exception {
57+
ChatModel model = new ChatModel();
58+
model.setAgentId("test_agentg_3821633206");
59+
model.setMemory(true);
60+
model.setConversationId("test_id");
61+
model.setUser("uid1");
62+
model.setQuery("Hello");
63+
ChatAgentResult result = agent.chat(model);
64+
System.out.println("Chat to agent test: " + result.toString());
65+
}
66+
67+
private static void createTest() throws Exception {
68+
AgentModel info = new AgentModel();
69+
info.setAgentId("rc_agentId");
70+
info.setName("rc_name");
71+
info.setDescription("rc_description");
72+
info.setType("chat");
73+
info.setStatus("active");
74+
AgentConfig agentConfig = new AgentConfig();
75+
Model model = new Model();
76+
model.setProvider("openai");
77+
model.setName("qwen-turbo");
78+
ModelOptions modelOptions = new ModelOptions();
79+
model.setOptions(modelOptions);
80+
agentConfig.setModel(model);
81+
Prompt prompt = new Prompt();
82+
// prompt.setId("temp_id");
83+
agentConfig.setPrompt(prompt);
84+
Memory memory = new Memory();
85+
memory.setStrategy("sliding_window");
86+
memory.setMaxMessages(10);
87+
memory.setMaxTokens(1000);
88+
agentConfig.setMemory(memory);
89+
info.setAgentConfig(agentConfig);
90+
ResponseResult result = agent.create(info);
91+
System.out.println("create agent test: " + result.toString());
92+
}
93+
94+
private static void getTest() throws Exception {
95+
GetAIAgentResult result = agent.get("rc_agentId");
96+
System.out.println("update agent test: " + result.toString());
97+
}
98+
99+
private static void deleteTest() throws Exception {
100+
ResponseResult result = agent.delete("rc_agentId");
101+
System.out.println("delete agent test: " + result.toString());
102+
}
103+
104+
private static void updateTest() throws Exception {
105+
AgentModel info = new AgentModel();
106+
info.setAgentId("rc_agentId");
107+
info.setName("rc_name111");
108+
info.setDescription("rc_description111");
109+
info.setType("chat");
110+
info.setStatus("active");
111+
AgentConfig agentConfig = new AgentConfig();
112+
Model model = new Model();
113+
model.setProvider("openai");
114+
model.setName("qwen-turbo");
115+
ModelOptions modelOptions = new ModelOptions();
116+
model.setOptions(modelOptions);
117+
agentConfig.setModel(model);
118+
Prompt prompt = new Prompt();
119+
agentConfig.setPrompt(prompt);
120+
Memory memory = new Memory();
121+
memory.setStrategy("sliding_window");
122+
memory.setMaxMessages(10);
123+
memory.setMaxTokens(1000);
124+
agentConfig.setMemory(memory);
125+
info.setAgentConfig(agentConfig);
126+
ResponseResult result = agent.update(info);
127+
System.out.println("update agent test: " + result.toString());
128+
}
129+
130+
private static void queryListTest() throws Exception {
131+
PagingQueryAgentsResult result = agent.query(1, 2, "active", "chat");
132+
System.out.println("update agent test: " + result.toString());
133+
}
134+
135+
136+
}
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
package io.rong.example.chatbot;
2+
3+
import io.rong.CenterEnum;
4+
import io.rong.RongCloud;
5+
import io.rong.methods.chatbot.Chatbot;
6+
import io.rong.models.bot.ChatbotInfoModel;
7+
import io.rong.models.bot.ChatbotIntegration;
8+
import io.rong.models.bot.SetChatbotIntegration;
9+
import io.rong.models.response.*;
10+
11+
import java.util.List;
12+
13+
/**
14+
* Chatbot test example
15+
*
16+
* @author RongCloud
17+
*/
18+
public class ChatbotExample {
19+
20+
/**
21+
* Replace with your App Key
22+
*/
23+
private static final String APP_KEY = "appKey";
24+
/**
25+
* Replace with your App Secret
26+
*/
27+
private static final String APP_SECRET = "secret";
28+
/**
29+
* Initialization
30+
*/
31+
private static Chatbot chatbot = RongCloud.getInstance(APP_KEY, APP_SECRET, CenterEnum.BJ).chatbot;
32+
33+
/**
34+
* Local test call
35+
*
36+
* @param args
37+
* @throws Exception
38+
*/
39+
public static void main(String[] args) throws Exception {
40+
// Create chatbot test
41+
createTest();
42+
// Delete chatbot test
43+
deleteTest();
44+
// Query chatbot list test
45+
queryChatbotListTest();
46+
// Get chatbot test
47+
getChatbotTest();
48+
// Update chatbot test
49+
updateTest();
50+
// Add chatbot integration test
51+
createIntegrationTest();
52+
// Delete chatbot integration test
53+
deleteIntegrationTest();
54+
// Update chatbot integration list test
55+
updateIntegrationTest();
56+
}
57+
58+
59+
private static void createTest() throws Exception {
60+
ChatbotInfoModel info = new ChatbotInfoModel();
61+
info.setUserId("bot_uid1");
62+
info.setName("name");
63+
info.setType("type");
64+
info.setProfileUrl("profileUrl");
65+
info.setMetadata(new java.util.HashMap<String, String>());
66+
List<ChatbotIntegration> integrations = new java.util.ArrayList<>();
67+
ChatbotIntegration chatbotIntegration = new ChatbotIntegration();
68+
chatbotIntegration.setType("webhook");
69+
chatbotIntegration.setCallbackUrl("callbackUrl");
70+
integrations.add(chatbotIntegration);
71+
info.setIntegrations(integrations);
72+
ResponseResult result = chatbot.create(info);
73+
System.out.println("create chatbot test: " + result.toString());
74+
}
75+
76+
private static void updateIntegrationTest() throws Exception {
77+
SetChatbotIntegration info = new SetChatbotIntegration();
78+
info.setCallbackUrl("https://ws");
79+
info.setUserId("bot_uid1");
80+
info.setType("webhook");
81+
ResponseResult result = chatbot.updateIntegration(info);
82+
System.out.println("update chat bot integration test: " + result.toString());
83+
}
84+
85+
private static void deleteIntegrationTest() throws Exception {
86+
ResponseResult result = chatbot.deleteIntegration("bot_uid1", "webhook");
87+
System.out.println("delete chat bot integration test: " + result.toString());
88+
}
89+
90+
91+
private static void createIntegrationTest() throws Exception {
92+
SetChatbotIntegration chatbotIntegration = new SetChatbotIntegration();
93+
chatbotIntegration.setType("webhook");
94+
chatbotIntegration.setCallbackUrl("callbackUrl2");
95+
chatbotIntegration.setUserId("bot_uid1");
96+
ResponseResult result = chatbot.createIntegration(chatbotIntegration);
97+
System.out.println("add chat bot integration test: " + result.toString());
98+
}
99+
100+
101+
private static void updateTest() throws Exception {
102+
ChatbotInfoModel info = new ChatbotInfoModel();
103+
info.setUserId("bot_uid1");
104+
info.setName("name");
105+
info.setType("type");
106+
info.setProfileUrl("profileUrl1");
107+
info.setMetadata(new java.util.HashMap<String, String>());
108+
List<ChatbotIntegration> integrations = new java.util.ArrayList<>();
109+
ChatbotIntegration chatbotIntegration = new ChatbotIntegration();
110+
chatbotIntegration.setType("webhook");
111+
chatbotIntegration.setCallbackUrl("callbackUrl1");
112+
integrations.add(chatbotIntegration);
113+
info.setIntegrations(integrations);
114+
ResponseResult result = chatbot.update(info);
115+
System.out.println("update chatbot test: " + result.toString());
116+
}
117+
118+
private static void getChatbotTest() throws Exception {
119+
QueryChatbotsResult result = chatbot.get("bot_uid1");
120+
System.out.println("get chatbot test: " + result.toString());
121+
}
122+
123+
private static void queryChatbotListTest() throws Exception {
124+
PagingQueryChatbotsResult result = chatbot.query(1, 2, true);
125+
System.out.println("query chatbot test: " + result.toString());
126+
}
127+
128+
private static void deleteTest() throws Exception {
129+
ResponseResult result = chatbot.delete("bot_uid1");
130+
System.out.println("delete chatbot test: " + result.toString());
131+
}
132+
133+
134+
}

0 commit comments

Comments
 (0)