diff --git a/examples/integrations/oci/genai-cdi/pom.xml b/examples/integrations/oci/genai-cdi/pom.xml new file mode 100644 index 00000000..d2f08ba2 --- /dev/null +++ b/examples/integrations/oci/genai-cdi/pom.xml @@ -0,0 +1,95 @@ + + + + 4.0.0 + + io.helidon.applications + helidon-mp + 4.1.2 + + + + io.helidon.examples.integrations.oci + helidon-examples-integrations-oci-genai-cdi + 1.0.0-SNAPSHOT + Helidon Examples Integration OCI GenAI CDI + CDI integration with OCI GenAI. + + + + io.helidon.microprofile.bundles + helidon-microprofile + + + io.helidon.logging + helidon-logging-jul + + + io.helidon.integrations.oci.sdk + helidon-integrations-oci-sdk-cdi + runtime + + + com.oracle.oci.sdk + oci-java-sdk-generativeaiinference + + + io.smallrye + jandex + runtime + + + + io.helidon.microprofile.testing + helidon-microprofile-testing-junit5 + test + + + org.junit.jupiter + junit-jupiter-api + test + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-libs + + + + + io.smallrye + jandex-maven-plugin + + + make-index + + + + + + diff --git a/examples/integrations/oci/genai-cdi/src/main/java/io/helidon/examples/integrations/oci/genai/cdi/GenAiResource.java b/examples/integrations/oci/genai-cdi/src/main/java/io/helidon/examples/integrations/oci/genai/cdi/GenAiResource.java new file mode 100644 index 00000000..b67d36c0 --- /dev/null +++ b/examples/integrations/oci/genai-cdi/src/main/java/io/helidon/examples/integrations/oci/genai/cdi/GenAiResource.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.helidon.examples.integrations.oci.genai.cdi; + +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + +import com.oracle.bmc.generativeaiinference.GenerativeAiInferenceClient; +import com.oracle.bmc.generativeaiinference.requests.ChatRequest; +import com.oracle.bmc.generativeaiinference.responses.ChatResponse; +import com.oracle.bmc.generativeaiinference.model.ChatContent; +import com.oracle.bmc.generativeaiinference.model.ChatDetails; +import com.oracle.bmc.generativeaiinference.model.ChatResult; +import com.oracle.bmc.generativeaiinference.model.GenericChatRequest; +import com.oracle.bmc.generativeaiinference.model.Message; +import com.oracle.bmc.generativeaiinference.model.OnDemandServingMode; +import com.oracle.bmc.generativeaiinference.model.TextContent; +import com.oracle.bmc.generativeaiinference.model.UserMessage; +import com.oracle.bmc.Region; + +import jakarta.inject.Inject; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.QueryParam; +import org.eclipse.microprofile.config.inject.ConfigProperty; + +/** + * JAX-RS resource - REST API for the Gen AI example. + */ +@Path("/genai") +public class GenAiResource { + private static final Logger LOGGER = Logger.getLogger(GenAiResource.class.getName()); + + private final GenerativeAiInferenceClient generativeAiInferenceClient; + + @Inject + @ConfigProperty(name="oci.genai.compartment.id") + private String COMPARTMENT_ID; + + @Inject + @ConfigProperty(name="oci.genai.model.id") + private String MODEL_ID; + + @Inject + GenAiResource(GenerativeAiInferenceClient generativeAiInferenceClient, + @ConfigProperty(name = "oci.genai.region") String region) { + this.generativeAiInferenceClient = generativeAiInferenceClient; + generativeAiInferenceClient.setRegion(Region.valueOf(region)); + } + + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("chat") + public String chatModelAsk(@QueryParam("userMessage") String userMessage) { + LOGGER.log(Level.INFO, "UserMessage is: " + userMessage); + ChatContent content = TextContent.builder() + .text(userMessage) + .build(); + List contents = new ArrayList<>(); + contents.add(content); + Message message = UserMessage.builder() + .content(contents) + .build(); + List messages = new ArrayList<>(); + messages.add(message); + GenericChatRequest chatRequest = GenericChatRequest.builder() + .messages(messages) + .isStream(false) + .build(); + ChatDetails details = ChatDetails.builder() + .servingMode(OnDemandServingMode.builder().modelId(MODEL_ID).build()) + .compartmentId(COMPARTMENT_ID) + .chatRequest(chatRequest) + .build(); + ChatRequest request = ChatRequest.builder() + .chatDetails(details) + .build(); + ChatResponse response = generativeAiInferenceClient.chat(request); + ChatResult chatResult = response.getChatResult(); + LOGGER.log(Level.INFO, "Chat Result is: " + chatResult.toString()); + return chatResult.toString(); + } +} + diff --git a/examples/integrations/oci/genai-cdi/src/main/java/io/helidon/examples/integrations/oci/genai/cdi/package-info.java b/examples/integrations/oci/genai-cdi/src/main/java/io/helidon/examples/integrations/oci/genai/cdi/package-info.java new file mode 100644 index 00000000..bb3eb5c3 --- /dev/null +++ b/examples/integrations/oci/genai-cdi/src/main/java/io/helidon/examples/integrations/oci/genai/cdi/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Example of integration with OCI GenAI in Helidon MP application. + */ +package io.helidon.examples.integrations.oci.genai.cdi; diff --git a/examples/integrations/oci/genai-cdi/src/main/resources/META-INF/beans.xml b/examples/integrations/oci/genai-cdi/src/main/resources/META-INF/beans.xml new file mode 100644 index 00000000..52f89a20 --- /dev/null +++ b/examples/integrations/oci/genai-cdi/src/main/resources/META-INF/beans.xml @@ -0,0 +1,25 @@ + + + + diff --git a/examples/integrations/oci/genai-cdi/src/main/resources/META-INF/microprofile-config.properties b/examples/integrations/oci/genai-cdi/src/main/resources/META-INF/microprofile-config.properties new file mode 100644 index 00000000..5575e183 --- /dev/null +++ b/examples/integrations/oci/genai-cdi/src/main/resources/META-INF/microprofile-config.properties @@ -0,0 +1,15 @@ +# Microprofile server properties +server.port=8080 +server.host=0.0.0.0 + +# OCI Auth related properties +# https://helidon.io/docs/latest/apidocs/io.helidon.integrations.oci.sdk.cdi/io/helidon/integrations/oci/sdk/cdi/OciExtension.html +# config,config-file,session-token-config-file,session-token-builder,instance-principals,resource-principal,oke-workload-identity +oci.auth-strategies=session-token-config-file +oci.config.profile=helidonocidev + +# OCI GenAI related properties +# https://docs.oracle.com/en-us/iaas/tools/java/3.53.1/com/oracle/bmc/Region.html +oci.genai.region=us-chicago-1 +oci.genai.compartment.id=ocid1.compartment.oc1..aaaaaaaaiwoctrgf6w6rtq7az62fabscwgzbax2iepwu2qlub5qzcvabn5wa +oci.genai.model.id=ocid1.generativeaimodel.oc1.us-chicago-1.amaaaaaask7dceyaiir6nnhmlgwvh37dr2mvragxzszqmz3hok52pcgmpqta diff --git a/examples/integrations/oci/genai-cdi/src/main/resources/logging.properties b/examples/integrations/oci/genai-cdi/src/main/resources/logging.properties new file mode 100644 index 00000000..ffad43db --- /dev/null +++ b/examples/integrations/oci/genai-cdi/src/main/resources/logging.properties @@ -0,0 +1,20 @@ + +# Example Logging Configuration File +# For more information see $JAVA_HOME/jre/lib/logging.properties + +# Send messages to the console +handlers=io.helidon.logging.jul.HelidonConsoleHandler + +# HelidonConsoleHandler uses a SimpleFormatter subclass that replaces "!thread!" with the current thread +java.util.logging.SimpleFormatter.format=%1$tY.%1$tm.%1$td %1$tH:%1$tM:%1$tS %4$s %3$s !thread!: %5$s%6$s%n + +# Global logging level. Can be overridden by specific loggers +.level=INFO + +# Quiet Weld +org.jboss.level=WARNING + +# Component specific log levels +#io.helidon.config.level=INFO +#io.helidon.security.level=INFO +#io.helidon.common.level=INFO diff --git a/examples/integrations/oci/genai-cdi/src/test/java/io/helidon/examples/integrations/oci/genai/cdi/GenAiResourceTest.java b/examples/integrations/oci/genai-cdi/src/test/java/io/helidon/examples/integrations/oci/genai/cdi/GenAiResourceTest.java new file mode 100644 index 00000000..7b56e95e --- /dev/null +++ b/examples/integrations/oci/genai-cdi/src/test/java/io/helidon/examples/integrations/oci/genai/cdi/GenAiResourceTest.java @@ -0,0 +1,33 @@ +package io.helidon.examples.integrations.oci.genai.cdi; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; + +import io.helidon.microprofile.testing.junit5.HelidonTest; +import jakarta.inject.Inject; +import jakarta.ws.rs.client.WebTarget; +import jakarta.ws.rs.core.MediaType; + +@HelidonTest +public class GenAiResourceTest { + + private static final String APP_URL = "/genai/"; + + @Inject + private WebTarget target; + + private static String appUrl(String path) { + return APP_URL + path; + } + + @Test + public void testChatModelAsk() { + String answer = target.path(appUrl("chat")) + .queryParam("userMessage", "Which are the most used Large Language Models?") + .request(MediaType.APPLICATION_JSON) + .get(String.class); + assertTrue(answer.contains("BERT"), "actual: " + answer); + } + +} diff --git a/examples/integrations/oci/genai/pom.xml b/examples/integrations/oci/genai/pom.xml new file mode 100644 index 00000000..fdae3e7f --- /dev/null +++ b/examples/integrations/oci/genai/pom.xml @@ -0,0 +1,93 @@ + + + + 4.0.0 + + io.helidon.applications + helidon-se + 4.1.2 + + + + io.helidon.examples.integrations.oci + helidon-examples-integrations-oci-genai + 1.0.0-SNAPSHOT + Helidon Examples Integration OCI GenAI + Integration with OCI GenAI. + + + io.helidon.examples.integrations.oci.atp.OciGenAiMain + + + + + io.helidon.webserver + helidon-webserver + + + io.helidon.config + helidon-config-yaml + + + io.helidon.logging + helidon-logging-jul + + + com.oracle.oci.sdk + oci-java-sdk-database + + + com.oracle.oci.sdk + oci-java-sdk-common-httpclient-jersey3 + runtime + + + com.oracle.oci.sdk + oci-java-sdk-generativeaiinference + + + + io.helidon.webserver.testing.junit5 + helidon-webserver-testing-junit5 + test + + + org.junit.jupiter + junit-jupiter-api + test + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-libs + + + + + + diff --git a/examples/integrations/oci/genai/src/main/java/io/helidon/examples/integrations/oci/genai/GenAiService.java b/examples/integrations/oci/genai/src/main/java/io/helidon/examples/integrations/oci/genai/GenAiService.java new file mode 100644 index 00000000..cd4d1287 --- /dev/null +++ b/examples/integrations/oci/genai/src/main/java/io/helidon/examples/integrations/oci/genai/GenAiService.java @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.helidon.examples.integrations.oci.genai; + +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + +import io.helidon.config.Config; +import io.helidon.http.Status; +import io.helidon.webserver.http.HttpRules; +import io.helidon.webserver.http.HttpService; +import io.helidon.webserver.http.ServerRequest; +import io.helidon.webserver.http.ServerResponse; + +import com.oracle.bmc.generativeaiinference.GenerativeAiInferenceClient; +import com.oracle.bmc.generativeaiinference.requests.ChatRequest; +import com.oracle.bmc.generativeaiinference.responses.ChatResponse; +import com.oracle.bmc.generativeaiinference.model.ChatContent; +import com.oracle.bmc.generativeaiinference.model.ChatDetails; +import com.oracle.bmc.generativeaiinference.model.ChatResult; +import com.oracle.bmc.generativeaiinference.model.GenericChatRequest; +import com.oracle.bmc.generativeaiinference.model.Message; +import com.oracle.bmc.generativeaiinference.model.OnDemandServingMode; +import com.oracle.bmc.generativeaiinference.model.TextContent; +import com.oracle.bmc.generativeaiinference.model.UserMessage; +import com.oracle.bmc.Region; + +/** + * JAX-RS resource - REST API for the Gen AI example. + */ +public class GenAiService implements HttpService { + private static final Logger LOGGER = Logger.getLogger(GenAiService.class.getName()); + + private final GenerativeAiInferenceClient generativeAiInferenceClient; + private final Config config; + private String COMPARTMENT_ID; + private String MODEL_ID; + private static final String USER_MESSAGE_PARAM = "userMessage" ; + + GenAiService(GenerativeAiInferenceClient generativeAiInferenceClient, + Config config) { + this.generativeAiInferenceClient = generativeAiInferenceClient; + this.config = config; + generativeAiInferenceClient.setRegion(Region.valueOf(config.get("oci.genai.region").asString().get())); + this.COMPARTMENT_ID = config.get("oci.genai.compartment_id").asString().get(); + this.MODEL_ID = config.get("oci.genai.model_id").asString().get(); + } + + @Override + public void routing(HttpRules rules) { + rules.get("/chat/{" + USER_MESSAGE_PARAM + "}", this::chatModelAsk); + } + + public void chatModelAsk(ServerRequest req, ServerResponse res) { + String userMessage = req.path().pathParameters().get("userMessage"); + LOGGER.log(Level.INFO, "UserMessage is: " + userMessage); + ChatContent content = TextContent.builder() + .text(userMessage) + .build(); + List contents = new ArrayList<>(); + contents.add(content); + Message message = UserMessage.builder() + .content(contents) + .build(); + List messages = new ArrayList<>(); + messages.add(message); + GenericChatRequest chatRequest = GenericChatRequest.builder() + .messages(messages) + .isStream(false) + .build(); + ChatDetails details = ChatDetails.builder() + .servingMode(OnDemandServingMode.builder().modelId(MODEL_ID).build()) + .compartmentId(COMPARTMENT_ID) + .chatRequest(chatRequest) + .build(); + ChatRequest request = ChatRequest.builder() + .chatDetails(details) + .build(); + ChatResponse response = generativeAiInferenceClient.chat(request); + ChatResult chatResult = response.getChatResult(); + LOGGER.log(Level.INFO, "Chat Result is: " + chatResult.toString()); + res.send(chatResult.toString()); + } +} + diff --git a/examples/integrations/oci/genai/src/main/java/io/helidon/examples/integrations/oci/genai/OciGenAiMain.java b/examples/integrations/oci/genai/src/main/java/io/helidon/examples/integrations/oci/genai/OciGenAiMain.java new file mode 100644 index 00000000..836ff94e --- /dev/null +++ b/examples/integrations/oci/genai/src/main/java/io/helidon/examples/integrations/oci/genai/OciGenAiMain.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.helidon.examples.integrations.oci.genai; + +import java.io.IOException; + +import io.helidon.config.Config; +import io.helidon.logging.common.LogConfig; +import io.helidon.webserver.WebServer; + +import com.oracle.bmc.ConfigFileReader; +import com.oracle.bmc.auth.AuthenticationDetailsProvider; +import com.oracle.bmc.auth.ConfigFileAuthenticationDetailsProvider; +import com.oracle.bmc.auth.SessionTokenAuthenticationDetailsProvider; +import com.oracle.bmc.generativeaiinference.GenerativeAiInferenceClient; +import com.oracle.bmc.generativeaiinference.requests.ChatRequest; +import com.oracle.bmc.generativeaiinference.responses.ChatResponse; +import com.oracle.bmc.generativeaiinference.model.ChatContent; +import com.oracle.bmc.generativeaiinference.model.ChatDetails; +import com.oracle.bmc.generativeaiinference.model.ChatResult; +import com.oracle.bmc.generativeaiinference.model.GenericChatRequest; +import com.oracle.bmc.generativeaiinference.model.Message; +import com.oracle.bmc.generativeaiinference.model.OnDemandServingMode; +import com.oracle.bmc.generativeaiinference.model.TextContent; +import com.oracle.bmc.generativeaiinference.model.UserMessage; +import com.oracle.bmc.Region; +import com.oracle.bmc.model.BmcException; + +/** + * Main class of the example. + * This example sets up a web server to serve REST API that integrates with OCI GenAI Service. + */ +public final class OciGenAiMain { + /** + * Cannot be instantiated. + */ + private OciGenAiMain() { + } + + /** + * Application main entry point. + * + * @param args command line arguments. + */ + public static void main(String[] args) throws IOException { + // load logging configuration + LogConfig.configureRuntime(); + + // By default, this will pick up application.yaml from the classpath + Config config = Config.create(); + + // this requires OCI configuration in the usual place + // ~/.oci/config + //ConfigFileReader.ConfigFile configFile = ConfigFileReader.parseDefault(); + //AuthenticationDetailsProvider authProvider = new ConfigFileAuthenticationDetailsProvider(configFile); + AuthenticationDetailsProvider authProvider = + new SessionTokenAuthenticationDetailsProvider(ConfigFileReader.DEFAULT_FILE_PATH,"helidonocidev"); + GenerativeAiInferenceClient generativeAiInferenceClient = GenerativeAiInferenceClient.builder().build(authProvider); + + // Prepare routing for the server + WebServer server = WebServer.builder() + .config(config.get("server")) + .routing(routing -> routing + .register("/genai", new GenAiService(generativeAiInferenceClient, config)) + // OCI SDK error handling + .error(BmcException.class, (req, res, ex) -> + res.status(ex.getStatusCode()) + .send(ex.getMessage()))) + .build() + .start(); + + System.out.println("WEB server is up! http://localhost:" + server.port() + "/"); + } +} diff --git a/examples/integrations/oci/genai/src/main/java/io/helidon/examples/integrations/oci/genai/package-info.java b/examples/integrations/oci/genai/src/main/java/io/helidon/examples/integrations/oci/genai/package-info.java new file mode 100644 index 00000000..6089a238 --- /dev/null +++ b/examples/integrations/oci/genai/src/main/java/io/helidon/examples/integrations/oci/genai/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Example of integration with OCI GenAI in Helidon SE application. + */ +package io.helidon.examples.integrations.oci.genai; diff --git a/examples/integrations/oci/genai/src/main/resources/application.yaml b/examples/integrations/oci/genai/src/main/resources/application.yaml new file mode 100644 index 00000000..d1168107 --- /dev/null +++ b/examples/integrations/oci/genai/src/main/resources/application.yaml @@ -0,0 +1,27 @@ +# +# Copyright (c) 2024 Oracle and/or its affiliates. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +server: + port: 8080 + host: 0.0.0.0 + +# OCI GenAI related properties +oci: + # https://docs.oracle.com/en-us/iaas/tools/java/3.53.1/com/oracle/bmc/Region.html + genai: + region: us-chicago-1 + compartment.id: ocid1.compartment.oc1..aaaaaaaaiwoctrgf6w6rtq7az62fabscwgzbax2iepwu2qlub5qzcvabn5wa + model.id: ocid1.generativeaimodel.oc1.us-chicago-1.amaaaaaask7dceyaiir6nnhmlgwvh37dr2mvragxzszqmz3hok52pcgmpqta diff --git a/examples/integrations/oci/genai/src/main/resources/logging.properties b/examples/integrations/oci/genai/src/main/resources/logging.properties new file mode 100644 index 00000000..ffad43db --- /dev/null +++ b/examples/integrations/oci/genai/src/main/resources/logging.properties @@ -0,0 +1,20 @@ + +# Example Logging Configuration File +# For more information see $JAVA_HOME/jre/lib/logging.properties + +# Send messages to the console +handlers=io.helidon.logging.jul.HelidonConsoleHandler + +# HelidonConsoleHandler uses a SimpleFormatter subclass that replaces "!thread!" with the current thread +java.util.logging.SimpleFormatter.format=%1$tY.%1$tm.%1$td %1$tH:%1$tM:%1$tS %4$s %3$s !thread!: %5$s%6$s%n + +# Global logging level. Can be overridden by specific loggers +.level=INFO + +# Quiet Weld +org.jboss.level=WARNING + +# Component specific log levels +#io.helidon.config.level=INFO +#io.helidon.security.level=INFO +#io.helidon.common.level=INFO diff --git a/examples/integrations/oci/genai/src/test/java/io/helidon/examples/integrations/oci/genai/GenAiServiceTest.java b/examples/integrations/oci/genai/src/test/java/io/helidon/examples/integrations/oci/genai/GenAiServiceTest.java new file mode 100644 index 00000000..7f8b1f8d --- /dev/null +++ b/examples/integrations/oci/genai/src/test/java/io/helidon/examples/integrations/oci/genai/GenAiServiceTest.java @@ -0,0 +1,41 @@ +package io.helidon.examples.integrations.oci.genai; + +import io.helidon.webserver.testing.junit5.ServerTest; +import io.helidon.webserver.WebServer; + +import org.junit.jupiter.api.Test; + +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.time.Duration; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +@ServerTest +public class GenAiServiceTest { + + private static HttpClient client; + private final URI baseUri; + + public GenAiServiceTest(WebServer server) throws Exception { + baseUri = URI.create("http://localhost:" + server.port()); + client = HttpClient.newBuilder() + .version(HttpClient.Version.HTTP_1_1) + .connectTimeout(Duration.ofSeconds(5)) + .build(); + } + + @Test + public void testChatModelAsk() throws Exception { + String userMessage = "Which are the most used Large Language Models?"; + HttpRequest getChatReq = HttpRequest.newBuilder() + .uri(baseUri.resolve("/genai/chat?userMessage="+userMessage)) + .GET() + .build(); + var getBooksRes = client.send(getChatReq, HttpResponse.BodyHandlers.ofString()); + assertTrue(getBooksRes.body().contains("BERT"), "actual: " + getBooksRes.body()); + } + +} diff --git a/examples/integrations/oci/pom.xml b/examples/integrations/oci/pom.xml index 4ecd5ad8..10ffa820 100644 --- a/examples/integrations/oci/pom.xml +++ b/examples/integrations/oci/pom.xml @@ -36,6 +36,8 @@ atp atp-cdi + genai + genai-cdi metrics objectstorage objectstorage-cdi