-
Notifications
You must be signed in to change notification settings - Fork 220
Expand file tree
/
Copy pathAIAgentExample.java
More file actions
136 lines (121 loc) · 4.26 KB
/
Copy pathAIAgentExample.java
File metadata and controls
136 lines (121 loc) · 4.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package io.rong.example.agent;
import io.rong.CenterEnum;
import io.rong.RongCloud;
import io.rong.methods.agent.AIAgent;
import io.rong.models.agent.*;
import io.rong.models.response.ChatAgentResult;
import io.rong.models.response.GetAIAgentResult;
import io.rong.models.response.PagingQueryAgentsResult;
import io.rong.models.response.ResponseResult;
/**
* AI agent test example
*
* @author RongCloud
*/
public class AIAgentExample {
/**
* Replace with your App Key
*/
private static final String APP_KEY = "appKey";
/**
* Replace with your App Secret
*/
private static final String APP_SECRET = "secret";
/**
* Initialization
*/
private static AIAgent agent = RongCloud.getInstance(APP_KEY, APP_SECRET, CenterEnum.BJ).agent;
/**
* Local test call
*
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
// Create agent test
createTest();
// Delete agent test
deleteTest();
// Update agent test
updateTest();
// Get agent test
getTest();
// Query agent list test
queryListTest();
// Test chat
chatTest();
}
private static void chatTest() throws Exception {
ChatModel model = new ChatModel();
model.setAgentId("test_agentg_3821633206");
model.setMemory(true);
model.setConversationId("test_id");
model.setUser("uid1");
model.setQuery("Hello");
ChatAgentResult result = agent.chat(model);
System.out.println("Chat to agent test: " + result.toString());
}
private static void createTest() throws Exception {
AgentModel info = new AgentModel();
info.setAgentId("rc_agentId");
info.setName("rc_name");
info.setDescription("rc_description");
info.setType("chat");
info.setStatus("active");
AgentConfig agentConfig = new AgentConfig();
Model model = new Model();
model.setProvider("openai");
model.setName("qwen-turbo");
ModelOptions modelOptions = new ModelOptions();
model.setOptions(modelOptions);
agentConfig.setModel(model);
Prompt prompt = new Prompt();
// prompt.setId("temp_id");
agentConfig.setPrompt(prompt);
Memory memory = new Memory();
memory.setStrategy("sliding_window");
memory.setMaxMessages(10);
memory.setMaxTokens(1000);
agentConfig.setMemory(memory);
info.setAgentConfig(agentConfig);
ResponseResult result = agent.create(info);
System.out.println("create agent test: " + result.toString());
}
private static void getTest() throws Exception {
GetAIAgentResult result = agent.get("rc_agentId");
System.out.println("update agent test: " + result.toString());
}
private static void deleteTest() throws Exception {
ResponseResult result = agent.delete("rc_agentId");
System.out.println("delete agent test: " + result.toString());
}
private static void updateTest() throws Exception {
AgentModel info = new AgentModel();
info.setAgentId("rc_agentId");
info.setName("rc_name111");
info.setDescription("rc_description111");
info.setType("chat");
info.setStatus("active");
AgentConfig agentConfig = new AgentConfig();
Model model = new Model();
model.setProvider("openai");
model.setName("qwen-turbo");
ModelOptions modelOptions = new ModelOptions();
model.setOptions(modelOptions);
agentConfig.setModel(model);
Prompt prompt = new Prompt();
agentConfig.setPrompt(prompt);
Memory memory = new Memory();
memory.setStrategy("sliding_window");
memory.setMaxMessages(10);
memory.setMaxTokens(1000);
agentConfig.setMemory(memory);
info.setAgentConfig(agentConfig);
ResponseResult result = agent.update(info);
System.out.println("update agent test: " + result.toString());
}
private static void queryListTest() throws Exception {
PagingQueryAgentsResult result = agent.query(1, 2, "active", "chat");
System.out.println("update agent test: " + result.toString());
}
}