|
11 | 11 |
|
12 | 12 | package com.sap.ai.sdk.orchestration.model; |
13 | 13 |
|
14 | | -import com.fasterxml.jackson.annotation.JsonAnyGetter; |
15 | | -import com.fasterxml.jackson.annotation.JsonAnySetter; |
16 | | -import com.fasterxml.jackson.annotation.JsonIgnore; |
17 | | -import com.fasterxml.jackson.annotation.JsonProperty; |
18 | | -import java.util.ArrayList; |
19 | | -import java.util.HashMap; |
20 | | -import java.util.LinkedHashMap; |
21 | | -import java.util.List; |
22 | | -import java.util.Map; |
23 | | -import java.util.NoSuchElementException; |
24 | | -import java.util.Objects; |
25 | | -import java.util.Set; |
26 | | -import javax.annotation.Nonnull; |
27 | | -import javax.annotation.Nullable; |
| 14 | +import com.fasterxml.jackson.annotation.JsonSubTypes; |
| 15 | +import com.fasterxml.jackson.annotation.JsonTypeInfo; |
28 | 16 |
|
29 | 17 | /** CompletionPostRequest */ |
30 | | -// CHECKSTYLE:OFF |
31 | | -public class CompletionPostRequest |
32 | | -// CHECKSTYLE:ON |
33 | | -{ |
34 | | - @JsonProperty("config") |
35 | | - private OrchestrationConfig config; |
36 | | - |
37 | | - @JsonProperty("placeholder_values") |
38 | | - private Map<String, String> placeholderValues = new HashMap<>(); |
39 | | - |
40 | | - @JsonProperty("messages_history") |
41 | | - private List<ChatMessage> messagesHistory; |
42 | | - |
43 | | - @JsonAnySetter @JsonAnyGetter |
44 | | - private final Map<String, Object> cloudSdkCustomFields = new LinkedHashMap<>(); |
45 | | - |
46 | | - /** Default constructor for CompletionPostRequest. */ |
47 | | - protected CompletionPostRequest() {} |
48 | | - |
49 | | - /** |
50 | | - * Set the config of this {@link CompletionPostRequest} instance and return the same instance. |
51 | | - * |
52 | | - * @param config The config of this {@link CompletionPostRequest} |
53 | | - * @return The same instance of this {@link CompletionPostRequest} class |
54 | | - */ |
55 | | - @Nonnull |
56 | | - public CompletionPostRequest config(@Nonnull final OrchestrationConfig config) { |
57 | | - this.config = config; |
58 | | - return this; |
59 | | - } |
60 | | - |
61 | | - /** |
62 | | - * Get config |
63 | | - * |
64 | | - * @return config The config of this {@link CompletionPostRequest} instance. |
65 | | - */ |
66 | | - @Nonnull |
67 | | - public OrchestrationConfig getConfig() { |
68 | | - return config; |
69 | | - } |
70 | | - |
71 | | - /** |
72 | | - * Set the config of this {@link CompletionPostRequest} instance. |
73 | | - * |
74 | | - * @param config The config of this {@link CompletionPostRequest} |
75 | | - */ |
76 | | - public void setConfig(@Nonnull final OrchestrationConfig config) { |
77 | | - this.config = config; |
78 | | - } |
79 | | - |
80 | | - /** |
81 | | - * Set the placeholderValues of this {@link CompletionPostRequest} instance and return the same |
82 | | - * instance. |
83 | | - * |
84 | | - * @param placeholderValues The placeholderValues of this {@link CompletionPostRequest} |
85 | | - * @return The same instance of this {@link CompletionPostRequest} class |
86 | | - */ |
87 | | - @Nonnull |
88 | | - public CompletionPostRequest placeholderValues( |
89 | | - @Nullable final Map<String, String> placeholderValues) { |
90 | | - this.placeholderValues = placeholderValues; |
91 | | - return this; |
92 | | - } |
93 | | - |
94 | | - /** |
95 | | - * Put one placeholderValues instance to this {@link CompletionPostRequest} instance. |
96 | | - * |
97 | | - * @param key The String key of this placeholderValues instance |
98 | | - * @param placeholderValuesItem The placeholderValues that should be added under the given key |
99 | | - * @return The same instance of type {@link CompletionPostRequest} |
100 | | - */ |
101 | | - @Nonnull |
102 | | - public CompletionPostRequest putplaceholderValuesItem( |
103 | | - @Nonnull final String key, @Nonnull final String placeholderValuesItem) { |
104 | | - if (this.placeholderValues == null) { |
105 | | - this.placeholderValues = new HashMap<>(); |
106 | | - } |
107 | | - this.placeholderValues.put(key, placeholderValuesItem); |
108 | | - return this; |
109 | | - } |
110 | | - |
111 | | - /** |
112 | | - * Get placeholderValues |
113 | | - * |
114 | | - * @return placeholderValues The placeholderValues of this {@link CompletionPostRequest} instance. |
115 | | - */ |
116 | | - @Nonnull |
117 | | - public Map<String, String> getPlaceholderValues() { |
118 | | - return placeholderValues; |
119 | | - } |
120 | | - |
121 | | - /** |
122 | | - * Set the placeholderValues of this {@link CompletionPostRequest} instance. |
123 | | - * |
124 | | - * @param placeholderValues The placeholderValues of this {@link CompletionPostRequest} |
125 | | - */ |
126 | | - public void setPlaceholderValues(@Nullable final Map<String, String> placeholderValues) { |
127 | | - this.placeholderValues = placeholderValues; |
128 | | - } |
129 | | - |
130 | | - /** |
131 | | - * Set the messagesHistory of this {@link CompletionPostRequest} instance and return the same |
132 | | - * instance. |
133 | | - * |
134 | | - * @param messagesHistory History of chat messages. Can be used to provide system and assistant |
135 | | - * messages to set the context of the conversation. Will be merged with the template message |
136 | | - * @return The same instance of this {@link CompletionPostRequest} class |
137 | | - */ |
138 | | - @Nonnull |
139 | | - public CompletionPostRequest messagesHistory(@Nullable final List<ChatMessage> messagesHistory) { |
140 | | - this.messagesHistory = messagesHistory; |
141 | | - return this; |
142 | | - } |
143 | | - |
144 | | - /** |
145 | | - * Add one messagesHistory instance to this {@link CompletionPostRequest}. |
146 | | - * |
147 | | - * @param messagesHistoryItem The messagesHistory that should be added |
148 | | - * @return The same instance of type {@link CompletionPostRequest} |
149 | | - */ |
150 | | - @Nonnull |
151 | | - public CompletionPostRequest addMessagesHistoryItem( |
152 | | - @Nonnull final ChatMessage messagesHistoryItem) { |
153 | | - if (this.messagesHistory == null) { |
154 | | - this.messagesHistory = new ArrayList<>(); |
155 | | - } |
156 | | - this.messagesHistory.add(messagesHistoryItem); |
157 | | - return this; |
158 | | - } |
159 | | - |
160 | | - /** |
161 | | - * History of chat messages. Can be used to provide system and assistant messages to set the |
162 | | - * context of the conversation. Will be merged with the template message |
163 | | - * |
164 | | - * @return messagesHistory The messagesHistory of this {@link CompletionPostRequest} instance. |
165 | | - */ |
166 | | - @Nonnull |
167 | | - public List<ChatMessage> getMessagesHistory() { |
168 | | - return messagesHistory; |
169 | | - } |
170 | | - |
171 | | - /** |
172 | | - * Set the messagesHistory of this {@link CompletionPostRequest} instance. |
173 | | - * |
174 | | - * @param messagesHistory History of chat messages. Can be used to provide system and assistant |
175 | | - * messages to set the context of the conversation. Will be merged with the template message |
176 | | - */ |
177 | | - public void setMessagesHistory(@Nullable final List<ChatMessage> messagesHistory) { |
178 | | - this.messagesHistory = messagesHistory; |
179 | | - } |
180 | | - |
181 | | - /** |
182 | | - * Get the names of the unrecognizable properties of the {@link CompletionPostRequest}. |
183 | | - * |
184 | | - * @return The set of properties names |
185 | | - */ |
186 | | - @JsonIgnore |
187 | | - @Nonnull |
188 | | - public Set<String> getCustomFieldNames() { |
189 | | - return cloudSdkCustomFields.keySet(); |
190 | | - } |
191 | | - |
192 | | - /** |
193 | | - * Get the value of an unrecognizable property of this {@link CompletionPostRequest} instance. |
194 | | - * |
195 | | - * @deprecated Use {@link #toMap()} instead. |
196 | | - * @param name The name of the property |
197 | | - * @return The value of the property |
198 | | - * @throws NoSuchElementException If no property with the given name could be found. |
199 | | - */ |
200 | | - @Nullable |
201 | | - @Deprecated |
202 | | - public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { |
203 | | - if (!cloudSdkCustomFields.containsKey(name)) { |
204 | | - throw new NoSuchElementException( |
205 | | - "CompletionPostRequest has no field with name '" + name + "'."); |
206 | | - } |
207 | | - return cloudSdkCustomFields.get(name); |
208 | | - } |
209 | | - |
210 | | - /** |
211 | | - * Get the value of all properties of this {@link CompletionPostRequest} instance including |
212 | | - * unrecognized properties. |
213 | | - * |
214 | | - * @return The map of all properties |
215 | | - */ |
216 | | - @JsonIgnore |
217 | | - @Nonnull |
218 | | - public Map<String, Object> toMap() { |
219 | | - final Map<String, Object> declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); |
220 | | - if (config != null) declaredFields.put("config", config); |
221 | | - if (placeholderValues != null) declaredFields.put("placeholderValues", placeholderValues); |
222 | | - if (messagesHistory != null) declaredFields.put("messagesHistory", messagesHistory); |
223 | | - return declaredFields; |
224 | | - } |
225 | | - |
226 | | - /** |
227 | | - * Set an unrecognizable property of this {@link CompletionPostRequest} instance. If the map |
228 | | - * previously contained a mapping for the key, the old value is replaced by the specified value. |
229 | | - * |
230 | | - * @param customFieldName The name of the property |
231 | | - * @param customFieldValue The value of the property |
232 | | - */ |
233 | | - @JsonIgnore |
234 | | - public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { |
235 | | - cloudSdkCustomFields.put(customFieldName, customFieldValue); |
236 | | - } |
237 | | - |
238 | | - @Override |
239 | | - public boolean equals(@Nullable final java.lang.Object o) { |
240 | | - if (this == o) { |
241 | | - return true; |
242 | | - } |
243 | | - if (o == null || getClass() != o.getClass()) { |
244 | | - return false; |
245 | | - } |
246 | | - final CompletionPostRequest completionPostRequest = (CompletionPostRequest) o; |
247 | | - return Objects.equals(this.cloudSdkCustomFields, completionPostRequest.cloudSdkCustomFields) |
248 | | - && Objects.equals(this.config, completionPostRequest.config) |
249 | | - && Objects.equals(this.placeholderValues, completionPostRequest.placeholderValues) |
250 | | - && Objects.equals(this.messagesHistory, completionPostRequest.messagesHistory); |
251 | | - } |
252 | | - |
253 | | - @Override |
254 | | - public int hashCode() { |
255 | | - return Objects.hash(config, placeholderValues, messagesHistory, cloudSdkCustomFields); |
256 | | - } |
257 | | - |
258 | | - @Override |
259 | | - @Nonnull |
260 | | - public String toString() { |
261 | | - final StringBuilder sb = new StringBuilder(); |
262 | | - sb.append("class CompletionPostRequest {\n"); |
263 | | - sb.append(" config: ").append(toIndentedString(config)).append("\n"); |
264 | | - sb.append(" placeholderValues: ").append(toIndentedString(placeholderValues)).append("\n"); |
265 | | - sb.append(" messagesHistory: ").append(toIndentedString(messagesHistory)).append("\n"); |
266 | | - cloudSdkCustomFields.forEach( |
267 | | - (k, v) -> |
268 | | - sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); |
269 | | - sb.append("}"); |
270 | | - return sb.toString(); |
271 | | - } |
272 | | - |
273 | | - /** |
274 | | - * Convert the given object to string with each line indented by 4 spaces (except the first line). |
275 | | - */ |
276 | | - private String toIndentedString(final java.lang.Object o) { |
277 | | - if (o == null) { |
278 | | - return "null"; |
279 | | - } |
280 | | - return o.toString().replace("\n", "\n "); |
281 | | - } |
282 | | - |
283 | | - /** |
284 | | - * Create a type-safe, fluent-api builder object to construct a new {@link CompletionPostRequest} |
285 | | - * instance with all required arguments. |
286 | | - */ |
287 | | - public static Builder create() { |
288 | | - return (config) -> new CompletionPostRequest().config(config); |
289 | | - } |
290 | | - |
291 | | - /** Builder helper class. */ |
292 | | - public interface Builder { |
293 | | - /** |
294 | | - * Set the config of this {@link CompletionPostRequest} instance. |
295 | | - * |
296 | | - * @param config The config of this {@link CompletionPostRequest} |
297 | | - * @return The CompletionPostRequest instance. |
298 | | - */ |
299 | | - CompletionPostRequest config(@Nonnull final OrchestrationConfig config); |
300 | | - } |
301 | | -} |
| 18 | +@JsonTypeInfo(use = JsonTypeInfo.Id.DEDUCTION) |
| 19 | +@JsonSubTypes({ |
| 20 | + @JsonSubTypes.Type(value = CompletionRequestConfiguration.class), |
| 21 | + @JsonSubTypes.Type(value = CompletionRequestConfigurationReferenceById.class), |
| 22 | + @JsonSubTypes.Type(value = CompletionRequestConfigurationReferenceByNameScenarioVersion.class), |
| 23 | +}) |
| 24 | +public interface CompletionPostRequest {} |
0 commit comments