001package com.box.sdk; 002 003import com.box.sdk.internal.utils.JsonUtils; 004import com.eclipsesource.json.JsonObject; 005 006/** Represents an AI agent tool used to handle longer text. */ 007public class BoxAIAgentAskLongText extends BoxJSONObject { 008 /** Embeddings used by the AI agent. */ 009 private BoxAIAgentEmbeddings embeddings; 010 /** The parameters for the LLM endpoint specific to OpenAI / Google models. */ 011 private BoxAIAgentLLMEndpointParams llmEndpointParams; 012 /** The model used for the AI Agent for basic text. */ 013 private String model; 014 /** The number of tokens for completion. */ 015 private int numTokensForCompletion; 016 /** 017 * The prompt template contains contextual information of the request and the user prompt. When 018 * passing prompt_template parameters, you must include inputs for {user_question} and {content}. 019 * Input for {current_date} is optional, depending on the use. 020 */ 021 private String promptTemplate; 022 /** System messages try to help the LLM "understand" its role and what it is supposed to do. */ 023 private String systemMessage; 024 025 /** 026 * Constructs an AI agent with default settings. 027 * 028 * @param embeddings Embeddings used by the AI agent. 029 * @param llmEndpointParams The parameters for the LLM endpoint specific to OpenAI / Google 030 * models. Value can be "google_params" or "openai_params". 031 * @param model The model used for the AI Agent for basic text. 032 * @param numTokensForCompletion The number of tokens for completion. 033 * @param promptTemplate The prompt template contains contextual information of the request and 034 * the user prompt. When passing prompt_template parameters, you must include inputs for 035 * {user_question} and {content}. Input for {current_date} is optional, depending on the use. 036 * @param systemMessage System messages try to help the LLM "understand" its role and what it is 037 * supposed to do. 038 */ 039 public BoxAIAgentAskLongText( 040 BoxAIAgentEmbeddings embeddings, 041 BoxAIAgentLLMEndpointParams llmEndpointParams, 042 String model, 043 int numTokensForCompletion, 044 String promptTemplate, 045 String systemMessage) { 046 this.embeddings = embeddings; 047 this.llmEndpointParams = llmEndpointParams; 048 this.model = model; 049 this.numTokensForCompletion = numTokensForCompletion; 050 this.promptTemplate = promptTemplate; 051 this.systemMessage = systemMessage; 052 } 053 054 /** 055 * Constructs an AI agent with default settings. 056 * 057 * @param jsonObject JSON object representing the AI agent. 058 */ 059 public BoxAIAgentAskLongText(JsonObject jsonObject) { 060 super(jsonObject); 061 } 062 063 /** 064 * Gets the embeddings used by the AI agent. 065 * 066 * @return The embeddings used by the AI agent. 067 */ 068 public BoxAIAgentEmbeddings getEmbeddings() { 069 return embeddings; 070 } 071 072 /** 073 * Sets the embeddings used by the AI agent. 074 * 075 * @param embeddings The embeddings used by the AI agent. 076 */ 077 public void setEmbeddings(BoxAIAgentEmbeddings embeddings) { 078 this.embeddings = embeddings; 079 } 080 081 /** 082 * Gets the parameters for the LLM endpoint specific to OpenAI / Google models. 083 * 084 * @return The parameters for the LLM endpoint specific to OpenAI / Google models. 085 */ 086 public BoxAIAgentLLMEndpointParams getLlmEndpointParams() { 087 return llmEndpointParams; 088 } 089 090 /** 091 * Sets the parameters for the LLM endpoint specific to OpenAI / Google models. 092 * 093 * @param llmEndpointParams The parameters for the LLM endpoint specific to OpenAI / Google 094 * models. 095 */ 096 public void setLlmEndpointParams(BoxAIAgentLLMEndpointParams llmEndpointParams) { 097 this.llmEndpointParams = llmEndpointParams; 098 } 099 100 /** 101 * Gets the model used for the AI Agent for basic text. 102 * 103 * @return The model used for the AI Agent for basic text. 104 */ 105 public String getModel() { 106 return model; 107 } 108 109 /** 110 * Sets the model used for the AI Agent for basic text. 111 * 112 * @param model The model used for the AI Agent for basic text. 113 */ 114 public void setModel(String model) { 115 this.model = model; 116 } 117 118 /** 119 * Gets the number of tokens for completion. 120 * 121 * @return The number of tokens for completion. 122 */ 123 public int getNumTokensForCompletion() { 124 return numTokensForCompletion; 125 } 126 127 /** 128 * Sets the number of tokens for completion. 129 * 130 * @param numTokensForCompletion The number of tokens for completion. 131 */ 132 public void setNumTokensForCompletion(int numTokensForCompletion) { 133 this.numTokensForCompletion = numTokensForCompletion; 134 } 135 136 /** 137 * Gets the prompt template contains contextual information of the request and the user prompt. 138 * When passing prompt_template parameters, you must include inputs for {user_question} and 139 * {content}. Input for {current_date} is optional, depending on the use. 140 * 141 * @return The prompt template contains contextual information of the request and the user prompt. 142 */ 143 public String getPromptTemplate() { 144 return promptTemplate; 145 } 146 147 /** 148 * Sets the prompt template contains contextual information of the request and the user prompt. 149 * When passing prompt_template parameters, you must include inputs for {user_question} and 150 * {content}. Input for {current_date} is optional, depending on the use. 151 * 152 * @param promptTemplate The prompt template contains contextual information of the request and 153 * the user prompt. 154 */ 155 public void setPromptTemplate(String promptTemplate) { 156 this.promptTemplate = promptTemplate; 157 } 158 159 /** 160 * Gets the system messages try to help the LLM "understand" its role and what it is supposed to 161 * do. 162 * 163 * @return The system messages try to help the LLM "understand" its role and what it is supposed 164 * to do. 165 */ 166 public String getSystemMessage() { 167 return systemMessage; 168 } 169 170 /** 171 * Sets the system messages try to help the LLM "understand" its role and what it is supposed to 172 * do. 173 * 174 * @param systemMessage The system messages try to help the LLM "understand" its role and what it 175 * is supposed to do. 176 */ 177 public void setSystemMessage(String systemMessage) { 178 this.systemMessage = systemMessage; 179 } 180 181 @Override 182 void parseJSONMember(JsonObject.Member member) { 183 super.parseJSONMember(member); 184 String memberName = member.getName(); 185 try { 186 switch (memberName) { 187 case "embeddings": 188 this.embeddings = new BoxAIAgentEmbeddings(member.getValue().asObject()); 189 break; 190 case "llm_endpoint_params": 191 this.llmEndpointParams = BoxAIAgentLLMEndpointParams.parse(member.getValue().asObject()); 192 break; 193 case "model": 194 this.model = member.getValue().asString(); 195 break; 196 case "num_tokens_for_completion": 197 this.numTokensForCompletion = member.getValue().asInt(); 198 break; 199 case "prompt_template": 200 this.promptTemplate = member.getValue().asString(); 201 break; 202 case "system_message": 203 this.systemMessage = member.getValue().asString(); 204 break; 205 default: 206 break; 207 } 208 } catch (Exception e) { 209 throw new BoxAPIException("Could not parse JSON response.", e); 210 } 211 } 212 213 public JsonObject getJSONObject() { 214 JsonObject jsonObject = new JsonObject(); 215 if (this.embeddings != null) { 216 jsonObject.add("embeddings", this.embeddings.getJSONObject()); 217 } 218 if (this.llmEndpointParams != null) { 219 jsonObject.add("llm_endpoint_params", this.llmEndpointParams.getJSONObject()); 220 } 221 JsonUtils.addIfNotNull(jsonObject, "model", this.model); 222 JsonUtils.addIfNotNull(jsonObject, "num_tokens_for_completion", this.numTokensForCompletion); 223 JsonUtils.addIfNotNull(jsonObject, "prompt_template", this.promptTemplate); 224 JsonUtils.addIfNotNull(jsonObject, "system_message", this.systemMessage); 225 return jsonObject; 226 } 227}