jamesnetherton commented on code in PR #8227: URL: https://github.com/apache/camel-quarkus/pull/8227#discussion_r2745532827
########## integration-tests/openai/src/test/java/org/apache/camel/quarkus/component/openai/it/OpenaiTest.java: ########## @@ -0,0 +1,179 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.camel.quarkus.component.openai.it; + +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.time.Duration; +import java.util.stream.IntStream; + +import io.quarkus.test.common.QuarkusTestResource; +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.RestAssured; +import io.restassured.http.ContentType; +import org.awaitility.Awaitility; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.Matchers.containsStringIgnoringCase; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; + +@QuarkusTestResource(OpenaiTestResource.class) +@QuarkusTest +class OpenaiTest { + @Test + void simpleChat() { + RestAssured.given() + .contentType(ContentType.TEXT) + .body("In one sentence, what is Apache Camel?") + .post("/openai/chat") + .then() + .statusCode(200) + .body(containsStringIgnoringCase("integration framework")); + } + + @Test + void chatWithImage() throws IOException { + Path path = Paths.get("target/camel-log.png"); + + try (InputStream stream = OpenaiTest.class.getResourceAsStream("/img/camel-logo.png")) { + if (stream == null) { + throw new IllegalStateException("Failed loading camel-logo.png"); + } + + stream.transferTo(new FileOutputStream(path.toFile())); + + RestAssured.given() + .queryParam("userMessage", "Describe what you see in this image") + .body("target/camel-log.png") + .post("/openai/chat/image") + .then() + .statusCode(200) + .body( + containsStringIgnoringCase("camel"), + containsStringIgnoringCase("silhouette"), + containsStringIgnoringCase("logo")); + } finally { + Files.deleteIfExists(path); + } + } + + @Test + void chatInitiatedFromFileConsumer() throws IOException { + Path prompts = Paths.get("target/prompts"); + Path prompt = prompts.resolve("whatis-camel-prompt.txt"); + Files.createDirectories(prompts); + + try (InputStream stream = OpenaiTest.class.getResourceAsStream("/prompts/whatis-camel-prompt.txt")) { + if (stream == null) { + throw new IllegalStateException("Failed loading whatis-camel-prompt.txt"); + } + + stream.transferTo(new FileOutputStream(prompt.toFile())); + + // Start the file-prompts route + RestAssured.given() + .post("/openai/routes/file-prompts/start") + .then() + .statusCode(204); + + Awaitility.await().pollDelay(Duration.ofSeconds(1)).atMost(Duration.ofMinutes(1)).untilAsserted(() -> { + RestAssured.given() + .queryParam("endpointUri", "seda:filePromptResults") + .get("/openai/chat/results") + .then() + .statusCode(200) + .body(containsStringIgnoringCase("integration framework")); + }); + } finally { + // Stop the file-prompts route + RestAssured.given() + .post("/openai/routes/file-prompts/stop") + .then() + .statusCode(204); + + Files.deleteIfExists(prompt); + } + } + + @Test + void chatWithMemory() { + RestAssured.given() + .contentType(ContentType.TEXT) + .body("I am a Camel and my species is Camelus Dromedarius.") + .post("/openai/chat/memory") + .then() + .statusCode(200) + .body(containsStringIgnoringCase("Camelus Dromedarius")); + } + + @Test + void streamingChat() { + // Send the streaming request + RestAssured.given() + .contentType(ContentType.TEXT) + .body("Stream the numbers 1 to 10 on a new line each time and nothing else.") + .post("/openai/chat/streaming") + .then() + .statusCode(204); + + // Assert the streamed results + IntStream.rangeClosed(1, 10) Review Comment: Ok - thanks for the feedback. Lets see how it goes. If it does prove to be flaky on CI, I will rework it. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
