|
3 | 3 | import com.sap.ai.sdk.orchestration.client.model.LLMModuleConfig; |
4 | 4 | import java.util.Map; |
5 | 5 | import javax.annotation.Nonnull; |
| 6 | +import javax.annotation.Nullable; |
6 | 7 | import lombok.Getter; |
7 | 8 |
|
8 | 9 | /** Large language models available in Orchestration. */ |
9 | 10 | // https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/models-and-scenarios-in-generative-ai-hub |
| 11 | +@Getter |
10 | 12 | public class OrchestrationAiModel { |
11 | | - @Getter private final LLMModuleConfig config; |
| 13 | + private final LLMModuleConfig config; |
12 | 14 |
|
13 | 15 | /** IBM Granite 13B chat completions model */ |
14 | 16 | public static final OrchestrationAiModel IBM_GRANITE_13B_CHAT = |
@@ -116,15 +118,64 @@ public class OrchestrationAiModel { |
116 | 118 | new OrchestrationAiModel("gemini-1.5-flash"); |
117 | 119 |
|
118 | 120 | OrchestrationAiModel(@Nonnull final String modelName) { |
119 | | - config = LLMModuleConfig.create().modelName(modelName).modelParams(Map.of()); |
| 121 | + config = new LLMModuleConfig().modelName(modelName).modelParams(Map.of()); |
120 | 122 | } |
121 | 123 |
|
122 | | - private OrchestrationAiModel( |
123 | | - @Nonnull final String modelName, Map<String, ? extends Number> modelParams) { |
124 | | - config = LLMModuleConfig.create().modelName(modelName).modelParams(modelParams); |
| 124 | + // private OrchestrationAiModel( |
| 125 | + // @Nonnull final String modelName, @Nonnull final Map<String, ? extends Number> modelParams) |
| 126 | + // { |
| 127 | + // config = new LLMModuleConfig().modelName(modelName).modelParams(modelParams); |
| 128 | + // } |
| 129 | + |
| 130 | + private OrchestrationAiModel(@Nonnull final String modelName, @Nonnull final Object modelParams) { |
| 131 | + config = new LLMModuleConfig().modelName(modelName).modelParams(modelParams); |
| 132 | + } |
| 133 | + |
| 134 | + /** |
| 135 | + * Set model version on this model. |
| 136 | + * |
| 137 | + * <pre>{@code |
| 138 | + * .modelVersion("latest) |
| 139 | + * }</pre> |
| 140 | + * |
| 141 | + * @param version The new version. |
| 142 | + * @return New instance of this class with new version. |
| 143 | + */ |
| 144 | + @Nonnull |
| 145 | + public OrchestrationAiModel modelVersion(@Nullable final String version) { |
| 146 | + // Question: I need a map but only got an object as modelParams. How are modelParams |
| 147 | + // structured? |
| 148 | + final var model = new OrchestrationAiModel(config.getModelName(), config.getModelParams()); |
| 149 | + model.config.setModelVersion(version); |
| 150 | + // Question: Is modelVersion not lost as soon as we call modelParams? |
| 151 | + // Do we need to propagate this in that function as well? |
| 152 | + return model; |
125 | 153 | } |
126 | 154 |
|
127 | | - public OrchestrationAiModel modelParams(Map<String, ? extends Number> modelParams) { |
128 | | - return new OrchestrationAiModel(config.getModelName(), modelParams); |
| 155 | + /** |
| 156 | + * Set model parameters on this model. |
| 157 | + * |
| 158 | + * <pre>{@code |
| 159 | + * .modelParams( |
| 160 | + * Map.of( |
| 161 | + * "max_tokens", 50, |
| 162 | + * "temperature", 0.1, |
| 163 | + * "frequency_penalty", 0, |
| 164 | + * "presence_penalty", 0)); |
| 165 | + * }</pre> |
| 166 | + * |
| 167 | + * @param modelParams Map of parameters. |
| 168 | + * @return New instance of this class. |
| 169 | + */ |
| 170 | + @Nonnull |
| 171 | + public OrchestrationAiModel modelParams(@Nonnull final Object modelParams) { |
| 172 | + return new OrchestrationAiModel(config.getModelName(), modelParams) |
| 173 | + .modelVersion(config.getModelVersion()); |
129 | 174 | } |
| 175 | + |
| 176 | + // @Nonnull |
| 177 | + // public OrchestrationAiModel modelParams( |
| 178 | + // @Nonnull final Map<String, ? extends Number> modelParams) { |
| 179 | + // return new OrchestrationAiModel(config.getModelName(), modelParams); |
| 180 | + // } |
130 | 181 | } |
0 commit comments