Skip to content

Commit b803086

Browse files
authored
Merge pull request #19 from seymourtang/feat/convoai
feat: Add new API: HistoryConvoAIAPI, InterruptConvoAIAPI, and SpeakConvoAIAPI to ConvoAIClient
2 parents 47964e9 + 85de9c8 commit b803086

File tree

16 files changed

+810
-75
lines changed

16 files changed

+810
-75
lines changed

agora-rest-client-core/src/main/java/io/agora/rest/services/convoai/ConvoAIClient.java

Lines changed: 64 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44
import io.agora.rest.core.DefaultContext;
55
import io.agora.rest.services.convoai.req.JoinConvoAIReq;
66
import io.agora.rest.services.convoai.req.ListConvoAIReq;
7+
import io.agora.rest.services.convoai.req.SpeakConvoAIReq;
78
import io.agora.rest.services.convoai.req.UpdateConvoAIReq;
9+
import io.agora.rest.services.convoai.res.HistoryConvoAIRes;
10+
import io.agora.rest.services.convoai.res.InterruptConvoAIRes;
811
import io.agora.rest.services.convoai.res.JoinConvoAIRes;
912
import io.agora.rest.services.convoai.res.ListConvoAIRes;
1013
import io.agora.rest.services.convoai.res.QueryConvoAIRes;
14+
import io.agora.rest.services.convoai.res.SpeakConvoAIRes;
1115
import io.agora.rest.services.convoai.res.UpdateConvoAIRes;
1216
import reactor.core.publisher.Mono;
1317

@@ -18,7 +22,8 @@ public abstract class ConvoAIClient {
1822
/**
1923
* @param convoAIConfig Instance of {@link ConvoAIConfig}.
2024
* @return Returns the Conversational AI engine client instance.
21-
* @brief Creates a Conversational AI engine client with the specified configuration.
25+
* @brief Creates a Conversational AI engine client with the specified
26+
* configuration.
2227
* @since v0.3.0
2328
*/
2429
public static synchronized ConvoAIClient create(ConvoAIConfig convoAIConfig) {
@@ -36,11 +41,13 @@ public static synchronized ConvoAIClient create(ConvoAIConfig convoAIConfig) {
3641
}
3742

3843
/**
39-
* @param request Parameters for the join request to the conversational AI engine, see {@link JoinConvoAIReq}.
44+
* @param request Parameters for the join request to the conversational AI
45+
* engine, see {@link JoinConvoAIReq}.
4046
* @return Returns the join response result, see {@link JoinConvoAIRes}.
4147
* @brief Creates an agent instance and joins the specified RTC channel.
4248
* @example Use this to create an agent instance in an RTC channel.
43-
* @post After successful execution, the agent will join the specified channel. You can perform subsequent operations using the returned agent ID.
49+
* @post After successful execution, the agent will join the specified channel.
50+
* You can perform subsequent operations using the returned agent ID.
4451
* @since v0.3.0
4552
*/
4653
public abstract Mono<JoinConvoAIRes> join(JoinConvoAIReq request);
@@ -49,18 +56,23 @@ public static synchronized ConvoAIClient create(ConvoAIConfig convoAIConfig) {
4956
* @param agentId Agent ID
5057
* @brief Stops the specified agent instance and leaves the RTC channel.
5158
* @example Use this to stop an agent instance.
52-
* @post After successful execution, the agent will be stopped and leave the RTC channel.
53-
* @note Ensure the agent ID has been obtained by calling the join API before using this method.
59+
* @post After successful execution, the agent will be stopped and leave the RTC
60+
* channel.
61+
* @note Ensure the agent ID has been obtained by calling the join API before
62+
* using this method.
5463
* @since v0.3.0
5564
*/
5665
public abstract Mono<Void> leave(String agentId);
5766

5867
/**
59-
* @param request Parameters for listing conversational agents, see {@link ListConvoAIReq}.
60-
* @return Returns the list response result, see {@link ListConvoAIRes} for details.
68+
* @param request Parameters for listing conversational agents, see
69+
* {@link ListConvoAIReq}.
70+
* @return Returns the list response result, see {@link ListConvoAIRes} for
71+
* details.
6172
* @brief Retrieves a list of agents that meet the specified criteria.
6273
* @example Use this to get a list of agents that meet the specified criteria.
63-
* @post After successful execution, a list of agents that meet the specified criteria will be retrieved.
74+
* @post After successful execution, a list of agents that meet the specified
75+
* criteria will be retrieved.
6476
* @since v0.3.0
6577
*/
6678
public abstract Mono<ListConvoAIRes> list(ListConvoAIReq request);
@@ -70,22 +82,61 @@ public static synchronized ConvoAIClient create(ConvoAIConfig convoAIConfig) {
7082
* @return Returns the query response result, see {@link QueryConvoAIRes}
7183
* @brief Query the current status of the specified agent instance.
7284
* @example Use this to get the current status of the specified agent instance.
73-
* @post After successful execution, the current running status information of the specified agent instance will be retrieved.
74-
* @note Ensure the agent ID has been obtained by calling the join API before using this method.
85+
* @post After successful execution, the current running status information of
86+
* the specified agent instance will be retrieved.
87+
* @note Ensure the agent ID has been obtained by calling the join API before
88+
* using this method.
7589
* @since v0.3.0
7690
*/
7791
public abstract Mono<QueryConvoAIRes> query(String agentId);
7892

7993
/**
8094
* @param agentId Agent ID
81-
* @param request Parameters for updating the conversational agent, see {@link UpdateConvoAIReq} for details.
82-
* @return Returns the update response result, see {@link UpdateConvoAIRes}.
95+
* @param request Parameters for updating the conversational agent, see
96+
* {@link UpdateConvoAIReq} for details.
97+
* @return Returns the update response result, see {@link UpdateConvoAIRes}
98+
* for details.
8399
* @brief Adjusts the agent's parameters at runtime.
84100
* @example Use this to adjust the agent's parameters at runtime.
85101
* @post After successful execution, the agent's parameters will be adjusted.
86-
* @note Ensure the agent ID has been obtained by calling the join API before using this method.
102+
* @note Ensure the agent ID has been obtained by calling the join API before
103+
* using this method.
87104
* @since v0.3.0
88105
*/
89106
public abstract Mono<UpdateConvoAIRes> update(String agentId, UpdateConvoAIReq request);
90107

108+
/**
109+
* @brief Acquires the short-term memory of the specified agent instance
110+
* @since v0.4.0
111+
* @example Use this method to acquire the short-term memory of the specified
112+
* agent instance.
113+
* @param agentId Agent ID.
114+
* @return Returns the short-term memory of the specified agent instance. See
115+
* {@link HistoryConvoAIRes} for details.
116+
*/
117+
public abstract Mono<HistoryConvoAIRes> getHistory(String agentId);
118+
119+
/**
120+
* @brief Interrupts the specified agent instance
121+
* @since v0.9.0
122+
* @example Use this method to interrupt the specified agent instance.
123+
* @param agentId Agent ID.
124+
* @return Returns the interrupt response result, see
125+
* {@link InterruptConvoAIRes}.
126+
*/
127+
public abstract Mono<InterruptConvoAIRes> interrupt(String agentId);
128+
129+
/**
130+
* @brief Speaks a custom message for the specified agent instance
131+
* @since v0.9.0
132+
* @example Use this method to speak a custom message for the specified agent
133+
* instance.
134+
* @param agentId Agent ID.
135+
* @param request Request body for the specified agent to speak a custom
136+
* message. See {@link SpeakConvoAIReq} for details.
137+
* @return Returns the response *SpeakResp. See {@link SpeakConvoAIRes} for
138+
* details.
139+
*/
140+
public abstract Mono<SpeakConvoAIRes> speak(String agentId, SpeakConvoAIReq request);
141+
91142
}

agora-rest-client-core/src/main/java/io/agora/rest/services/convoai/ConvoAIClientImpl.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@
55
import io.agora.rest.services.convoai.api.*;
66
import io.agora.rest.services.convoai.req.JoinConvoAIReq;
77
import io.agora.rest.services.convoai.req.ListConvoAIReq;
8+
import io.agora.rest.services.convoai.req.SpeakConvoAIReq;
89
import io.agora.rest.services.convoai.req.UpdateConvoAIReq;
10+
import io.agora.rest.services.convoai.res.HistoryConvoAIRes;
11+
import io.agora.rest.services.convoai.res.InterruptConvoAIRes;
912
import io.agora.rest.services.convoai.res.JoinConvoAIRes;
1013
import io.agora.rest.services.convoai.res.ListConvoAIRes;
1114
import io.agora.rest.services.convoai.res.QueryConvoAIRes;
15+
import io.agora.rest.services.convoai.res.SpeakConvoAIRes;
1216
import io.agora.rest.services.convoai.res.UpdateConvoAIRes;
1317
import reactor.core.publisher.Mono;
1418

@@ -24,6 +28,12 @@ public class ConvoAIClientImpl extends ConvoAIClient {
2428

2529
private final UpdateConvoAIAPI updateConvoAIAPI;
2630

31+
private final HistoryConvoAIAPI historyConvoAIAPI;
32+
33+
private final InterruptConvoAIAPI interruptConvoAIAPI;
34+
35+
private final SpeakConvoAIAPI speakConvoAIAPI;
36+
2737
private final static String chineseMainlandPrefixTpl = "/cn/api/conversational-ai-agent/v2/projects/%s";
2838

2939
private final static String globalPrefixTpl = "/api/conversational-ai-agent/v2/projects/%s";
@@ -35,6 +45,9 @@ protected ConvoAIClientImpl(Context context, ConvoAIServiceRegionEnum serviceReg
3545
listConvoAIAPI = new ListConvoAIAPI(context, pathPrefix);
3646
queryConvoAIAPI = new QueryConvoAIAPI(context, pathPrefix);
3747
updateConvoAIAPI = new UpdateConvoAIAPI(context, pathPrefix);
48+
historyConvoAIAPI = new HistoryConvoAIAPI(context, pathPrefix);
49+
interruptConvoAIAPI = new InterruptConvoAIAPI(context, pathPrefix);
50+
speakConvoAIAPI = new SpeakConvoAIAPI(context, pathPrefix);
3851
}
3952

4053
private String getPathPrefix(Context context, ConvoAIServiceRegionEnum serviceRegionEnum) {
@@ -75,4 +88,16 @@ public Mono<QueryConvoAIRes> query(String agentId) {
7588
public Mono<UpdateConvoAIRes> update(String agentId, UpdateConvoAIReq request) {
7689
return updateConvoAIAPI.handle(agentId, request);
7790
}
91+
92+
public Mono<HistoryConvoAIRes> getHistory(String agentId) {
93+
return historyConvoAIAPI.handle(agentId);
94+
}
95+
96+
public Mono<InterruptConvoAIRes> interrupt(String agentId) {
97+
return interruptConvoAIAPI.handle(agentId);
98+
}
99+
100+
public Mono<SpeakConvoAIRes> speak(String agentId, SpeakConvoAIReq request) {
101+
return speakConvoAIAPI.handle(agentId, request);
102+
}
78103
}

agora-rest-client-core/src/main/java/io/agora/rest/services/convoai/ConvoAIConfig.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ public Builder domainArea(DomainArea domainArea) {
113113
return this;
114114
}
115115

116+
public Builder httpProperty(HttpProperty httpProperty) {
117+
this.httpProperty = httpProperty;
118+
return this;
119+
}
120+
116121
public Builder serverRegion(ConvoAIServiceRegionEnum serverRegion) {
117122
this.serviceRegion = serverRegion;
118123
return this;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package io.agora.rest.services.convoai.api;
2+
3+
import io.agora.rest.core.Context;
4+
import io.agora.rest.services.convoai.res.HistoryConvoAIRes;
5+
import io.netty.handler.codec.http.HttpMethod;
6+
import reactor.core.publisher.Mono;
7+
8+
public class HistoryConvoAIAPI {
9+
private final Context context;
10+
11+
private final String pathPrefix;
12+
13+
public HistoryConvoAIAPI(Context context, String pathPrefix) {
14+
this.context = context;
15+
this.pathPrefix = pathPrefix;
16+
}
17+
18+
public Mono<HistoryConvoAIRes> handle(String agentId) {
19+
String path = String.format("%s/agents/%s/history", pathPrefix, agentId);
20+
return this.context.sendRequest(path, HttpMethod.GET, null, HistoryConvoAIRes.class);
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package io.agora.rest.services.convoai.api;
2+
3+
import io.agora.rest.core.Context;
4+
import io.agora.rest.services.convoai.res.InterruptConvoAIRes;
5+
import io.netty.handler.codec.http.HttpMethod;
6+
import reactor.core.publisher.Mono;
7+
8+
public class InterruptConvoAIAPI {
9+
private final Context context;
10+
11+
private final String pathPrefix;
12+
13+
public InterruptConvoAIAPI(Context context, String pathPrefix) {
14+
this.context = context;
15+
this.pathPrefix = pathPrefix;
16+
}
17+
18+
public Mono<InterruptConvoAIRes> handle(String agentId) {
19+
String path = String.format("%s/agents/%s/interrupt", pathPrefix, agentId);
20+
return this.context.sendRequest(path, HttpMethod.POST, null, InterruptConvoAIRes.class);
21+
}
22+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package io.agora.rest.services.convoai.api;
2+
3+
import io.agora.rest.core.Context;
4+
import io.agora.rest.services.convoai.req.SpeakConvoAIReq;
5+
import io.agora.rest.services.convoai.res.SpeakConvoAIRes;
6+
import io.netty.handler.codec.http.HttpMethod;
7+
import reactor.core.publisher.Mono;
8+
9+
public class SpeakConvoAIAPI {
10+
private final Context context;
11+
12+
private final String pathPrefix;
13+
14+
public SpeakConvoAIAPI(Context context, String pathPrefix) {
15+
this.context = context;
16+
this.pathPrefix = pathPrefix;
17+
}
18+
19+
public Mono<SpeakConvoAIRes> handle(String agentId, SpeakConvoAIReq request) {
20+
String path = String.format("%s/agents/%s/speak", pathPrefix, agentId);
21+
return this.context.sendRequest(path, HttpMethod.POST, request, SpeakConvoAIRes.class);
22+
}
23+
24+
}

0 commit comments

Comments
 (0)