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