@@ -18,20 +18,45 @@ public final class BoxAI {
1818 * Text gen AI url.
1919 */
2020 public static final URLTemplate SEND_AI_TEXT_GEN_REQUEST_URL = new URLTemplate ("ai/text_gen" );
21+ /**
22+ * AI agent default config url.
23+ */
24+ public static final URLTemplate AI_AGENT_DEFAULT_CONFIG_URL = new URLTemplate ("ai_agent_default" );
2125
2226 private BoxAI () {
2327 }
2428
2529 /**
2630 * Sends an AI request to supported LLMs and returns an answer specifically focused
2731 * on the user's question given the provided items.
28- * @param api the API connection to be used by the created user.
32+ *
33+ * @param api the API connection to be used by the created user.
2934 * @param prompt The prompt provided by the client to be answered by the LLM.
30- * @param items The items to be processed by the LLM, currently only files are supported.
31- * @param mode The mode specifies if this request is for a single or multiple items.
35+ * @param items The items to be processed by the LLM, currently only files are supported.
36+ * @param mode The mode specifies if this request is for a single or multiple items.
3237 * @return The response from the AI.
3338 */
3439 public static BoxAIResponse sendAIRequest (BoxAPIConnection api , String prompt , List <BoxAIItem > items , Mode mode ) {
40+ return sendAIRequest (api , prompt , items , mode , null , null , null );
41+ }
42+
43+ /**
44+ * Sends an AI request to supported LLMs and returns an answer specifically focused
45+ * on the user's question given the provided items.
46+ *
47+ * @param api the API connection to be used by the created user.
48+ * @param prompt The prompt provided by the client to be answered by the LLM.
49+ * @param items The items to be processed by the LLM, currently only files are supported.
50+ * @param mode The mode specifies if this request is for a single or multiple items.
51+ * @param dialogueHistory The history of prompts and answers previously passed to the LLM.
52+ * This provides additional context to the LLM in generating the response.
53+ * @param agent The AI agent configuration to be used for the request.
54+ * @param includeCitations Whether to include citations in the response.
55+ * @return The response from the AI.
56+ */
57+ public static BoxAIResponse sendAIRequest (BoxAPIConnection api , String prompt , List <BoxAIItem > items , Mode mode ,
58+ List <BoxAIDialogueEntry > dialogueHistory , BoxAIAgentAsk agent ,
59+ Boolean includeCitations ) {
3560 URL url = SEND_AI_REQUEST_URL .build (api .getBaseURL ());
3661 JsonObject requestJSON = new JsonObject ();
3762 requestJSON .add ("mode" , mode .toString ());
@@ -43,6 +68,20 @@ public static BoxAIResponse sendAIRequest(BoxAPIConnection api, String prompt, L
4368 }
4469 requestJSON .add ("items" , itemsJSON );
4570
71+ if (dialogueHistory != null ) {
72+ JsonArray dialogueHistoryJSON = new JsonArray ();
73+ for (BoxAIDialogueEntry dialogueEntry : dialogueHistory ) {
74+ dialogueHistoryJSON .add (dialogueEntry .getJSONObject ());
75+ }
76+ requestJSON .add ("dialogue_history" , dialogueHistoryJSON );
77+ }
78+ if (agent != null ) {
79+ requestJSON .add ("ai_agent" , agent .getJSONObject ());
80+ }
81+ if (includeCitations != null ) {
82+ requestJSON .add ("include_citations" , includeCitations );
83+ }
84+
4685 BoxJSONRequest req = new BoxJSONRequest (api , url , HttpMethod .POST );
4786 req .setBody (requestJSON .toString ());
4887
@@ -54,9 +93,10 @@ public static BoxAIResponse sendAIRequest(BoxAPIConnection api, String prompt, L
5493
5594 /**
5695 * Sends an AI request to supported LLMs and returns an answer specifically focused on the creation of new text.
57- * @param api the API connection to be used by the created user.
96+ *
97+ * @param api the API connection to be used by the created user.
5898 * @param prompt The prompt provided by the client to be answered by the LLM.
59- * @param items The items to be processed by the LLM, currently only files are supported.
99+ * @param items The items to be processed by the LLM, currently only files are supported.
60100 * @return The response from the AI.
61101 */
62102 public static BoxAIResponse sendAITextGenRequest (BoxAPIConnection api , String prompt , List <BoxAIItem > items ) {
@@ -65,16 +105,33 @@ public static BoxAIResponse sendAITextGenRequest(BoxAPIConnection api, String pr
65105
66106 /**
67107 * Sends an AI request to supported LLMs and returns an answer specifically focused on the creation of new text.
68- * @param api the API connection to be used by the created user.
69- * @param prompt The prompt provided by the client to be answered by the LLM.
70- * @param items The items to be processed by the LLM, currently only files are supported.
108+ *
109+ * @param api the API connection to be used by the created user.
110+ * @param prompt The prompt provided by the client to be answered by the LLM.
111+ * @param items The items to be processed by the LLM, currently only files are supported.
71112 * @param dialogueHistory The history of prompts and answers previously passed to the LLM.
72113 * This provides additional context to the LLM in generating the response.
73114 * @return The response from the AI.
74115 */
75- public static BoxAIResponse sendAITextGenRequest (
76- BoxAPIConnection api , String prompt , List <BoxAIItem > items , List <BoxAIDialogueEntry > dialogueHistory
77- ) {
116+ public static BoxAIResponse sendAITextGenRequest (BoxAPIConnection api , String prompt , List <BoxAIItem > items ,
117+ List <BoxAIDialogueEntry > dialogueHistory ) {
118+ return sendAITextGenRequest (api , prompt , items , dialogueHistory , null );
119+ }
120+
121+ /**
122+ * Sends an AI request to supported LLMs and returns an answer specifically focused on the creation of new text.
123+ *
124+ * @param api the API connection to be used by the created user.
125+ * @param prompt The prompt provided by the client to be answered by the LLM.
126+ * @param items The items to be processed by the LLM, currently only files are supported.
127+ * @param dialogueHistory The history of prompts and answers previously passed to the LLM.
128+ * This provides additional context to the LLM in generating the response.
129+ * @param agent The AI agent configuration to be used for the request.
130+ * @return The response from the AI.
131+ */
132+ public static BoxAIResponse sendAITextGenRequest (BoxAPIConnection api , String prompt , List <BoxAIItem > items ,
133+ List <BoxAIDialogueEntry > dialogueHistory ,
134+ BoxAIAgentTextGen agent ) {
78135 URL url = SEND_AI_TEXT_GEN_REQUEST_URL .build (api .getBaseURL ());
79136 JsonObject requestJSON = new JsonObject ();
80137 requestJSON .add ("prompt" , prompt );
@@ -93,6 +150,10 @@ public static BoxAIResponse sendAITextGenRequest(
93150 requestJSON .add ("dialogue_history" , dialogueHistoryJSON );
94151 }
95152
153+ if (agent != null ) {
154+ requestJSON .add ("ai_agent" , agent .getJSONObject ());
155+ }
156+
96157 BoxJSONRequest req = new BoxJSONRequest (api , url , HttpMethod .POST );
97158 req .setBody (requestJSON .toString ());
98159
@@ -102,6 +163,46 @@ public static BoxAIResponse sendAITextGenRequest(
102163 }
103164 }
104165
166+ /**
167+ * Get the default AI Agent use for the given mode.
168+ *
169+ * @param api The API connection to be used by the created user.
170+ * @param mode The mode to filter the agent config to return.
171+ * @return A successful response including the default agent configuration.
172+ */
173+ public static BoxAIAgent getAiAgentDefaultConfig (BoxAPIConnection api , BoxAIAgent .Mode mode ) {
174+ return getAiAgentDefaultConfig (api , mode , null , null );
175+ }
176+
177+ /**
178+ * Get the default AI Agent use for the given mode.
179+ *
180+ * @param api The API connection to be used by the created user.
181+ * @param mode The mode to filter the agent config to return.
182+ * @param language The language to filter the agent config to return.
183+ * @param model The model to filter the agent config to return.
184+ * @return A successful response including the default agent configuration.
185+ */
186+ public static BoxAIAgent getAiAgentDefaultConfig (BoxAPIConnection api ,
187+ BoxAIAgent .Mode mode ,
188+ String language ,
189+ String model ) {
190+ QueryStringBuilder builder = new QueryStringBuilder ();
191+ builder .appendParam ("mode" , mode .toString ());
192+ if (language != null ) {
193+ builder .appendParam ("language" , language );
194+ }
195+ if (model != null ) {
196+ builder .appendParam ("model" , model );
197+ }
198+ URL url = AI_AGENT_DEFAULT_CONFIG_URL .buildWithQuery (api .getBaseURL (), builder .toString ());
199+ BoxAPIRequest req = new BoxAPIRequest (api , url , HttpMethod .GET );
200+ try (BoxJSONResponse response = (BoxJSONResponse ) req .send ()) {
201+ JsonObject responseJSON = Json .parse (response .getJSON ()).asObject ();
202+ return BoxAIAgent .parse (responseJSON );
203+ }
204+ }
205+
105206 public enum Mode {
106207 /**
107208 * Multiple items
0 commit comments