From f76ad94c42c814cca7c151325c1db1dc6b86e846 Mon Sep 17 00:00:00 2001 From: Thomas Vitale Date: Sat, 20 Jan 2024 21:49:59 +0100 Subject: [PATCH] Update tests and docs --- .github/workflows/commit-stage.yml | 27 +++++++++++++++++++ 01-chat-models/chat-models-ollama/README.md | 9 +++++++ .../ChatModelsOllamaApplicationTests.java | 23 ++-------------- .../TestChatModelsOllamaApplication.java | 1 - 01-chat-models/chat-models-openai/README.md | 9 +++++++ 5 files changed, 47 insertions(+), 22 deletions(-) create mode 100644 .github/workflows/commit-stage.yml create mode 100644 01-chat-models/chat-models-ollama/README.md create mode 100644 01-chat-models/chat-models-openai/README.md diff --git a/.github/workflows/commit-stage.yml b/.github/workflows/commit-stage.yml new file mode 100644 index 0000000..749f373 --- /dev/null +++ b/.github/workflows/commit-stage.yml @@ -0,0 +1,27 @@ +name: Commit Stage +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + build: + name: Build + runs-on: ubuntu-22.04 + permissions: + contents: read + steps: + - name: Check out source code + uses: actions/checkout@v4 + + - name: Set up Java + uses: actions/setup-java@v4 + with: + java-version: 21 + distribution: temurin + + - name: Compile and test + run: ./gradlew build diff --git a/01-chat-models/chat-models-ollama/README.md b/01-chat-models/chat-models-ollama/README.md new file mode 100644 index 0000000..4db2d8c --- /dev/null +++ b/01-chat-models/chat-models-ollama/README.md @@ -0,0 +1,9 @@ +# Chat Models: Ollama + +```shell +./gradlew bootTestRun +``` + +```shell +http :8080/ai/chat +``` diff --git a/01-chat-models/chat-models-ollama/src/test/java/com/thomasvitale/ai/spring/ChatModelsOllamaApplicationTests.java b/01-chat-models/chat-models-ollama/src/test/java/com/thomasvitale/ai/spring/ChatModelsOllamaApplicationTests.java index 57908d9..c3355df 100644 --- a/01-chat-models/chat-models-ollama/src/test/java/com/thomasvitale/ai/spring/ChatModelsOllamaApplicationTests.java +++ b/01-chat-models/chat-models-ollama/src/test/java/com/thomasvitale/ai/spring/ChatModelsOllamaApplicationTests.java @@ -1,32 +1,13 @@ package com.thomasvitale.ai.spring; import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.annotation.Import; -import org.springframework.test.web.reactive.server.WebTestClient; -import static org.assertj.core.api.Assertions.assertThat; - -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -@Import(TestChatModelsOllamaApplication.class) -@AutoConfigureWebTestClient(timeout = "30s") +@SpringBootTest class ChatModelsOllamaApplicationTests { - @Autowired - WebTestClient webTestClient; - @Test - void chat() { - webTestClient - .get() - .uri("/ai/chat") - .exchange() - .expectStatus().isOk() - .expectBody(String.class).value(response -> { - assertThat(response).contains("You shall not pass"); - }); + void contextLoads() { } } diff --git a/01-chat-models/chat-models-ollama/src/test/java/com/thomasvitale/ai/spring/TestChatModelsOllamaApplication.java b/01-chat-models/chat-models-ollama/src/test/java/com/thomasvitale/ai/spring/TestChatModelsOllamaApplication.java index de4ff1a..0189ddf 100644 --- a/01-chat-models/chat-models-ollama/src/test/java/com/thomasvitale/ai/spring/TestChatModelsOllamaApplication.java +++ b/01-chat-models/chat-models-ollama/src/test/java/com/thomasvitale/ai/spring/TestChatModelsOllamaApplication.java @@ -15,7 +15,6 @@ GenericContainer ollama(DynamicPropertyRegistry properties) { .withExposedPorts(11434); properties.add("spring.ai.ollama.base-url", () -> "http://%s:%s".formatted(ollama.getHost(), ollama.getMappedPort(11434))); - properties.add("spring.ai.ollama.chat.model", () -> "llama2"); return ollama; } diff --git a/01-chat-models/chat-models-openai/README.md b/01-chat-models/chat-models-openai/README.md new file mode 100644 index 0000000..d1d095c --- /dev/null +++ b/01-chat-models/chat-models-openai/README.md @@ -0,0 +1,9 @@ +# Chat Models: OpenAI + +```shell +./gradlew bootRun +``` + +```shell +http :8080/ai/chat +```