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

box / box-java-sdk / #5696

18 Nov 2025 06:12PM UTC coverage: 13.3% (+0.008%) from 13.292%
#5696

push

github

web-flow
fix(boxsdkgen): Fix parsing `OffsetDateTime` from String (box/box-codegen#887) (#1581)

0 of 10 new or added lines in 1 file covered. (0.0%)

34 existing lines in 12 files now uncovered.

8374 of 62961 relevant lines covered (13.3%)

0.13 hits per line

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

0.0
/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) {
×
36
    this.auth = builder.auth;
×
37
    this.networkSession = builder.networkSession;
×
38
  }
×
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());
×
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()));
×
59
    FetchResponse response =
×
60
        this.networkSession
61
            .getNetworkClient()
×
62
            .fetch(
×
63
                new FetchOptions.Builder(
64
                        String.join(
×
65
                            "", this.networkSession.getBaseUrls().getBaseUrl(), "/2.0/ai/ask"),
×
66
                        "POST")
67
                    .headers(headersMap)
×
68
                    .data(JsonManager.serialize(requestBody))
×
69
                    .contentType("application/json")
×
70
                    .responseFormat(ResponseFormat.JSON)
×
71
                    .auth(this.auth)
×
72
                    .networkSession(this.networkSession)
×
73
                    .build());
×
74
    if (convertToString(response.getStatus()).equals("204")) {
×
75
      return null;
×
76
    }
77
    return JsonManager.deserialize(response.getData(), AiResponseFull.class);
×
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());
×
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()));
×
99
    FetchResponse response =
×
100
        this.networkSession
101
            .getNetworkClient()
×
102
            .fetch(
×
103
                new FetchOptions.Builder(
104
                        String.join(
×
105
                            "", this.networkSession.getBaseUrls().getBaseUrl(), "/2.0/ai/text_gen"),
×
106
                        "POST")
107
                    .headers(headersMap)
×
108
                    .data(JsonManager.serialize(requestBody))
×
109
                    .contentType("application/json")
×
110
                    .responseFormat(ResponseFormat.JSON)
×
111
                    .auth(this.auth)
×
112
                    .networkSession(this.networkSession)
×
113
                    .build());
×
114
    return JsonManager.deserialize(response.getData(), AiResponse.class);
×
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());
×
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 =
×
135
        prepareParams(
×
136
            mapOf(
×
137
                entryOf("mode", convertToString(queryParams.getMode())),
×
138
                entryOf("language", convertToString(queryParams.getLanguage())),
×
139
                entryOf("model", convertToString(queryParams.getModel()))));
×
140
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
×
141
    FetchResponse response =
×
142
        this.networkSession
143
            .getNetworkClient()
×
144
            .fetch(
×
145
                new FetchOptions.Builder(
146
                        String.join(
×
147
                            "",
148
                            this.networkSession.getBaseUrls().getBaseUrl(),
×
149
                            "/2.0/ai_agent_default"),
150
                        "GET")
151
                    .params(queryParamsMap)
×
152
                    .headers(headersMap)
×
153
                    .responseFormat(ResponseFormat.JSON)
×
154
                    .auth(this.auth)
×
155
                    .networkSession(this.networkSession)
×
156
                    .build());
×
157
    return JsonManager.deserialize(response.getData(), AiAgent.class);
×
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());
×
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()));
×
181
    FetchResponse response =
×
182
        this.networkSession
183
            .getNetworkClient()
×
184
            .fetch(
×
185
                new FetchOptions.Builder(
186
                        String.join(
×
187
                            "", this.networkSession.getBaseUrls().getBaseUrl(), "/2.0/ai/extract"),
×
188
                        "POST")
189
                    .headers(headersMap)
×
190
                    .data(JsonManager.serialize(requestBody))
×
191
                    .contentType("application/json")
×
192
                    .responseFormat(ResponseFormat.JSON)
×
193
                    .auth(this.auth)
×
194
                    .networkSession(this.networkSession)
×
195
                    .build());
×
196
    return JsonManager.deserialize(response.getData(), AiResponse.class);
×
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](g://metadata/templates/create).
207
   *
208
   * <p>This endpoint also supports [Enhanced Extract
209
   * Agent](g://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 (structured)](g://box-ai/ai-tutorials/extract-metadata-structured) API guide.
213
   *
214
   * @param requestBody Request body of createAiExtractStructured method
215
   */
216
  public AiExtractStructuredResponse createAiExtractStructured(AiExtractStructured requestBody) {
UNCOV
217
    return createAiExtractStructured(requestBody, new CreateAiExtractStructuredHeaders());
×
218
  }
219

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

261
  public Authentication getAuth() {
UNCOV
262
    return auth;
×
263
  }
264

265
  public NetworkSession getNetworkSession() {
UNCOV
266
    return networkSession;
×
267
  }
268

269
  public static class Builder {
270

271
    protected Authentication auth;
272

273
    protected NetworkSession networkSession;
274

UNCOV
275
    public Builder() {
×
UNCOV
276
      this.networkSession = new NetworkSession();
×
277
    }
×
278

279
    public Builder auth(Authentication auth) {
UNCOV
280
      this.auth = auth;
×
UNCOV
281
      return this;
×
282
    }
283

284
    public Builder networkSession(NetworkSession networkSession) {
UNCOV
285
      this.networkSession = networkSession;
×
UNCOV
286
      return this;
×
287
    }
288

289
    public AiManager build() {
UNCOV
290
      return new AiManager(this);
×
291
    }
292
  }
293
}
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