This is an automated email from the ASF dual-hosted git repository.
Croway pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new c087fc46bd0b chore(camel-spring-ai-chat): run the integration tests on
any OpenAI-compatible server
c087fc46bd0b is described below
commit c087fc46bd0b0ff9e7100cdb3d2c2f2446b01a1d
Author: croway <[email protected]>
AuthorDate: Tue Nov 24 16:20:36 2026 +0100
chore(camel-spring-ai-chat): run the integration tests on any
OpenAI-compatible server
The Spring AI chat integration tests could only run on Ollama:
OllamaTestSupport built an
OllamaChatModel, and the vector store tests an OllamaEmbeddingModel, even
with
-Dollama.instance.type=openai, which the camel-openai, langchain4j and
mcp-server tests
already support.
With -Dollama.instance.type=openai, OllamaTestSupport now builds Spring
AI's OpenAI chat and
embedding models from openai.endpoint, openai.model, openai.embedding.model
and
openai.api.key. Thinking is turned off with reasoning_effort=none and
chat_template_kwargs
(enable_thinking=false), which Ollama's OpenAI API and vLLM read, as
disableThinking() does on
Ollama. Neither field is sent to the OpenAI platform, and
-Dopenai.disable.thinking=false
leaves both out for servers that reject reasoning_effort=none. The vector
store tests get
their embedding model from the same support class.
The camel-spring-ai test guide describes the new mode. Test-only change:
spring-ai-openai is
added with test scope.
---
.../camel-spring-ai/camel-spring-ai-chat/pom.xml | 6 ++
.../component/springai/chat/OllamaTestSupport.java | 76 +++++++++++++++++++++-
.../springai/chat/SpringAiChatVectorMemoryIT.java | 15 +----
.../springai/chat/SpringAiChatVectorStoreIT.java | 15 +----
.../camel-spring-ai/test-execution.md | 36 +++++++++-
5 files changed, 118 insertions(+), 30 deletions(-)
diff --git
a/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/pom.xml
b/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/pom.xml
index c28f830e626e..c02b686a6afc 100644
---
a/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/pom.xml
+++
b/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/pom.xml
@@ -148,6 +148,12 @@
<artifactId>spring-ai-ollama</artifactId>
<scope>test</scope>
</dependency>
+ <!-- Spring AI OpenAI for integration tests against OpenAI-compatible
servers -->
+ <dependency>
+ <groupId>org.springframework.ai</groupId>
+ <artifactId>spring-ai-openai</artifactId>
+ <scope>test</scope>
+ </dependency>
<!-- Ollama test infrastructure -->
<dependency>
<groupId>org.apache.camel</groupId>
diff --git
a/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/src/test/java/org/apache/camel/component/springai/chat/OllamaTestSupport.java
b/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/src/test/java/org/apache/camel/component/springai/chat/OllamaTestSupport.java
index 914074f644d0..cb848280b21c 100644
---
a/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/src/test/java/org/apache/camel/component/springai/chat/OllamaTestSupport.java
+++
b/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/src/test/java/org/apache/camel/component/springai/chat/OllamaTestSupport.java
@@ -16,18 +16,31 @@
*/
package org.apache.camel.component.springai.chat;
+import java.net.URI;
+import java.util.Locale;
+import java.util.Map;
+
import org.apache.camel.CamelContext;
import org.apache.camel.test.infra.ollama.services.OllamaService;
import org.apache.camel.test.infra.ollama.services.OllamaServiceFactory;
+import org.apache.camel.test.infra.ollama.services.OpenAIService;
import org.apache.camel.test.junit6.CamelTestSupport;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.springframework.ai.chat.model.ChatModel;
+import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.ollama.OllamaChatModel;
+import org.springframework.ai.ollama.OllamaEmbeddingModel;
import org.springframework.ai.ollama.api.OllamaApi;
import org.springframework.ai.ollama.api.OllamaChatOptions;
+import org.springframework.ai.ollama.api.OllamaEmbeddingOptions;
+import org.springframework.ai.openai.OpenAiChatModel;
+import org.springframework.ai.openai.OpenAiChatOptions;
+import org.springframework.ai.openai.OpenAiEmbeddingModel;
+import org.springframework.ai.openai.OpenAiEmbeddingOptions;
/**
- * Base test support class for Spring AI Ollama integration tests.
+ * Base test support class for the Spring AI chat integration tests. They run
on Ollama by default, and on any
+ * OpenAI-compatible server with -Dollama.instance.type=openai.
*/
public class OllamaTestSupport extends CamelTestSupport {
@@ -52,6 +65,10 @@ public class OllamaTestSupport extends CamelTestSupport {
}
protected ChatModel createModel() {
+ if (OLLAMA instanceof OpenAIService) {
+ return createOpenAiModel();
+ }
+
OllamaApi ollamaApi = OllamaApi.builder()
.baseUrl(OLLAMA.baseUrl())
.build();
@@ -72,4 +89,61 @@ public class OllamaTestSupport extends CamelTestSupport {
return chatModel;
}
+
+ /**
+ * The embedding model of the tests that fill a vector store: the
embedding model of the OpenAI-compatible server
+ * with -Dollama.instance.type=openai (-Dopenai.embedding.model),
otherwise embeddinggemma:300m on Ollama.
+ */
+ protected EmbeddingModel createEmbeddingModel() {
+ if (OLLAMA instanceof OpenAIService) {
+ OpenAiEmbeddingOptions options = OpenAiEmbeddingOptions.builder()
+ .baseUrl(OLLAMA.baseUrlV1())
+ .apiKey(OLLAMA.apiKey())
+ .model(OLLAMA.embeddingModelName())
+ .build();
+ return OpenAiEmbeddingModel.builder().options(options).build();
+ }
+
+ OllamaApi ollamaApi = OllamaApi.builder()
+ .baseUrl(OLLAMA.baseUrl())
+ .build();
+
+ return OllamaEmbeddingModel.builder()
+ .ollamaApi(ollamaApi)
+ .options(OllamaEmbeddingOptions.builder()
+ .model("embeddinggemma:300m")
+ .build())
+ .build();
+ }
+
+ /**
+ * Any OpenAI-compatible server (-Dollama.instance.type=openai with
-Dopenai.endpoint, -Dopenai.model and
+ * -Dopenai.api.key). Thinking is turned off as disableThinking() does on
Ollama: Ollama's OpenAI API reads
+ * reasoning_effort, vLLM reads it too and also takes enable_thinking from
the chat template arguments. The OpenAI
+ * platform gets neither: it is strict about the request fields it
accepts. -Dopenai.disable.thinking=false leaves
+ * both out, for servers that reject reasoning_effort=none (vLLM before
0.18, GPT-OSS models).
+ */
+ private ChatModel createOpenAiModel() {
+ OpenAiChatOptions.Builder options = OpenAiChatOptions.builder()
+ .baseUrl(OLLAMA.baseUrlV1())
+ .apiKey(OLLAMA.apiKey())
+ .model(modelName())
+ .temperature(0.3);
+ if (Boolean.parseBoolean(System.getProperty("openai.disable.thinking",
"true"))
+ && !isOpenAiPlatform(OLLAMA.baseUrlV1())) {
+ options.extraBody(Map.of(
+ "reasoning_effort", "none",
+ "chat_template_kwargs", Map.of("enable_thinking", false)));
+ }
+ return OpenAiChatModel.builder().options(options.build()).build();
+ }
+
+ private static boolean isOpenAiPlatform(String baseUrl) {
+ String host = URI.create(baseUrl).getHost();
+ if (host == null) {
+ return false;
+ }
+ host = host.toLowerCase(Locale.ROOT);
+ return host.equals("api.openai.com") ||
host.endsWith(".api.openai.com");
+ }
}
diff --git
a/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/src/test/java/org/apache/camel/component/springai/chat/SpringAiChatVectorMemoryIT.java
b/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/src/test/java/org/apache/camel/component/springai/chat/SpringAiChatVectorMemoryIT.java
index b59d2d80b7f0..e155aeb69d59 100644
---
a/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/src/test/java/org/apache/camel/component/springai/chat/SpringAiChatVectorMemoryIT.java
+++
b/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/src/test/java/org/apache/camel/component/springai/chat/SpringAiChatVectorMemoryIT.java
@@ -20,9 +20,6 @@ import org.apache.camel.builder.RouteBuilder;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledIfSystemProperty;
import org.springframework.ai.embedding.EmbeddingModel;
-import org.springframework.ai.ollama.OllamaEmbeddingModel;
-import org.springframework.ai.ollama.api.OllamaApi;
-import org.springframework.ai.ollama.api.OllamaEmbeddingOptions;
import org.springframework.ai.vectorstore.SimpleVectorStore;
import org.springframework.ai.vectorstore.VectorStore;
@@ -43,17 +40,7 @@ public class SpringAiChatVectorMemoryIT extends
OllamaTestSupport {
protected void setupResources() throws Exception {
super.setupResources();
- // Create embedding model for vector store
- OllamaApi ollamaApi = OllamaApi.builder()
- .baseUrl(OLLAMA.baseUrl())
- .build();
-
- EmbeddingModel embeddingModel = OllamaEmbeddingModel.builder()
- .ollamaApi(ollamaApi)
- .options(OllamaEmbeddingOptions.builder()
- .model("embeddinggemma:300m")
- .build())
- .build();
+ EmbeddingModel embeddingModel = createEmbeddingModel();
// Create vector store for chat memory
chatMemoryVectorStore = SimpleVectorStore.builder(embeddingModel)
diff --git
a/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/src/test/java/org/apache/camel/component/springai/chat/SpringAiChatVectorStoreIT.java
b/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/src/test/java/org/apache/camel/component/springai/chat/SpringAiChatVectorStoreIT.java
index 91b6b79faa44..5498a09b43be 100644
---
a/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/src/test/java/org/apache/camel/component/springai/chat/SpringAiChatVectorStoreIT.java
+++
b/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/src/test/java/org/apache/camel/component/springai/chat/SpringAiChatVectorStoreIT.java
@@ -24,9 +24,6 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledIfSystemProperty;
import org.springframework.ai.document.Document;
import org.springframework.ai.embedding.EmbeddingModel;
-import org.springframework.ai.ollama.OllamaEmbeddingModel;
-import org.springframework.ai.ollama.api.OllamaApi;
-import org.springframework.ai.ollama.api.OllamaEmbeddingOptions;
import org.springframework.ai.vectorstore.SimpleVectorStore;
import org.springframework.ai.vectorstore.VectorStore;
@@ -44,17 +41,7 @@ public class SpringAiChatVectorStoreIT extends
OllamaTestSupport {
protected void setupResources() throws Exception {
super.setupResources();
- // Create embedding model for vector store
- OllamaApi ollamaApi = OllamaApi.builder()
- .baseUrl(OLLAMA.baseUrl())
- .build();
-
- EmbeddingModel embeddingModel = OllamaEmbeddingModel.builder()
- .ollamaApi(ollamaApi)
- .options(OllamaEmbeddingOptions.builder()
- .model("embeddinggemma:300m")
- .build())
- .build();
+ EmbeddingModel embeddingModel = createEmbeddingModel();
// Create and populate vector store
vectorStore = SimpleVectorStore.builder(embeddingModel)
diff --git a/components/camel-spring-parent/camel-spring-ai/test-execution.md
b/components/camel-spring-parent/camel-spring-ai/test-execution.md
index b1d5bb22994c..6fc6544e51df 100644
--- a/components/camel-spring-parent/camel-spring-ai/test-execution.md
+++ b/components/camel-spring-parent/camel-spring-ai/test-execution.md
@@ -65,7 +65,8 @@ from Ollama if it has not been pulled:
| `embeddinggemma:300m` | `SpringAiChatVectorStoreIT`,
`SpringAiChatVectorMemoryIT`, `QdrantVectorStoreIT` |
| `x/flux2-klein:4b` | `SpringAiImageOllamaIT` |
-`ollama.embedding.model` only drives `SpringAiEmbeddingsIT`.
+`ollama.embedding.model` only drives `SpringAiEmbeddingsIT`. With
`-Dollama.instance.type=openai`, the two
+chat vector ITs use `openai.embedding.model` instead of `embeddinggemma:300m`.
### Extra requirements
@@ -82,6 +83,39 @@ with empty content, so the assertions fail or the run hangs
on an unbounded gene
accepts `think=false` on models without a thinking mode too, so this is safe
for every model —
the granite4:3b result is identical with and without it.
+### Any OpenAI-compatible server
+
+`camel-spring-ai-chat` also runs on vLLM, LiteLLM, LM Studio, Ollama's `/v1`
endpoint or OpenAI. With
+`-Dollama.instance.type=openai`, `OllamaTestSupport` builds Spring AI's OpenAI
chat and embedding models
+instead of the Ollama ones. Pass the key in the `OPENAI_API_KEY` environment
variable: an `openai.api.key`
+system property is written into the failsafe reports. The MCP filesystem
server that `SpringAiChatMcpIT` starts
+with `npx` inherits that environment, so leave that IT out when the key is one
you do not want to share with it.
+
+```bash
+export OPENAI_API_KEY=... # any value for a server that checks none
+mvn verify -pl camel-spring-ai-chat -Dollama.instance.type=openai \
+ -Dopenai.endpoint=http://localhost:8000/v1 \
+ -Dopenai.model=my-model \
+ -Dopenai.embedding.model=my-embedding-model
+```
+
+- `openai.endpoint` defaults to `https://api.openai.com/v1/`, `openai.model`
to `gpt-4o-mini` and
+ `openai.embedding.model` to `text-embedding-ada-002`. They can also be set
with the `OPENAI_BASE_URL`,
+ `OPENAI_MODEL` and `OPENAI_EMBEDDING_MODEL` environment variables.
+- `openai.embedding.model` drives `SpringAiChatVectorStoreIT` and
`SpringAiChatVectorMemoryIT`. On a server
+ without an embedding model, leave them out:
+
`-Dit.test='SpringAiChat*IT,!SpringAiChatVectorStoreIT,!SpringAiChatVectorMemoryIT'`.
+- Thinking is turned off with `reasoning_effort: none` and
`chat_template_kwargs` (`enable_thinking: false`),
+ which Ollama and vLLM read, as `disableThinking()` does on Ollama. Neither
is sent to the OpenAI platform.
+ `-Dopenai.disable.thinking=false` leaves both out, for servers that reject
`reasoning_effort: none` (vLLM
+ before 0.18, GPT-OSS models).
+- The tool-calling ITs need a server that accepts `tool_choice: auto`: start
vLLM with
+ `--enable-auto-tool-choice` and the `--tool-call-parser` of the model.
+- The tests set `temperature` and other sampling options, so use a model that
accepts them. OpenAI's reasoning
+ models only accept the default temperature.
+- A slow server can take longer than the 600s `camel.failsafe.forkTimeout`:
raise it, for example with
+ `-Dcamel.failsafe.forkTimeout=3600`.
+
### Other models tried
Measured on `camel-spring-ai-chat` (91 tests, 5 skipped) on Apple Silicon.
Ollama is MLX-backed on