-
Notifications
You must be signed in to change notification settings - Fork 189
Expand file tree
/
Copy pathAiStudioManager.java
More file actions
302 lines (272 loc) · 11.2 KB
/
AiStudioManager.java
File metadata and controls
302 lines (272 loc) · 11.2 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
package com.box.sdkgen.managers.aistudio;
import static com.box.sdkgen.internal.utils.UtilsManager.convertToString;
import static com.box.sdkgen.internal.utils.UtilsManager.entryOf;
import static com.box.sdkgen.internal.utils.UtilsManager.mapOf;
import static com.box.sdkgen.internal.utils.UtilsManager.mergeMaps;
import static com.box.sdkgen.internal.utils.UtilsManager.prepareParams;
import com.box.sdkgen.networking.auth.Authentication;
import com.box.sdkgen.networking.fetchoptions.FetchOptions;
import com.box.sdkgen.networking.fetchoptions.ResponseFormat;
import com.box.sdkgen.networking.fetchresponse.FetchResponse;
import com.box.sdkgen.networking.network.NetworkSession;
import com.box.sdkgen.schemas.aimultipleagentresponse.AiMultipleAgentResponse;
import com.box.sdkgen.schemas.aisingleagentresponsefull.AiSingleAgentResponseFull;
import com.box.sdkgen.schemas.createaiagent.CreateAiAgent;
import com.box.sdkgen.serialization.json.JsonManager;
import java.util.Map;
public class AiStudioManager {
public Authentication auth;
public NetworkSession networkSession;
public AiStudioManager() {
this.networkSession = new NetworkSession();
}
protected AiStudioManager(Builder builder) {
this.auth = builder.auth;
this.networkSession = builder.networkSession;
}
/** Lists AI agents based on the provided parameters. */
public AiMultipleAgentResponse getAiAgents() {
return getAiAgents(new GetAiAgentsQueryParams(), new GetAiAgentsHeaders());
}
/**
* Lists AI agents based on the provided parameters.
*
* @param queryParams Query parameters of getAiAgents method
*/
public AiMultipleAgentResponse getAiAgents(GetAiAgentsQueryParams queryParams) {
return getAiAgents(queryParams, new GetAiAgentsHeaders());
}
/**
* Lists AI agents based on the provided parameters.
*
* @param headers Headers of getAiAgents method
*/
public AiMultipleAgentResponse getAiAgents(GetAiAgentsHeaders headers) {
return getAiAgents(new GetAiAgentsQueryParams(), headers);
}
/**
* Lists AI agents based on the provided parameters.
*
* @param queryParams Query parameters of getAiAgents method
* @param headers Headers of getAiAgents method
*/
public AiMultipleAgentResponse getAiAgents(
GetAiAgentsQueryParams queryParams, GetAiAgentsHeaders headers) {
Map<String, String> queryParamsMap =
prepareParams(
mapOf(
entryOf("mode", convertToString(queryParams.getMode())),
entryOf("fields", convertToString(queryParams.getFields())),
entryOf("agent_state", convertToString(queryParams.getAgentState())),
entryOf("include_box_default", convertToString(queryParams.getIncludeBoxDefault())),
entryOf("marker", convertToString(queryParams.getMarker())),
entryOf("limit", convertToString(queryParams.getLimit()))));
Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
FetchResponse response =
this.networkSession
.getNetworkClient()
.fetch(
new FetchOptions.Builder(
String.join(
"", this.networkSession.getBaseUrls().getBaseUrl(), "/2.0/ai_agents"),
"GET")
.params(queryParamsMap)
.headers(headersMap)
.responseFormat(ResponseFormat.JSON)
.auth(this.auth)
.networkSession(this.networkSession)
.build());
return JsonManager.deserialize(response.getData(), AiMultipleAgentResponse.class);
}
/**
* Creates an AI agent. At least one of the following capabilities must be provided: `ask`,
* `text_gen`, `extract`.
*
* @param requestBody Request body of createAiAgent method
*/
public AiSingleAgentResponseFull createAiAgent(CreateAiAgent requestBody) {
return createAiAgent(requestBody, new CreateAiAgentHeaders());
}
/**
* Creates an AI agent. At least one of the following capabilities must be provided: `ask`,
* `text_gen`, `extract`.
*
* @param requestBody Request body of createAiAgent method
* @param headers Headers of createAiAgent method
*/
public AiSingleAgentResponseFull createAiAgent(
CreateAiAgent requestBody, CreateAiAgentHeaders headers) {
Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
FetchResponse response =
this.networkSession
.getNetworkClient()
.fetch(
new FetchOptions.Builder(
String.join(
"", this.networkSession.getBaseUrls().getBaseUrl(), "/2.0/ai_agents"),
"POST")
.headers(headersMap)
.data(JsonManager.serialize(requestBody))
.contentType("application/json")
.responseFormat(ResponseFormat.JSON)
.auth(this.auth)
.networkSession(this.networkSession)
.build());
return JsonManager.deserialize(response.getData(), AiSingleAgentResponseFull.class);
}
/**
* Updates an AI agent.
*
* @param agentId The ID of the agent to update. Example: "1234"
* @param requestBody Request body of updateAiAgentById method
*/
public AiSingleAgentResponseFull updateAiAgentById(String agentId, CreateAiAgent requestBody) {
return updateAiAgentById(agentId, requestBody, new UpdateAiAgentByIdHeaders());
}
/**
* Updates an AI agent.
*
* @param agentId The ID of the agent to update. Example: "1234"
* @param requestBody Request body of updateAiAgentById method
* @param headers Headers of updateAiAgentById method
*/
public AiSingleAgentResponseFull updateAiAgentById(
String agentId, CreateAiAgent requestBody, UpdateAiAgentByIdHeaders headers) {
Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
FetchResponse response =
this.networkSession
.getNetworkClient()
.fetch(
new FetchOptions.Builder(
String.join(
"",
this.networkSession.getBaseUrls().getBaseUrl(),
"/2.0/ai_agents/",
convertToString(agentId)),
"PUT")
.headers(headersMap)
.data(JsonManager.serialize(requestBody))
.contentType("application/json")
.responseFormat(ResponseFormat.JSON)
.auth(this.auth)
.networkSession(this.networkSession)
.build());
return JsonManager.deserialize(response.getData(), AiSingleAgentResponseFull.class);
}
/**
* Gets an AI Agent using the `agent_id` parameter.
*
* @param agentId The agent id to get. Example: "1234"
*/
public AiSingleAgentResponseFull getAiAgentById(String agentId) {
return getAiAgentById(agentId, new GetAiAgentByIdQueryParams(), new GetAiAgentByIdHeaders());
}
/**
* Gets an AI Agent using the `agent_id` parameter.
*
* @param agentId The agent id to get. Example: "1234"
* @param queryParams Query parameters of getAiAgentById method
*/
public AiSingleAgentResponseFull getAiAgentById(
String agentId, GetAiAgentByIdQueryParams queryParams) {
return getAiAgentById(agentId, queryParams, new GetAiAgentByIdHeaders());
}
/**
* Gets an AI Agent using the `agent_id` parameter.
*
* @param agentId The agent id to get. Example: "1234"
* @param headers Headers of getAiAgentById method
*/
public AiSingleAgentResponseFull getAiAgentById(String agentId, GetAiAgentByIdHeaders headers) {
return getAiAgentById(agentId, new GetAiAgentByIdQueryParams(), headers);
}
/**
* Gets an AI Agent using the `agent_id` parameter.
*
* @param agentId The agent id to get. Example: "1234"
* @param queryParams Query parameters of getAiAgentById method
* @param headers Headers of getAiAgentById method
*/
public AiSingleAgentResponseFull getAiAgentById(
String agentId, GetAiAgentByIdQueryParams queryParams, GetAiAgentByIdHeaders headers) {
Map<String, String> queryParamsMap =
prepareParams(mapOf(entryOf("fields", convertToString(queryParams.getFields()))));
Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
FetchResponse response =
this.networkSession
.getNetworkClient()
.fetch(
new FetchOptions.Builder(
String.join(
"",
this.networkSession.getBaseUrls().getBaseUrl(),
"/2.0/ai_agents/",
convertToString(agentId)),
"GET")
.params(queryParamsMap)
.headers(headersMap)
.responseFormat(ResponseFormat.JSON)
.auth(this.auth)
.networkSession(this.networkSession)
.build());
return JsonManager.deserialize(response.getData(), AiSingleAgentResponseFull.class);
}
/**
* Deletes an AI agent using the provided parameters.
*
* @param agentId The ID of the agent to delete. Example: "1234"
*/
public void deleteAiAgentById(String agentId) {
deleteAiAgentById(agentId, new DeleteAiAgentByIdHeaders());
}
/**
* Deletes an AI agent using the provided parameters.
*
* @param agentId The ID of the agent to delete. Example: "1234"
* @param headers Headers of deleteAiAgentById method
*/
public void deleteAiAgentById(String agentId, DeleteAiAgentByIdHeaders headers) {
Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
FetchResponse response =
this.networkSession
.getNetworkClient()
.fetch(
new FetchOptions.Builder(
String.join(
"",
this.networkSession.getBaseUrls().getBaseUrl(),
"/2.0/ai_agents/",
convertToString(agentId)),
"DELETE")
.headers(headersMap)
.responseFormat(ResponseFormat.NO_CONTENT)
.auth(this.auth)
.networkSession(this.networkSession)
.build());
}
public Authentication getAuth() {
return auth;
}
public NetworkSession getNetworkSession() {
return networkSession;
}
public static class Builder {
protected Authentication auth;
protected NetworkSession networkSession;
public Builder() {}
public Builder auth(Authentication auth) {
this.auth = auth;
return this;
}
public Builder networkSession(NetworkSession networkSession) {
this.networkSession = networkSession;
return this;
}
public AiStudioManager build() {
if (this.networkSession == null) {
this.networkSession = new NetworkSession();
}
return new AiStudioManager(this);
}
}
}