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