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

box / box-java-sdk / #5922

17 Dec 2025 05:03PM UTC coverage: 35.498% (-0.4%) from 35.917%
#5922

push

github

web-flow
fix: add taxonomy to Metadata Field (read) definition (box/box-openapi#572) (#1644)

Co-authored-by: box-sdk-build <box-sdk-build@box.com>

2 of 2 new or added lines in 1 file covered. (100.0%)

535 existing lines in 31 files now uncovered.

18926 of 53316 relevant lines covered (35.5%)

0.35 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.
202
   *
203
   * <p>To define the extraction structure, provide either a metadata template or a list of fields.
204
   * To learn more about creating templates, see [Creating metadata templates in the Admin
205
   * Console](https://support.box.com/hc/en-us/articles/360044194033-Customizing-Metadata-Templates)
206
   * or use the [metadata template API](https://developer.box.com/guides/metadata/templates/create).
207
   *
208
   * <p>This endpoint also supports [Enhanced Extract
209
   * Agent](https://developer.box.com/guides/box-ai/ai-tutorials/extract-metadata-structured#enhanced-extract-agent).
210
   *
211
   * <p>For information about supported file formats and languages, see the [Extract metadata from
212
   * file
213
   * (structured)](https://developer.box.com/guides/box-ai/ai-tutorials/extract-metadata-structured)
214
   * API guide.
215
   *
216
   * @param requestBody Request body of createAiExtractStructured method
217
   */
218
  public AiExtractStructuredResponse createAiExtractStructured(AiExtractStructured requestBody) {
219
    return createAiExtractStructured(requestBody, new CreateAiExtractStructuredHeaders());
1✔
220
  }
221

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

265
  public Authentication getAuth() {
266
    return auth;
×
267
  }
268

269
  public NetworkSession getNetworkSession() {
UNCOV
270
    return networkSession;
×
271
  }
272

273
  public static class Builder {
274

275
    protected Authentication auth;
276

277
    protected NetworkSession networkSession;
278

279
    public Builder() {
1✔
280
      this.networkSession = new NetworkSession();
1✔
281
    }
1✔
282

283
    public Builder auth(Authentication auth) {
284
      this.auth = auth;
1✔
285
      return this;
1✔
286
    }
287

288
    public Builder networkSession(NetworkSession networkSession) {
289
      this.networkSession = networkSession;
1✔
290
      return this;
1✔
291
    }
292

293
    public AiManager build() {
294
      return new AiManager(this);
1✔
295
    }
296
  }
297
}
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

© 2025 Coveralls, Inc