-
Notifications
You must be signed in to change notification settings - Fork 15
feat: [Orchestration] Spring AI integration #278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| private <T> T getLlmConfigParam(@Nonnull final String param) { | ||
| if (getLlmConfigNonNull().getModelParams() instanceof LinkedHashMap) { | ||
| return ((LinkedHashMap<String, T>) getLlmConfigNonNull().getModelParams()).get(param); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional: T could be Parameter<ValueT> (from the class OrchestrationAiModel)
But I didn't find a way to do this...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested that:
private <T> Option<T> getLlmConfigParam(@Nonnull final String param) {
return Option.of(getLlmConfigNonNull().getModelParams())
.filter(p -> p instanceof Map<?,?>)
.map(p -> (T) ((Map<?,?>) p).get(param))
.filter(Objects::nonNull);
}Unfortunately upon usage, the impliciit T is not recognized:
public Double getPresencePenalty() {
- return getLlmConfigParam(PRESENCE_PENALTY.getName());
+ return getLlmConfigParam(PRESENCE_PENALTY.getName()).getOrNull();
}However this would work, but it looks worse:
public Double getPresencePenalty() {
- return getLlmConfigParam(PRESENCE_PENALTY.getName());
+ return this.<Double>getLlmConfigParam(PRESENCE_PENALTY.getName()).getOrNull();
}
orchestration/src/main/java/com/sap/ai/sdk/orchestration/spring/OrchestrationChatModel.java
Show resolved
Hide resolved
orchestration/src/main/java/com/sap/ai/sdk/orchestration/spring/OrchestrationChatModel.java
Outdated
Show resolved
Hide resolved
orchestration/src/main/java/com/sap/ai/sdk/orchestration/spring/OrchestrationChatModel.java
Outdated
Show resolved
Hide resolved
| throw new IllegalArgumentException( | ||
| "Please add OrchestrationChatOptions to the Prompt: new Prompt(\"message\", new OrchestrationChatOptions(config))"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Question)
So we're planning to throw an exception, when the provided prompt argument does not contain an OrchestrationChatOptions object. This is implicit behavior. Users may not catch that limitation on design-time.
Would it be possible to make it explicit, e.g. by enforcing a constructor argument for OrchestrationChatOptionsOrchestrationModuleConfig on OrchestrationChatModel? Thus passing it on for every as fallback?call
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
callis part if the interface, cannot be modified.- If we add a constructor param then there are 2 different places to add a config. We have to merge them which is implicit behaviour.
This is not solveable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If not constructor - offering an optional setDefaultChatOptions(..) is probably not helping either, right? Because then you would need to thin about merging options ._.
orchestration/src/main/java/com/sap/ai/sdk/orchestration/spring/OrchestrationChatModel.java
Outdated
Show resolved
Hide resolved
orchestration/src/main/java/com/sap/ai/sdk/orchestration/spring/OrchestrationChatOptions.java
Outdated
Show resolved
Hide resolved
orchestration/src/main/java/com/sap/ai/sdk/orchestration/spring/OrchestrationChatOptions.java
Outdated
Show resolved
Hide resolved
orchestration/src/main/java/com/sap/ai/sdk/orchestration/spring/OrchestrationChatOptions.java
Outdated
Show resolved
Hide resolved
| ``` | ||
|
|
||
| ### Using a Custom Resource Group | ||
| ## Using a Custom Resource Group |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Comment)
Why the drive-by changes 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this ## adds underlines which makes it more readable because the file is super long, it also aligns with the other files.
underline
orchestration/src/main/java/com/sap/ai/sdk/orchestration/ConfigToRequestTransformer.java
Show resolved
Hide resolved
| public final class ConfigToRequestTransformer { | ||
| @Nonnull | ||
| static CompletionPostRequest toCompletionPostRequest( | ||
| @Nonnull final OrchestrationPrompt prompt, @Nonnull final OrchestrationModuleConfig config) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Major)
(I expect static code checks to flag warnings for) incomplete JavaDoc on public API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see that we only need this for copy. Did you check if we really need to support copy? If not, we could think about throwing a NotImplementedException
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OrchestrationModuleConfig is immutable. I will turn the deep copy into a normal copy since config cannot be modified anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the config inside of OrchestrationModuleConfig can be modified, e.g. LlmModuleConfig. Shallow copy is only okay if we are sure it won't be modified.
orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationJacksonConfiguration.java
Show resolved
Hide resolved
orchestration/src/main/java/com/sap/ai/sdk/orchestration/spring/OrchestrationChatModel.java
Show resolved
Hide resolved
orchestration/src/main/java/com/sap/ai/sdk/orchestration/spring/OrchestrationChatOptions.java
Show resolved
Hide resolved
...ation/src/main/java/com/sap/ai/sdk/orchestration/spring/OrchestrationSpringChatResponse.java
Show resolved
Hide resolved
newtork
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks lgtm to me
Context
AI/ai-sdk-java-backlog#8.
It's possible to use Spring AI and "under the hood" the AI SDK functionality is called
Feature scope:
OrchestrationChatModel, a clientOrchestrationChatOptions, that fits in the Spring AIPromptOrchestrationSpringChatResponseSpringAiOrchestrationControllerend-to-end testDefinition of Done
Aligned changes with the JavaScript SDK