-
Notifications
You must be signed in to change notification settings - Fork 16
chore: Translation Module Convenience #646
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
base: main
Are you sure you want to change the base?
Changes from all commits
c018480
817a5e9
ca75f86
092c1fc
082ec9a
861df11
ef484ea
63dd65f
519cd75
1d13880
108730a
4b97583
ae4f5e3
7c2a641
35e5035
e937917
5a9740a
e5974e6
64e01b7
c85c2ff
a97bfec
7e64b07
964271f
130f454
0e5a395
60b101b
b9baee5
7f40361
876ea56
18e68ee
d26b07b
4cadce0
0908881
321fd62
6affa80
0424e27
3d0d337
af3bba9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| package com.sap.ai.sdk.orchestration; | ||
|
|
||
| import com.sap.ai.sdk.orchestration.model.SAPDocumentTranslationInput; | ||
| import com.sap.ai.sdk.orchestration.model.SAPDocumentTranslationInputConfig; | ||
| import com.sap.ai.sdk.orchestration.model.SAPDocumentTranslationOutput; | ||
| import com.sap.ai.sdk.orchestration.model.SAPDocumentTranslationOutputConfig; | ||
| import com.sap.ai.sdk.orchestration.model.SAPDocumentTranslationOutputTargetLanguage; | ||
| import javax.annotation.Nonnull; | ||
| import lombok.AccessLevel; | ||
| import lombok.Getter; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.Value; | ||
|
|
||
| /** | ||
| * Configuration helper for SAP Document Translation. | ||
| * | ||
| * @link <a | ||
| * href="https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/sap-document-translation">SAP | ||
| * AI Core: Orchestration - SAP Document Translation</a> | ||
| */ | ||
| @Value | ||
| @Getter(AccessLevel.PACKAGE) | ||
| @RequiredArgsConstructor(access = AccessLevel.PRIVATE) | ||
| public class TranslationConfig { | ||
| @Nonnull SAPDocumentTranslationInput.TypeEnum translationType; | ||
|
|
||
| /** | ||
| * Create a builder for the SAP_DOCUMENT_TRANSLATION translation provider | ||
| * | ||
| * @return The Builder instance. | ||
| */ | ||
| @Nonnull | ||
| public static Builder inputTranslation() { | ||
| return new TranslationConfig.Builder( | ||
| SAPDocumentTranslationInput.TypeEnum.SAP_DOCUMENT_TRANSLATION); | ||
| } | ||
|
|
||
| /** | ||
| * Create a builder for the SAP_DOCUMENT_TRANSLATION translation provider | ||
| * | ||
| * @return The Builder2 instance. | ||
| */ | ||
| @Nonnull | ||
| public static Builder2 outputTranslation() { | ||
| return new TranslationConfig.Builder2( | ||
| SAPDocumentTranslationOutput.TypeEnum.SAP_DOCUMENT_TRANSLATION); | ||
| } | ||
|
|
||
| /** Builder helper class. */ | ||
| @RequiredArgsConstructor(access = AccessLevel.PRIVATE) | ||
| public static class Builder { | ||
|
|
||
| private final SAPDocumentTranslationInput.TypeEnum translationType; | ||
|
|
||
| /** | ||
| * Get the input translation config with default values. | ||
| * | ||
| * @return The SAPDocumentTranslationInput instance. | ||
| */ | ||
| @Nonnull | ||
| public SAPDocumentTranslationInput getInputTranslationConfig() { | ||
| return SAPDocumentTranslationInput.create() | ||
| .type(translationType) | ||
| .config(SAPDocumentTranslationInputConfig.create().targetLanguage("en-US").applyTo(null)); | ||
| } | ||
| } | ||
|
|
||
| /** Sample builder class */ | ||
| @RequiredArgsConstructor(access = AccessLevel.PRIVATE) | ||
| public static class Builder2 { | ||
| private final SAPDocumentTranslationOutput.TypeEnum translationType; | ||
|
|
||
| /** | ||
| * Get the output translation config with default values. | ||
| * | ||
| * @return The SAPDocumentTranslationOutput instance. | ||
| */ | ||
| @Nonnull | ||
| public SAPDocumentTranslationOutput getOutputTranslationConfig() { | ||
| return SAPDocumentTranslationOutput.create() | ||
| .type(translationType) | ||
| .config( | ||
| SAPDocumentTranslationOutputConfig.create() | ||
| .targetLanguage(SAPDocumentTranslationOutputTargetLanguage.create("de-DE")) | ||
| .sourceLanguage("en-US")); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Major) These arguments need to be configurable fully for the convenience layer. |
||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,17 +23,13 @@ | |
| import com.sap.ai.sdk.orchestration.OrchestrationPrompt; | ||
| import com.sap.ai.sdk.orchestration.ResponseJsonSchema; | ||
| import com.sap.ai.sdk.orchestration.TemplateConfig; | ||
| import com.sap.ai.sdk.orchestration.TranslationConfig; | ||
| import com.sap.ai.sdk.orchestration.model.DPIEntities; | ||
| import com.sap.ai.sdk.orchestration.model.DataRepositoryType; | ||
| import com.sap.ai.sdk.orchestration.model.DocumentGroundingFilter; | ||
| import com.sap.ai.sdk.orchestration.model.GroundingFilterSearchConfiguration; | ||
| import com.sap.ai.sdk.orchestration.model.LlamaGuard38b; | ||
| import com.sap.ai.sdk.orchestration.model.ResponseFormatText; | ||
| import com.sap.ai.sdk.orchestration.model.SAPDocumentTranslationInput; | ||
| import com.sap.ai.sdk.orchestration.model.SAPDocumentTranslationInputConfig; | ||
| import com.sap.ai.sdk.orchestration.model.SAPDocumentTranslationOutput; | ||
| import com.sap.ai.sdk.orchestration.model.SAPDocumentTranslationOutputConfig; | ||
| import com.sap.ai.sdk.orchestration.model.SAPDocumentTranslationOutputTargetLanguage; | ||
| import com.sap.ai.sdk.orchestration.model.SearchDocumentKeyValueListPair; | ||
| import com.sap.ai.sdk.orchestration.model.SearchSelectOptionEnum; | ||
| import com.sap.ai.sdk.orchestration.model.Template; | ||
|
|
@@ -621,20 +617,10 @@ public OrchestrationChatResponse translation() { | |
| val configWithTranslation = | ||
| config | ||
| .withInputTranslationConfig( | ||
| SAPDocumentTranslationInput.create() | ||
| .type(SAPDocumentTranslationInput.TypeEnum.SAP_DOCUMENT_TRANSLATION) | ||
| .config( | ||
| SAPDocumentTranslationInputConfig.create() | ||
| .targetLanguage("en-US") | ||
| .applyTo(null))) | ||
| TranslationConfig.inputTranslation().getInputTranslationConfig()) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Minor) I would expect an overload for
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please compare to the other |
||
| .withOutputTranslationConfig( | ||
| SAPDocumentTranslationOutput.create() | ||
| .type(SAPDocumentTranslationOutput.TypeEnum.SAP_DOCUMENT_TRANSLATION) | ||
| .config( | ||
| SAPDocumentTranslationOutputConfig.create() | ||
| .targetLanguage( | ||
| SAPDocumentTranslationOutputTargetLanguage.create("de-DE")) | ||
| .sourceLanguage("en-US"))); // optional source language | ||
| TranslationConfig.outputTranslation() | ||
| .getOutputTranslationConfig()); // optional source language | ||
|
|
||
| return client.chatCompletion(prompt, configWithTranslation); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.