001package com.box.sdk;
002
003import com.box.sdk.internal.utils.JsonUtils;
004import com.eclipsesource.json.JsonObject;
005
006/** Represents the AI LLM endpoint params OpenAI object. */
007public class BoxAIAgentLLMEndpointParamsOpenAI extends BoxAIAgentLLMEndpointParams {
008
009  /** The type of the LLM endpoint parameters. */
010  public static final String TYPE = "openai_params";
011
012  /**
013   * Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing
014   * frequency in the text so far, decreasing the model's likelihood to repeat the same line
015   * verbatim.
016   */
017  private Double frequencyPenalty;
018  /**
019   * Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear
020   * in the text so far, increasing the model's likelihood to talk about new topics.
021   */
022  private Double presencePenalty;
023  /** Up to 4 sequences where the API will stop generating further tokens. */
024  private String stop;
025  /**
026   * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output
027   * more random, while lower values like 0.2 will make it more focused and deterministic. We
028   * generally recommend altering this or top_p but not both.
029   */
030  private Double temperature;
031  /**
032   * An alternative to sampling with temperature, called nucleus sampling, where the model considers
033   * the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising
034   * the top 10% probability mass are considered. We generally recommend altering this or
035   * temperature but not both.
036   */
037  private Double topP;
038
039  /**
040   * Constructs an AI agent with default settings.
041   *
042   * @param frequencyPenalty Number between -2.0 and 2.0. Positive values penalize new tokens based
043   *     on their existing frequency in the text so far, decreasing the model's likelihood to repeat
044   *     the same line verbatim.
045   * @param presencePenalty Number between -2.0 and 2.0. Positive values penalize new tokens based
046   *     on whether they appear in the text so far, increasing the model's likelihood to talk about
047   *     new topics.
048   * @param stop Up to 4 sequences where the API will stop generating further tokens.
049   * @param temperature What sampling temperature to use, between 0 and 2. Higher values like 0.8
050   *     will make the output more random, while lower values like 0.2 will make it more focused and
051   *     deterministic. We generally recommend altering this or top_p but not both.
052   * @param topP An alternative to sampling with temperature, called nucleus sampling, where the
053   *     model considers the results of the tokens with top_p probability mass. So 0.1 means only
054   *     the tokens comprising the top 10% probability mass are considered. We generally recommend
055   *     altering this or temperature but not both.
056   */
057  public BoxAIAgentLLMEndpointParamsOpenAI(
058      Double frequencyPenalty,
059      Double presencePenalty,
060      String stop,
061      Double temperature,
062      Double topP) {
063    super(TYPE);
064    this.frequencyPenalty = frequencyPenalty;
065    this.presencePenalty = presencePenalty;
066    this.stop = stop;
067    this.temperature = temperature;
068    this.topP = topP;
069  }
070
071  /**
072   * Constructs an AI agent with default settings.
073   *
074   * @param jsonObject JSON object representing the AI agent.
075   */
076  public BoxAIAgentLLMEndpointParamsOpenAI(JsonObject jsonObject) {
077    super(jsonObject);
078  }
079
080  /**
081   * Gets the frequency penalty.
082   *
083   * @return The frequency penalty.
084   */
085  public Double getFrequencyPenalty() {
086    return frequencyPenalty;
087  }
088
089  /**
090   * Sets the frequency penalty.
091   *
092   * @param frequencyPenalty The frequency penalty.
093   */
094  public void setFrequencyPenalty(Double frequencyPenalty) {
095    this.frequencyPenalty = frequencyPenalty;
096  }
097
098  /**
099   * Gets the presence penalty.
100   *
101   * @return The presence penalty.
102   */
103  public Double getPresencePenalty() {
104    return presencePenalty;
105  }
106
107  /**
108   * Sets the presence penalty.
109   *
110   * @param presencePenalty The presence penalty.
111   */
112  public void setPresencePenalty(Double presencePenalty) {
113    this.presencePenalty = presencePenalty;
114  }
115
116  /**
117   * Gets the stop.
118   *
119   * @return The stop.
120   */
121  public String getStop() {
122    return stop;
123  }
124
125  /**
126   * Sets the stop.
127   *
128   * @param stop The stop.
129   */
130  public void setStop(String stop) {
131    this.stop = stop;
132  }
133
134  /**
135   * Gets the temperature.
136   *
137   * @return The temperature.
138   */
139  public Double getTemperature() {
140    return temperature;
141  }
142
143  /**
144   * Sets the temperature.
145   *
146   * @param temperature The temperature.
147   */
148  public void setTemperature(Double temperature) {
149    this.temperature = temperature;
150  }
151
152  /**
153   * Gets the top-P.
154   *
155   * @return The top-P.
156   */
157  public Double getTopP() {
158    return topP;
159  }
160
161  /**
162   * Sets the top-P.
163   *
164   * @param topP The top-P.
165   */
166  public void setTopP(Double topP) {
167    this.topP = topP;
168  }
169
170  @Override
171  void parseJSONMember(JsonObject.Member member) {
172    super.parseJSONMember(member);
173    String memberName = member.getName();
174    switch (memberName) {
175      case "frequency_penalty":
176        this.frequencyPenalty = member.getValue().asDouble();
177        break;
178      case "presence_penalty":
179        this.presencePenalty = member.getValue().asDouble();
180        break;
181      case "stop":
182        this.stop = member.getValue().asString();
183        break;
184      case "temperature":
185        this.temperature = member.getValue().asDouble();
186        break;
187      case "top_p":
188        this.topP = member.getValue().asDouble();
189        break;
190      default:
191        break;
192    }
193  }
194
195  public JsonObject getJSONObject() {
196    JsonObject jsonObject = new JsonObject();
197    JsonUtils.addIfNotNull(jsonObject, "type", this.getType());
198    JsonUtils.addIfNotNull(jsonObject, "frequency_penalty", this.frequencyPenalty);
199    JsonUtils.addIfNotNull(jsonObject, "presence_penalty", this.presencePenalty);
200    JsonUtils.addIfNotNull(jsonObject, "stop", this.stop);
201    JsonUtils.addIfNotNull(jsonObject, "temperature", this.temperature);
202    JsonUtils.addIfNotNull(jsonObject, "top_p", this.topP);
203    return jsonObject;
204  }
205}