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