generated from SAP/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into workflow/compatibility-version
- Loading branch information
Showing
16 changed files
with
224 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
orchestration/src/main/java/com/sap/ai/sdk/orchestration/JacksonMixins.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.sap.ai.sdk.orchestration; | ||
|
||
import com.fasterxml.jackson.annotation.JsonTypeInfo; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import com.sap.ai.sdk.orchestration.client.model.LLMChoice; | ||
import com.sap.ai.sdk.orchestration.client.model.LLMModuleResultSynchronous; | ||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
final class JacksonMixins { | ||
/** Mixin to enforce a specific subtype to be deserialized always. */ | ||
@JsonTypeInfo(use = JsonTypeInfo.Id.NONE) | ||
@JsonDeserialize(as = LLMModuleResultSynchronous.class) | ||
interface LLMModuleResultMixIn {} | ||
|
||
/** Mixin to enforce a specific subtype to be deserialized always. */ | ||
@JsonTypeInfo(use = JsonTypeInfo.Id.NONE) | ||
@JsonDeserialize(as = LLMChoice.class) | ||
interface ModuleResultsOutputUnmaskingInnerMixIn {} | ||
|
||
/** Mixin to suppress @JsonTypeInfo for oneOf interfaces. */ | ||
@JsonTypeInfo(use = JsonTypeInfo.Id.NONE) | ||
interface NoTypeInfoMixin {} | ||
} |
10 changes: 0 additions & 10 deletions
10
orchestration/src/main/java/com/sap/ai/sdk/orchestration/LLMModuleResultMixIn.java
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
orchestration/src/main/java/com/sap/ai/sdk/orchestration/NoTypeInfoMixin.java
This file was deleted.
Oops, something went wrong.
41 changes: 41 additions & 0 deletions
41
orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationChatResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.sap.ai.sdk.orchestration; | ||
|
||
import static lombok.AccessLevel.PACKAGE; | ||
|
||
import com.sap.ai.sdk.orchestration.client.model.CompletionPostResponse; | ||
import com.sap.ai.sdk.orchestration.client.model.LLMModuleResultSynchronous; | ||
import javax.annotation.Nonnull; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.Value; | ||
|
||
/** Orchestration chat completion output. */ | ||
@Value | ||
@RequiredArgsConstructor(access = PACKAGE) | ||
public class OrchestrationChatResponse { | ||
CompletionPostResponse originalResponse; | ||
|
||
/** | ||
* Get the message content from the output. | ||
* | ||
* <p>Note: If there are multiple choices only the first one is returned | ||
* | ||
* @return the message content or empty string. | ||
* @throws OrchestrationClientException if the content filter filtered the output. | ||
*/ | ||
@Nonnull | ||
public String getContent() throws OrchestrationClientException { | ||
final var choices = | ||
((LLMModuleResultSynchronous) originalResponse.getOrchestrationResult()).getChoices(); | ||
|
||
if (choices.isEmpty()) { | ||
return ""; | ||
} | ||
|
||
final var choice = choices.get(0); | ||
|
||
if ("content_filter".equals(choice.getFinishReason())) { | ||
throw new OrchestrationClientException("Content filter filtered the output."); | ||
} | ||
return choice.getMessage().getContent(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
orchestration/src/test/resources/__files/emptyChoicesResponse.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"request_id": "26ea36b5-c196-4806-a9a6-a686f0c6ad91", | ||
"module_results": { | ||
"templating": [ | ||
{ | ||
"role": "user", | ||
"content": "Reply with 'Orchestration Service is working!' in German" | ||
} | ||
], | ||
"llm": { | ||
"id": "chatcmpl-9lzPV4kLrXjFckOp2yY454wksWBoj", | ||
"object": "chat.completion", | ||
"created": 1721224505, | ||
"model": "gpt-35-turbo-16k", | ||
"choices": [], | ||
"usage": { | ||
"completion_tokens": 7, | ||
"prompt_tokens": 19, | ||
"total_tokens": 26 | ||
} | ||
} | ||
}, | ||
"orchestration_result": { | ||
"id": "chatcmpl-9lzPV4kLrXjFckOp2yY454wksWBoj", | ||
"object": "chat.completion", | ||
"created": 1721224505, | ||
"model": "gpt-35-turbo-16k", | ||
"choices": [], | ||
"usage": { | ||
"completion_tokens": 7, | ||
"prompt_tokens": 19, | ||
"total_tokens": 26 | ||
} | ||
} | ||
} |
Oops, something went wrong.