You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by al...@apache.org on 2024/10/08 14:48:57 UTC

(camel-quarkus-examples) branch camel-quarkus-main updated (901b2b8 -> b62f180)

This is an automated email from the ASF dual-hosted git repository.

aldettinger pushed a change to branch camel-quarkus-main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus-examples.git


    from 901b2b8  Bump the maven group across 28 directories with 2 updates
     new b8f1ec3  data-extract: switch to ollama container maintained version
     new b62f180  data-extract: switch tests to ollama maintained containers

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 data-extract-langchain4j/README.adoc               | 25 ++++++-
 data-extract-langchain4j/pom.xml                   |  2 +-
 .../org/acme/extraction/OllamaTestResource.java    | 80 ++++++++++++----------
 3 files changed, 65 insertions(+), 42 deletions(-)


(camel-quarkus-examples) 01/02: data-extract: switch to ollama container maintained version

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aldettinger pushed a commit to branch camel-quarkus-main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus-examples.git

commit b8f1ec3bf824a0262151a5a178bd3e5ad33e2168
Author: aldettinger <al...@gmail.com>
AuthorDate: Tue Oct 8 14:56:02 2024 +0200

    data-extract: switch to ollama container maintained version
---
 data-extract-langchain4j/README.adoc | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)

diff --git a/data-extract-langchain4j/README.adoc b/data-extract-langchain4j/README.adoc
index 3970d36..00ea497 100644
--- a/data-extract-langchain4j/README.adoc
+++ b/data-extract-langchain4j/README.adoc
@@ -22,21 +22,40 @@ Finally, we'll invoke the AiService extraction method via the https://camel.apac
 
 === Start the Large Language Model
 
-Let's start a container to serve the LLM with Ollama:
+Let's start a container to serve the LLM with Ollama, in a first shell type:
 
 [source,shell]
 ----
-docker run -p11434:11434 langchain4j/ollama-codellama:latest
+docker run --rm -it -v cqex-data-extract-ollama:/root/.ollama -p 11434:11434 --name cqex-data-extract-ollama ollama/ollama:0.3.12
 ----
 
 After a moment, a log like below should be output:
 
 [source,shell]
 ----
-time=2024-09-03T08:03:15.532Z level=INFO source=types.go:98 msg="inference compute" id=0 library=cpu compute="" driver=0.0 name="" total="62.5 GiB" available="54.4 GiB"
+time=2024-10-08T12:43:43.329Z level=INFO source=types.go:107 msg="inference compute" id=0 library=cpu variant=avx2 compute="" driver=0.0 name="" total="62.5 GiB" available="52.4 GiB"
+----
+
+Then, download the codellama model, in a second shell type:
+
+[source,shell]
+----
+docker exec -it cqex-data-extract-ollama ollama pull codellama
+----
+
+After a moment, log like below should be output:
+
+[source,shell]
+----
+pulling manifest 
+...
+verifying sha256 digest 
+writing manifest 
+success 
 ----
 
 That's it, the LLM is now ready to serve our data extraction requests.
+The second shell could be reused, however the first one need to stay up while running this example.
 
 === Package and run the application
 


(camel-quarkus-examples) 02/02: data-extract: switch tests to ollama maintained containers

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aldettinger pushed a commit to branch camel-quarkus-main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus-examples.git

commit b62f180219269a21d9e22c8de1442e868cf34958
Author: aldettinger <al...@gmail.com>
AuthorDate: Tue Oct 8 15:43:08 2024 +0200

    data-extract: switch tests to ollama maintained containers
---
 data-extract-langchain4j/pom.xml                   |  2 +-
 .../org/acme/extraction/OllamaTestResource.java    | 80 ++++++++++++----------
 2 files changed, 43 insertions(+), 39 deletions(-)

diff --git a/data-extract-langchain4j/pom.xml b/data-extract-langchain4j/pom.xml
index 7a6d145..1236aa8 100644
--- a/data-extract-langchain4j/pom.xml
+++ b/data-extract-langchain4j/pom.xml
@@ -126,7 +126,7 @@
         </dependency>
         <dependency>
             <groupId>org.testcontainers</groupId>
-            <artifactId>testcontainers</artifactId>
+            <artifactId>ollama</artifactId>
             <scope>test</scope>
         </dependency>
         <dependency>
diff --git a/data-extract-langchain4j/src/test/java/org/acme/extraction/OllamaTestResource.java b/data-extract-langchain4j/src/test/java/org/acme/extraction/OllamaTestResource.java
index 2a9489e..b9cebd6 100644
--- a/data-extract-langchain4j/src/test/java/org/acme/extraction/OllamaTestResource.java
+++ b/data-extract-langchain4j/src/test/java/org/acme/extraction/OllamaTestResource.java
@@ -23,32 +23,30 @@ import com.github.tomakehurst.wiremock.WireMockServer;
 import io.quarkus.test.common.QuarkusTestResourceLifecycleManager;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.testcontainers.containers.GenericContainer;
 import org.testcontainers.containers.output.Slf4jLogConsumer;
-import org.testcontainers.containers.wait.strategy.Wait;
+import org.testcontainers.ollama.OllamaContainer;
 
 import static java.lang.String.format;
 
+import static org.eclipse.microprofile.config.ConfigProvider.getConfig;
+
 public class OllamaTestResource implements QuarkusTestResourceLifecycleManager {
 
     private static final Logger LOG = LoggerFactory.getLogger(OllamaTestResource.class);
 
-    // LangChain4j offers only latest tag for ollama-codellama, hence we do use latest until more tags are introduced
-    private static final String OLLAMA_IMAGE = "langchain4j/ollama-codellama:latest";
+    private static final String OLLAMA_IMAGE = "ollama/ollama:0.3.12";
     private static final int OLLAMA_SERVER_PORT = 11434;
 
-    private GenericContainer<?> ollamaContainer;
-
-    private WireMockServer wireMockServer;
-    private String baseUrl;
-
     private static final String MODE_MOCK = "mock";
     private static final String MODE_RECORDING = "record";
     private static final String MODE_CONTAINER = "container";
 
+    private OllamaContainer ollamaContainer;
+    private WireMockServer wireMockServer;
+    private String baseUrl;
+
     /**
-     * The testMode value could be defined, for instance by invoking:
-     * mvn clean test -DtestMode=mock.
+     * The testMode value could be defined, for instance by invoking: mvn clean test -DtestMode=mock.
      *
      * With the default value "mock", the LLM is faked based on the last recorded run.
      * With the value "record", tests are run against a containerized LLM while the HTTP interactions are recorded.
@@ -64,36 +62,42 @@ public class OllamaTestResource implements QuarkusTestResourceLifecycleManager {
     @Override
     public Map<String, String> start() {
 
-        // Check the test running mode
-        String testMode = System.getProperty("testMode", MODE_MOCK);
-        isMockMode = MODE_MOCK.equals(testMode);
-        isRecordingMode = MODE_RECORDING.equals(testMode);
-        isContainerMode = MODE_CONTAINER.equals(testMode);
-        if (!isMockMode && !isRecordingMode && !isContainerMode) {
-            throw new IllegalArgumentException(
-                    "testMode value should be one of " + Arrays.asList(MODE_MOCK, MODE_RECORDING, MODE_CONTAINER));
-        }
+        try {
+            // Check the test running mode
+            String testMode = System.getProperty("testMode", MODE_MOCK);
+            isMockMode = MODE_MOCK.equals(testMode);
+            isRecordingMode = MODE_RECORDING.equals(testMode);
+            isContainerMode = MODE_CONTAINER.equals(testMode);
+            if (!isMockMode && !isRecordingMode && !isContainerMode) {
+                throw new IllegalArgumentException(
+                        "testMode value should be one of " + Arrays.asList(MODE_MOCK, MODE_RECORDING, MODE_CONTAINER));
+            }
 
-        if (isMockMode) {
-            LOG.info("Starting a fake Ollama server backed by wiremock");
-            initWireMockServer();
-        } else {
-            LOG.info("Starting an Ollama server backed by testcontainers");
-            ollamaContainer = new GenericContainer<>(OLLAMA_IMAGE)
-                    .withExposedPorts(OLLAMA_SERVER_PORT)
-                    .withLogConsumer(new Slf4jLogConsumer(LOG).withPrefix("basicAuthContainer"))
-                    .waitingFor(Wait.forLogMessage(".* msg=\"inference compute\" .*", 1));
-            ollamaContainer.start();
-
-            baseUrl = format(BASE_URL_FORMAT, ollamaContainer.getHost(), ollamaContainer.getMappedPort(OLLAMA_SERVER_PORT));
-
-            if (isRecordingMode) {
-                LOG.info("Recording interactions with the Ollama server backed by testcontainers");
+            if (isMockMode) {
+                LOG.info("Starting a fake Ollama server backed by wiremock");
                 initWireMockServer();
+            } else {
+                LOG.info("Starting an Ollama server backed by testcontainers");
+                ollamaContainer = new OllamaContainer(OLLAMA_IMAGE)
+                        .withLogConsumer(new Slf4jLogConsumer(LOG).withPrefix("basicAuthContainer"));
+                ollamaContainer.start();
+
+                String ollamaModelId = getConfig().getValue("quarkus.langchain4j.ollama.chat-model.model-id", String.class);
+
+                ollamaContainer.execInContainer("ollama", "pull", ollamaModelId);
+
+                baseUrl = format(BASE_URL_FORMAT, ollamaContainer.getHost(), ollamaContainer.getMappedPort(OLLAMA_SERVER_PORT));
+
+                if (isRecordingMode) {
+                    LOG.info("Recording interactions with the Ollama server backed by testcontainers");
+                    initWireMockServer();
+                }
             }
-        }
 
-        return Map.of("quarkus.langchain4j.ollama.base-url", baseUrl);
+            return Map.of("quarkus.langchain4j.ollama.base-url", baseUrl);
+        } catch (Exception ex) {
+            throw new RuntimeException("An issue occurred while starting ollama container", ex);
+        }
     }
 
     private void initWireMockServer() {
@@ -113,7 +117,7 @@ public class OllamaTestResource implements QuarkusTestResourceLifecycleManager {
                 ollamaContainer.stop();
             }
         } catch (Exception ex) {
-            LOG.error("An issue occurred while stopping " + ollamaContainer.getNetworkAliases(), ex);
+            LOG.error("An issue occurred while stopping ollama container", ex);
         }
 
         if (isMockMode) {