File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed
sample-code/spring-app/src
main/java/com/sap/ai/sdk/app/services
test/java/com/sap/ai/sdk/app/controllers Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change 11package com .sap .ai .sdk .app .services ;
22
33import static com .sap .ai .sdk .orchestration .OrchestrationAiModel .GEMINI_1_5_FLASH ;
4+ import static com .sap .ai .sdk .orchestration .OrchestrationAiModel .GPT_4O ;
45import static com .sap .ai .sdk .orchestration .OrchestrationAiModel .GPT_4O_MINI ;
56import static com .sap .ai .sdk .orchestration .OrchestrationAiModel .Parameter .TEMPERATURE ;
67
4041public class OrchestrationService {
4142 private final OrchestrationClient client = new OrchestrationClient ();
4243
44+ /**
45+ * Demo operation to serve chatbot responses to payment questions.
46+ *
47+ * @param msg_user The user message.
48+ * @return A response from our chatbot.
49+ */
50+ public String queryPayments (String msg_user ) {
51+ var msg_system = "You are a helpful chat bot to answer questions on company payments." ;
52+
53+ var config = new OrchestrationModuleConfig ().withLlmConfig (GPT_4O .withParam (TEMPERATURE , 0.5 ));
54+ var prompt = new OrchestrationPrompt (Message .system (msg_system ), Message .user (msg_user ));
55+ var result = client .chatCompletion (prompt , config );
56+ return result .getContent ();
57+ }
58+
4359 @ Getter
4460 private final OrchestrationModuleConfig config =
4561 new OrchestrationModuleConfig ().withLlmConfig (GEMINI_1_5_FLASH .withParam (TEMPERATURE , 0.0 ));
Original file line number Diff line number Diff line change 2020import java .util .List ;
2121import java .util .Map ;
2222import java .util .concurrent .atomic .AtomicInteger ;
23+ import java .util .function .Function ;
2324import lombok .extern .slf4j .Slf4j ;
2425import org .junit .jupiter .api .BeforeEach ;
2526import org .junit .jupiter .api .Test ;
@@ -40,6 +41,9 @@ void testCompletion() {
4041
4142 assertThat (result ).isNotNull ();
4243 assertThat (result .getContent ()).isNotEmpty ();
44+
45+ Function <String , String > op = service ::queryPayments ;
46+ assertThat (op ).isNotNull ();
4347 }
4448
4549 @ Test
You can’t perform that action at this time.
0 commit comments