This is an automated email from the ASF dual-hosted git repository.
jamesnetherton pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/main by this push:
new 1c463984778 Make the ai-tool Ollama tests deterministic and allow an
external Ollama
1c463984778 is described below
commit 1c4639847783ea546b6e3fe5594024039cb80016
Author: Jiří Ondrušek <[email protected]>
AuthorDate: Tue Dec 1 13:49:56 2026 +0100
Make the ai-tool Ollama tests deterministic and allow an external Ollama
* ai-tool: Make the Ollama tests deterministic and allow an external Ollama
The listener records the tools offered to the model.
The wrong-tag test asserts exactly getNews is offered.
LANGCHAIN4J_OLLAMA_BASE_URL uses an external Ollama instead of dev services.
The README gets a section on running the tests with a local Ollama.
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
* ai-tool: Also assert the real model answer in the Ollama wrong-tag test
The offered-tools check duplicates the mock model test.
Only the real run proves the real Ollama model and LLM answer
without the weather tool result.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---------
Co-authored-by: jiriOndrusek-agent <[email protected]>
Co-authored-by: Claude Sonnet 5.5 <[email protected]>
---
integration-tests/ai-tool-langchain4j/README.adoc | 16 ++++++++
.../it/AiToolLangchain4jOllamaResource.java | 11 ++++++
.../tool/langchain4j/it/OfferedToolsListener.java | 45 ++++++++++++++++++++++
.../it/AiToolLangchain4jOllamaTest.java | 22 ++++++++++-
4 files changed, 92 insertions(+), 2 deletions(-)
diff --git a/integration-tests/ai-tool-langchain4j/README.adoc
b/integration-tests/ai-tool-langchain4j/README.adoc
index 40a56d5e241..0b651b01f7d 100644
--- a/integration-tests/ai-tool-langchain4j/README.adoc
+++ b/integration-tests/ai-tool-langchain4j/README.adoc
@@ -13,3 +13,19 @@ This requires Docker to be running.
----
The first run may take longer as the Ollama container image and model are
downloaded.
+
+=== Using an external Ollama
+
+To skip the dev services container and use an Ollama you manage yourself
(local or remote), make sure the `qwen3:1.7b` model is pulled there and set
`LANGCHAIN4J_OLLAMA_BASE_URL`. Example with a local Ollama:
+
+[source,shell]
+----
+ollama serve &
+until ollama list >/dev/null 2>&1; do sleep 1; done
+ollama pull qwen3:1.7b
+# or in a container:
+# podman run -d --name ollama -p 11434:11434 docker.io/ollama/ollama
+# podman exec ollama ollama pull qwen3:1.7b
+export LANGCHAIN4J_OLLAMA_BASE_URL=http://localhost:11434
+./mvnw verify -f integration-tests/ai-tool-langchain4j -Pollama
+----
diff --git
a/integration-tests/ai-tool-langchain4j/src/main/java/org/apache/camel/quarkus/component/ai/tool/langchain4j/it/AiToolLangchain4jOllamaResource.java
b/integration-tests/ai-tool-langchain4j/src/main/java/org/apache/camel/quarkus/component/ai/tool/langchain4j/it/AiToolLangchain4jOllamaResource.java
index 60fdd44967e..52a7f1fe87e 100644
---
a/integration-tests/ai-tool-langchain4j/src/main/java/org/apache/camel/quarkus/component/ai/tool/langchain4j/it/AiToolLangchain4jOllamaResource.java
+++
b/integration-tests/ai-tool-langchain4j/src/main/java/org/apache/camel/quarkus/component/ai/tool/langchain4j/it/AiToolLangchain4jOllamaResource.java
@@ -19,6 +19,7 @@ package
org.apache.camel.quarkus.component.ai.tool.langchain4j.it;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.ws.rs.Consumes;
+import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
@@ -36,6 +37,9 @@ public class AiToolLangchain4jOllamaResource {
@Inject
WeatherAiServiceOllamaWrongTag weatherAiServiceWrongTag;
+ @Inject
+ OfferedToolsListener offeredToolsListener;
+
@Path("/chat")
@POST
@Consumes(MediaType.TEXT_PLAIN)
@@ -51,4 +55,11 @@ public class AiToolLangchain4jOllamaResource {
public String chatWrongTag(String message) {
return weatherAiServiceWrongTag.chat(message);
}
+
+ @Path("/offered-tools")
+ @GET
+ @Produces(MediaType.TEXT_PLAIN)
+ public String offeredTools() {
+ return offeredToolsListener.getLastOfferedTools();
+ }
}
diff --git
a/integration-tests/ai-tool-langchain4j/src/main/java/org/apache/camel/quarkus/component/ai/tool/langchain4j/it/OfferedToolsListener.java
b/integration-tests/ai-tool-langchain4j/src/main/java/org/apache/camel/quarkus/component/ai/tool/langchain4j/it/OfferedToolsListener.java
new file mode 100644
index 00000000000..690f904db8b
--- /dev/null
+++
b/integration-tests/ai-tool-langchain4j/src/main/java/org/apache/camel/quarkus/component/ai/tool/langchain4j/it/OfferedToolsListener.java
@@ -0,0 +1,45 @@
+/*
+ * 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.ai.tool.langchain4j.it;
+
+import java.util.stream.Collectors;
+
+import dev.langchain4j.agent.tool.ToolSpecification;
+import dev.langchain4j.model.chat.listener.ChatModelListener;
+import dev.langchain4j.model.chat.listener.ChatModelRequestContext;
+import jakarta.enterprise.context.ApplicationScoped;
+
+/**
+ * Records the names of the tools offered to the Ollama chat model in the last
request.
+ */
+@ApplicationScoped
+public class OfferedToolsListener implements ChatModelListener {
+
+ private volatile String lastOfferedTools = "";
+
+ @Override
+ public void onRequest(ChatModelRequestContext requestContext) {
+ lastOfferedTools =
requestContext.chatRequest().toolSpecifications().stream()
+ .map(ToolSpecification::name)
+ .sorted()
+ .collect(Collectors.joining(","));
+ }
+
+ public String getLastOfferedTools() {
+ return lastOfferedTools;
+ }
+}
diff --git
a/integration-tests/ai-tool-langchain4j/src/test/java/org/apache/camel/quarkus/component/ai/tool/langchain4j/it/AiToolLangchain4jOllamaTest.java
b/integration-tests/ai-tool-langchain4j/src/test/java/org/apache/camel/quarkus/component/ai/tool/langchain4j/it/AiToolLangchain4jOllamaTest.java
index e49b5ded468..7d5f9982568 100644
---
a/integration-tests/ai-tool-langchain4j/src/test/java/org/apache/camel/quarkus/component/ai/tool/langchain4j/it/AiToolLangchain4jOllamaTest.java
+++
b/integration-tests/ai-tool-langchain4j/src/test/java/org/apache/camel/quarkus/component/ai/tool/langchain4j/it/AiToolLangchain4jOllamaTest.java
@@ -26,6 +26,7 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
@QuarkusTest
@@ -42,11 +43,18 @@ class AiToolLangchain4jOllamaTest {
.then()
.statusCode(200)
.body(containsString("1111"));
+
+ RestAssured.get("/ai-tool-langchain4j-ollama/offered-tools")
+ .then()
+ .statusCode(200)
+ .body(is("getWeather"));
}
// Verifies that @CamelAiTools filters tools by tag: a service tagged
"adminTag"
- // should not see the getWeather tool (tagged "weatherTag"), so the real
LLM won't call it
- // and "1111" won't appear in the response. Fails if the tag filter is
broken and all tools are visible.
+ // must be offered only the getNews tool, not getWeather (tagged
"weatherTag").
+ // The offered-tools check does not depend on the LLM answer. The answer
check adds what
+ // the mock model test cannot: the real Ollama model builds the request
and the real LLM
+ // answers without the weather tool result.
@Test
void weatherWithWrongTag() {
RestAssured.given()
@@ -56,11 +64,21 @@ class AiToolLangchain4jOllamaTest {
.then()
.statusCode(200)
.body(not(containsString("1111")));
+
+ RestAssured.get("/ai-tool-langchain4j-ollama/offered-tools")
+ .then()
+ .statusCode(200)
+ .body(is("getNews"));
}
public static class OllamaProfile implements QuarkusTestProfile {
@Override
public Map<String, String> getConfigOverrides() {
+ // Use an external Ollama if LANGCHAIN4J_OLLAMA_BASE_URL is set,
otherwise start it via dev services
+ String baseUrl = System.getenv("LANGCHAIN4J_OLLAMA_BASE_URL");
+ if (baseUrl != null && !baseUrl.isBlank()) {
+ return Map.of("quarkus.langchain4j.ollama.base-url", baseUrl);
+ }
return Map.of(
"quarkus.devservices.enabled", "true",
"quarkus.langchain4j.devservices.enabled", "true");