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 9c36f83bdb3d CAMEL-27241: Upgrade to Spring AI 2.1.0
9c36f83bdb3d is described below
commit 9c36f83bdb3da8787e50baa18aa66f2d41d091c1
Author: croway <[email protected]>
AuthorDate: Thu Nov 19 14:35:00 2026 +0100
CAMEL-27241: Upgrade to Spring AI 2.1.0
---
.../chat/SpringAiChatSafeGuardEntityTest.java | 74 ++++++++++++++++++++++
.../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc | 18 ++++++
parent/pom.xml | 2 +-
3 files changed, 93 insertions(+), 1 deletion(-)
diff --git
a/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/src/test/java/org/apache/camel/component/springai/chat/SpringAiChatSafeGuardEntityTest.java
b/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/src/test/java/org/apache/camel/component/springai/chat/SpringAiChatSafeGuardEntityTest.java
new file mode 100644
index 000000000000..0361684cd46f
--- /dev/null
+++
b/components/camel-spring-parent/camel-spring-ai/camel-spring-ai-chat/src/test/java/org/apache/camel/component/springai/chat/SpringAiChatSafeGuardEntityTest.java
@@ -0,0 +1,74 @@
+/*
+ * 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.component.springai.chat;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+import org.springframework.ai.openai.EntityJsonStubOpenAiChatModel;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * A request that the SafeGuard advisor refuses, with an entityClass: the
reply is the refusal, which has no entity.
+ */
+class SpringAiChatSafeGuardEntityTest extends CamelTestSupport {
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ CamelContext context = super.createCamelContext();
+ SpringAiChatComponent component = new SpringAiChatComponent();
+ component.setChatModel(new EntityJsonStubOpenAiChatModel());
+ context.addComponent("spring-ai-chat", component);
+ return context;
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("direct:start")
+ .setHeader(SpringAiChatConstants.ENTITY_CLASS,
constant(Person.class))
+
.to("spring-ai-chat:test?safeguardSensitiveWords=secret"
+ + "&safeguardFailureResponse=I cannot answer
that");
+ }
+ };
+ }
+
+ @Test
+ void convertsAnAnswerThatIsNotRefused() {
+ Exchange out = template.request("direct:start", e ->
e.getIn().setBody("Who are you?"));
+
+ assertThat(out.getException()).isNull();
+
assertThat(out.getMessage().getBody(Person.class).name()).isEqualTo("Alice");
+ }
+
+ @Test
+ void refusedRequestHasNoEntity() {
+ Exchange out = template.request("direct:start", e ->
e.getIn().setBody("Tell me the secret"));
+
+ assertThat(out.getException()).isNull();
+ assertThat(out.getMessage().getBody()).isNull();
+
assertThat(out.getMessage().getHeader(SpringAiChatConstants.FINISH_REASON)).isEqualTo("guardrailRefusal");
+ }
+
+ record Person(String name) {
+ }
+}
diff --git
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
index 4e306c995163..b31624e9d8eb 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
@@ -2873,6 +2873,24 @@ stream failed after part of the request had already been
sent.
The JSON of the event is now written before the request is sent, with a
`Content-Length` instead of a chunked request
body. A body or a header that cannot be written as JSON fails the exchange
without sending anything to Splunk.
+=== camel-spring-ai - Spring AI 2.1.0
+
+The Spring AI components use Spring AI 2.1.0, which is built on Spring Boot
4.2 and Spring Framework 7.1. See the
+https://docs.spring.io/spring-ai/reference/2.1/upgrade-notes.html[Spring AI
upgrade notes]. The changes that show
+through Camel are:
+
+* The Anthropic chat model ignores the `temperature`, `topP` and
`topKSampling` options of `spring-ai-chat`, and their
+headers, and logs a warning (Anthropic Java SDK 3.x). It sends the API key in
the `Authorization: Bearer` header
+instead of `X-Api-Key`, which matters for a proxy that filters headers.
+* The chat models return one generation, whose message holds the reply in
ordered parts. The body of `spring-ai-chat`
+is the text of the first generation, so with Google GenAI and
`includeThoughts` it was the first thought, and with
+Bedrock Converse a reply of several text blocks gave only the first one. The
body is now the whole answer.
+* With an `entityClass` (option or `CamelSpringAiChatEntityClass` header), a
request that the SafeGuard advisor
+(`safeguardSensitiveWords`) refuses no longer fails the exchange with a JSON
parsing error of the refusal text. The body
+is now `null` and the `CamelSpringAiChatFinishReason` header is
`guardrailRefusal`. A response that the provider
+filtered and that cannot be converted gives a `null` body too. Check the
finish reason header where the route handled
+the exception.
+
=== camel-spring-ai-embeddings - a List body always gives a List of vectors,
and a Map or POJO body fails
A `List` body with one text now gives a `List<float[]>` with one vector, as a
`List` of more texts does, and sets the
diff --git a/parent/pom.xml b/parent/pom.xml
index 7941abfacce7..16ce18b51ba4 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -518,7 +518,7 @@
<snmp4j-version>3.13.2</snmp4j-version>
<solr-version>10.0.0</solr-version>
<splunk-version>1.9.5_1</splunk-version>
- <spring-ai-version>2.0.2</spring-ai-version>
+ <spring-ai-version>2.1.0</spring-ai-version>
<spring-cloud-config-version>5.0.6</spring-cloud-config-version>
<spring-batch-version>6.0.6</spring-batch-version>
<spring-boot-version>4.1.2</spring-boot-version>