Skip to content

Commit

Permalink
Alex's review
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlesDuboisSAP committed Jan 17, 2025
1 parent 5ffb8ec commit 5f6a163
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
import lombok.NoArgsConstructor;
import lombok.val;

/** Internal factory to create all data objects from an orchestration configuration. */
/** Factory to create all data objects from an orchestration configuration. */
@NoArgsConstructor(access = AccessLevel.NONE)
public final class ConfigToRequestTransformer {
final class ConfigToRequestTransformer {
@Nonnull
static CompletionPostRequest toCompletionPostRequest(
@Nonnull final OrchestrationPrompt prompt, @Nonnull final OrchestrationModuleConfig config) {
Expand Down Expand Up @@ -59,9 +59,8 @@ static TemplatingModuleConfig toTemplateModuleConfig(
return Template.create().template(messagesWithPrompt);
}

/** Internal method to convert the convenience configuration to the data objec configuration. */
@Nonnull
public static ModuleConfigs toModuleConfigs(@Nonnull final OrchestrationModuleConfig config) {
static ModuleConfigs toModuleConfigs(@Nonnull final OrchestrationModuleConfig config) {
val llmConfig =
Option.of(config.getLlmConfig())
.getOrElseThrow(() -> new IllegalStateException("LLM config is required."));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
import lombok.NoArgsConstructor;
import lombok.val;

/** Internal utility class for getting a default object mapper with preset configuration. */
/**
* Internal utility class for getting a default object mapper with preset configuration.
*
* @since 1.2.0
*/
@Beta
@NoArgsConstructor(access = AccessLevel.NONE)
public class OrchestrationJacksonConfiguration {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
package com.sap.ai.sdk.orchestration.spring;

import static com.sap.ai.sdk.orchestration.ConfigToRequestTransformer.toModuleConfigs;
import static com.sap.ai.sdk.orchestration.OrchestrationAiModel.Parameter.FREQUENCY_PENALTY;
import static com.sap.ai.sdk.orchestration.OrchestrationAiModel.Parameter.MAX_TOKENS;
import static com.sap.ai.sdk.orchestration.OrchestrationAiModel.Parameter.PRESENCE_PENALTY;
import static com.sap.ai.sdk.orchestration.OrchestrationAiModel.Parameter.TEMPERATURE;
import static com.sap.ai.sdk.orchestration.OrchestrationAiModel.Parameter.TOP_P;
import static com.sap.ai.sdk.orchestration.OrchestrationJacksonConfiguration.getOrchestrationObjectMapper;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.annotations.Beta;
import com.sap.ai.sdk.orchestration.OrchestrationClientException;
import com.sap.ai.sdk.orchestration.OrchestrationModuleConfig;
import com.sap.ai.sdk.orchestration.model.LLMModuleConfig;
import com.sap.ai.sdk.orchestration.model.ModuleConfigs;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -153,22 +149,14 @@ public Double getTopP() {
@Nonnull
@Override
public <T extends ChatOptions> T copy() {
try {
val json = JACKSON.writeValueAsString(toModuleConfigs(config));
val copy = JACKSON.readValue(json, ModuleConfigs.class);
val copyConfig =
new OrchestrationModuleConfig()
.withTemplateConfig(copy.getTemplatingModuleConfig())
.withFilteringConfig(copy.getFilteringModuleConfig())
.withLlmConfig(copy.getLlmModuleConfig())
.withMaskingConfig(copy.getMaskingModuleConfig())
.withGroundingConfig(copy.getGroundingModuleConfig());
return (T) new OrchestrationChatOptions(copyConfig);

} catch (JsonProcessingException e) {
throw new OrchestrationClientException(
"Orchestration module configuration not readable: " + config, e);
}
val copyConfig =
new OrchestrationModuleConfig()
.withTemplateConfig(config.getTemplateConfig())
.withFilteringConfig(config.getFilteringConfig())
.withLlmConfig(config.getLlmConfig())
.withMaskingConfig(config.getMaskingConfig())
.withGroundingConfig(config.getGroundingConfig());
return (T) new OrchestrationChatOptions(copyConfig);
}

@SuppressWarnings("unchecked") // getModelParams() returns Object, it should return Map
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.sap.ai.sdk.orchestration.spring;

import com.google.common.annotations.Beta;
import com.sap.ai.sdk.orchestration.OrchestrationChatResponse;
import com.sap.ai.sdk.orchestration.model.LLMChoice;
import com.sap.ai.sdk.orchestration.model.LLMModuleResultSynchronous;
Expand All @@ -17,7 +18,12 @@
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.chat.model.Generation;

/** Response from the orchestration service in a Spring AI {@link ChatResponse}. */
/**
* Response from the orchestration service in a Spring AI {@link ChatResponse}.
*
* @since 1.2.0
*/
@Beta
@Value
@EqualsAndHashCode(callSuper = true)
public class OrchestrationSpringChatResponse extends ChatResponse {
Expand Down

0 comments on commit 5f6a163

Please sign in to comment.