• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

box / box-java-sdk / #5076

07 Oct 2025 12:35PM UTC coverage: 37.132% (+0.007%) from 37.125%
#5076

push

github

web-flow
test: Change `Event.additionalDetails` field assertion in events test (box/box-codegen#858) (#1491)

18454 of 49699 relevant lines covered (37.13%)

0.37 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.94
/src/main/java/com/box/sdkgen/managers/ai/AiManager.java
1
package com.box.sdkgen.managers.ai;
2

3
import static com.box.sdkgen.internal.utils.UtilsManager.convertToString;
4
import static com.box.sdkgen.internal.utils.UtilsManager.entryOf;
5
import static com.box.sdkgen.internal.utils.UtilsManager.mapOf;
6
import static com.box.sdkgen.internal.utils.UtilsManager.mergeMaps;
7
import static com.box.sdkgen.internal.utils.UtilsManager.prepareParams;
8

9
import com.box.sdkgen.networking.auth.Authentication;
10
import com.box.sdkgen.networking.fetchoptions.FetchOptions;
11
import com.box.sdkgen.networking.fetchoptions.ResponseFormat;
12
import com.box.sdkgen.networking.fetchresponse.FetchResponse;
13
import com.box.sdkgen.networking.network.NetworkSession;
14
import com.box.sdkgen.schemas.aiagent.AiAgent;
15
import com.box.sdkgen.schemas.aiask.AiAsk;
16
import com.box.sdkgen.schemas.aiextract.AiExtract;
17
import com.box.sdkgen.schemas.aiextractstructured.AiExtractStructured;
18
import com.box.sdkgen.schemas.aiextractstructuredresponse.AiExtractStructuredResponse;
19
import com.box.sdkgen.schemas.airesponse.AiResponse;
20
import com.box.sdkgen.schemas.airesponsefull.AiResponseFull;
21
import com.box.sdkgen.schemas.aitextgen.AiTextGen;
22
import com.box.sdkgen.serialization.json.JsonManager;
23
import java.util.Map;
24

25
public class AiManager {
26

27
  public Authentication auth;
28

29
  public NetworkSession networkSession;
30

31
  public AiManager() {
×
32
    this.networkSession = new NetworkSession();
×
33
  }
×
34

35
  protected AiManager(Builder builder) {
1✔
36
    this.auth = builder.auth;
1✔
37
    this.networkSession = builder.networkSession;
1✔
38
  }
1✔
39

40
  /**
41
   * Sends an AI request to supported LLMs and returns an answer specifically focused on the user's
42
   * question given the provided context.
43
   *
44
   * @param requestBody Request body of createAiAsk method
45
   */
46
  public AiResponseFull createAiAsk(AiAsk requestBody) {
47
    return createAiAsk(requestBody, new CreateAiAskHeaders());
1✔
48
  }
49

50
  /**
51
   * Sends an AI request to supported LLMs and returns an answer specifically focused on the user's
52
   * question given the provided context.
53
   *
54
   * @param requestBody Request body of createAiAsk method
55
   * @param headers Headers of createAiAsk method
56
   */
57
  public AiResponseFull createAiAsk(AiAsk requestBody, CreateAiAskHeaders headers) {
58
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
59
    FetchResponse response =
1✔
60
        this.networkSession
61
            .getNetworkClient()
1✔
62
            .fetch(
1✔
63
                new FetchOptions.Builder(
64
                        String.join(
1✔
65
                            "", this.networkSession.getBaseUrls().getBaseUrl(), "/2.0/ai/ask"),
1✔
66
                        "POST")
67
                    .headers(headersMap)
1✔
68
                    .data(JsonManager.serialize(requestBody))
1✔
69
                    .contentType("application/json")
1✔
70
                    .responseFormat(ResponseFormat.JSON)
1✔
71
                    .auth(this.auth)
1✔
72
                    .networkSession(this.networkSession)
1✔
73
                    .build());
1✔
74
    if (convertToString(response.getStatus()).equals("204")) {
1✔
75
      return null;
×
76
    }
77
    return JsonManager.deserialize(response.getData(), AiResponseFull.class);
1✔
78
  }
79

80
  /**
81
   * Sends an AI request to supported Large Language Models (LLMs) and returns generated text based
82
   * on the provided prompt.
83
   *
84
   * @param requestBody Request body of createAiTextGen method
85
   */
86
  public AiResponse createAiTextGen(AiTextGen requestBody) {
87
    return createAiTextGen(requestBody, new CreateAiTextGenHeaders());
1✔
88
  }
89

90
  /**
91
   * Sends an AI request to supported Large Language Models (LLMs) and returns generated text based
92
   * on the provided prompt.
93
   *
94
   * @param requestBody Request body of createAiTextGen method
95
   * @param headers Headers of createAiTextGen method
96
   */
97
  public AiResponse createAiTextGen(AiTextGen requestBody, CreateAiTextGenHeaders headers) {
98
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
99
    FetchResponse response =
1✔
100
        this.networkSession
101
            .getNetworkClient()
1✔
102
            .fetch(
1✔
103
                new FetchOptions.Builder(
104
                        String.join(
1✔
105
                            "", this.networkSession.getBaseUrls().getBaseUrl(), "/2.0/ai/text_gen"),
1✔
106
                        "POST")
107
                    .headers(headersMap)
1✔
108
                    .data(JsonManager.serialize(requestBody))
1✔
109
                    .contentType("application/json")
1✔
110
                    .responseFormat(ResponseFormat.JSON)
1✔
111
                    .auth(this.auth)
1✔
112
                    .networkSession(this.networkSession)
1✔
113
                    .build());
1✔
114
    return JsonManager.deserialize(response.getData(), AiResponse.class);
1✔
115
  }
116

117
  /**
118
   * Get the AI agent default config.
119
   *
120
   * @param queryParams Query parameters of getAiAgentDefaultConfig method
121
   */
122
  public AiAgent getAiAgentDefaultConfig(GetAiAgentDefaultConfigQueryParams queryParams) {
123
    return getAiAgentDefaultConfig(queryParams, new GetAiAgentDefaultConfigHeaders());
1✔
124
  }
125

126
  /**
127
   * Get the AI agent default config.
128
   *
129
   * @param queryParams Query parameters of getAiAgentDefaultConfig method
130
   * @param headers Headers of getAiAgentDefaultConfig method
131
   */
132
  public AiAgent getAiAgentDefaultConfig(
133
      GetAiAgentDefaultConfigQueryParams queryParams, GetAiAgentDefaultConfigHeaders headers) {
134
    Map<String, String> queryParamsMap =
1✔
135
        prepareParams(
1✔
136
            mapOf(
1✔
137
                entryOf("mode", convertToString(queryParams.getMode())),
1✔
138
                entryOf("language", convertToString(queryParams.getLanguage())),
1✔
139
                entryOf("model", convertToString(queryParams.getModel()))));
1✔
140
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
141
    FetchResponse response =
1✔
142
        this.networkSession
143
            .getNetworkClient()
1✔
144
            .fetch(
1✔
145
                new FetchOptions.Builder(
146
                        String.join(
1✔
147
                            "",
148
                            this.networkSession.getBaseUrls().getBaseUrl(),
1✔
149
                            "/2.0/ai_agent_default"),
150
                        "GET")
151
                    .params(queryParamsMap)
1✔
152
                    .headers(headersMap)
1✔
153
                    .responseFormat(ResponseFormat.JSON)
1✔
154
                    .auth(this.auth)
1✔
155
                    .networkSession(this.networkSession)
1✔
156
                    .build());
1✔
157
    return JsonManager.deserialize(response.getData(), AiAgent.class);
1✔
158
  }
159

160
  /**
161
   * Sends an AI request to supported Large Language Models (LLMs) and extracts metadata in form of
162
   * key-value pairs. In this request, both the prompt and the output can be freeform. Metadata
163
   * template setup before sending the request is not required.
164
   *
165
   * @param requestBody Request body of createAiExtract method
166
   */
167
  public AiResponse createAiExtract(AiExtract requestBody) {
168
    return createAiExtract(requestBody, new CreateAiExtractHeaders());
1✔
169
  }
170

171
  /**
172
   * Sends an AI request to supported Large Language Models (LLMs) and extracts metadata in form of
173
   * key-value pairs. In this request, both the prompt and the output can be freeform. Metadata
174
   * template setup before sending the request is not required.
175
   *
176
   * @param requestBody Request body of createAiExtract method
177
   * @param headers Headers of createAiExtract method
178
   */
179
  public AiResponse createAiExtract(AiExtract requestBody, CreateAiExtractHeaders headers) {
180
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
181
    FetchResponse response =
1✔
182
        this.networkSession
183
            .getNetworkClient()
1✔
184
            .fetch(
1✔
185
                new FetchOptions.Builder(
186
                        String.join(
1✔
187
                            "", this.networkSession.getBaseUrls().getBaseUrl(), "/2.0/ai/extract"),
1✔
188
                        "POST")
189
                    .headers(headersMap)
1✔
190
                    .data(JsonManager.serialize(requestBody))
1✔
191
                    .contentType("application/json")
1✔
192
                    .responseFormat(ResponseFormat.JSON)
1✔
193
                    .auth(this.auth)
1✔
194
                    .networkSession(this.networkSession)
1✔
195
                    .build());
1✔
196
    return JsonManager.deserialize(response.getData(), AiResponse.class);
1✔
197
  }
198

199
  /**
200
   * Sends an AI request to supported Large Language Models (LLMs) and returns extracted metadata as
201
   * a set of key-value pairs. For this request, you either need a metadata template or a list of
202
   * fields you want to extract. Input is **either** a metadata template or a list of fields to
203
   * ensure the structure. To learn more about creating templates, see [Creating metadata templates
204
   * in the Admin
205
   * Console](https://support.box.com/hc/en-us/articles/360044194033-Customizing-Metadata-Templates)
206
   * or use the [metadata template API](g://metadata/templates/create). This endpoint also supports
207
   * [Enhanced Extract
208
   * Agent](g://box-ai/ai-tutorials/extract-metadata-structured/#enhanced-extract-agent).
209
   *
210
   * @param requestBody Request body of createAiExtractStructured method
211
   */
212
  public AiExtractStructuredResponse createAiExtractStructured(AiExtractStructured requestBody) {
213
    return createAiExtractStructured(requestBody, new CreateAiExtractStructuredHeaders());
1✔
214
  }
215

216
  /**
217
   * Sends an AI request to supported Large Language Models (LLMs) and returns extracted metadata as
218
   * a set of key-value pairs. For this request, you either need a metadata template or a list of
219
   * fields you want to extract. Input is **either** a metadata template or a list of fields to
220
   * ensure the structure. To learn more about creating templates, see [Creating metadata templates
221
   * in the Admin
222
   * Console](https://support.box.com/hc/en-us/articles/360044194033-Customizing-Metadata-Templates)
223
   * or use the [metadata template API](g://metadata/templates/create). This endpoint also supports
224
   * [Enhanced Extract
225
   * Agent](g://box-ai/ai-tutorials/extract-metadata-structured/#enhanced-extract-agent).
226
   *
227
   * @param requestBody Request body of createAiExtractStructured method
228
   * @param headers Headers of createAiExtractStructured method
229
   */
230
  public AiExtractStructuredResponse createAiExtractStructured(
231
      AiExtractStructured requestBody, CreateAiExtractStructuredHeaders headers) {
232
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
233
    FetchResponse response =
1✔
234
        this.networkSession
235
            .getNetworkClient()
1✔
236
            .fetch(
1✔
237
                new FetchOptions.Builder(
238
                        String.join(
1✔
239
                            "",
240
                            this.networkSession.getBaseUrls().getBaseUrl(),
1✔
241
                            "/2.0/ai/extract_structured"),
242
                        "POST")
243
                    .headers(headersMap)
1✔
244
                    .data(JsonManager.serialize(requestBody))
1✔
245
                    .contentType("application/json")
1✔
246
                    .responseFormat(ResponseFormat.JSON)
1✔
247
                    .auth(this.auth)
1✔
248
                    .networkSession(this.networkSession)
1✔
249
                    .build());
1✔
250
    return JsonManager.deserialize(response.getData(), AiExtractStructuredResponse.class);
1✔
251
  }
252

253
  public Authentication getAuth() {
254
    return auth;
×
255
  }
256

257
  public NetworkSession getNetworkSession() {
258
    return networkSession;
×
259
  }
260

261
  public static class Builder {
262

263
    protected Authentication auth;
264

265
    protected NetworkSession networkSession;
266

267
    public Builder() {
1✔
268
      this.networkSession = new NetworkSession();
1✔
269
    }
1✔
270

271
    public Builder auth(Authentication auth) {
272
      this.auth = auth;
1✔
273
      return this;
1✔
274
    }
275

276
    public Builder networkSession(NetworkSession networkSession) {
277
      this.networkSession = networkSession;
1✔
278
      return this;
1✔
279
    }
280

281
    public AiManager build() {
282
      return new AiManager(this);
1✔
283
    }
284
  }
285
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc