You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "zbendhiba (via GitHub)" <gi...@apache.org> on 2024/07/24 13:49:31 UTC

[PR] CAMEL-20935: introduce Camel LangChain4j Web Search component [camel]

zbendhiba opened a new pull request, #14928:
URL: https://github.com/apache/camel/pull/14928

   # Description
   
   <!--
   - Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
   -->
   
   # Target
   
   - [ ] I checked that the commit is targeting the correct branch (note that Camel 3 uses `camel-3.x`, whereas Camel 4 uses the `main` branch)
   
   # Tracking
   - [ ] If this is a large change, bug fix, or code improvement, I checked there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for the change (usually before you start working on it).
   
   <!--
   # *Note*: trivial changes like, typos, minor documentation fixes and other small items do not require a JIRA issue. In this case your pull request should address just this issue, without pulling in other changes.
   -->
   
   # Apache Camel coding standards and style
   
   - [ ] I checked that each commit in the pull request has a meaningful subject line and body.
   
   <!--
   If you're unsure, you can format the pull request title like `[CAMEL-XXX] Fixes bug in camel-file component`, where you replace `CAMEL-XXX` with the appropriate JIRA issue.
   -->
   
   - [ ] I have run `mvn clean install -DskipTests` locally and I have committed all auto-generated changes
   
   <!--
   You can run the aforementioned command in your module so that the build auto-formats your code. This will also be verified as part of the checks and your PR may be rejected if if there are uncommited changes after running `mvn clean install -DskipTests`.
   
   You can learn more about the contribution guidelines at https://github.com/apache/camel/blob/main/CONTRIBUTING.md
   -->
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-20935: introduce Camel LangChain4j Web Search component [camel]

Posted by "zbendhiba (via GitHub)" <gi...@apache.org>.
zbendhiba commented on code in PR #14928:
URL: https://github.com/apache/camel/pull/14928#discussion_r1691257303


##########
components/camel-ai/camel-langchain4j-web-search/src/main/docs/langchain4j-web-search-component.adoc:
##########
@@ -0,0 +1,159 @@
+= LangChain4j Web Search Component
+:doctitle: LangChain4j Web Search
+:shortname: langchain4j-web-search
+:artifactid: camel-langchain4j-web-search
+:description: LangChain4j Web Search Engine
+:since: 4.8
+:supportlevel: Preview
+:tabs-sync-option:
+:component-header: Only producer is supported
+//Manually maintained attributes
+:group: AI
+:camel-spring-boot-name: langchain4j-web-search
+
+*Since Camel {since}*
+
+*{component-header}*
+
+The LangChain4j Web Search component provides support to perform a web search using the https://docs.langchain4j.dev/[LangChain4j] Web Search Engines.
+
+Maven users will need to add the following dependency to their `pom.xml`
+for this component:
+
+[source,xml]
+----
+<dependency>
+    <groupId>org.apache.camel</groupId>
+    <artifactId>camel-langchain4j-web-search</artifactId>
+    <version>x.x.x</version>
+    <!-- use the same version as your Camel core version -->
+</dependency>
+----
+
+
+== URI format
+
+[source]
+----
+langchain4j-web-search:searchId[?options]
+----
+
+Where *searchId* can be any string to uniquely identify the endpoint
+
+
+// component-configure options: START
+
+// component-configure options: END
+
+// component options: START
+include::partial$component-configure-options.adoc[]
+include::partial$component-endpoint-options.adoc[]
+// component options: END
+
+// endpoint options: START
+
+// endpoint options: END
+
+// component headers: START
+include::partial$component-endpoint-headers.adoc[]
+// component headers: END
+
+include::spring-boot:partial$starter.adoc[]
+
+
+== Using a specific Web Search Engine
+The Camel LangChain4j web search component provides an abstraction for interacting with various types of Web Search Engines supported by https://github.com/langchain4j/langchain4j[LangChain4j].
+
+To integrate with a specific Web Search Engine, users should follow these steps:
+
+=== Example of integrating with Tavily
+Add the dependency for LangChain4j Tavily Web Search Engine support :
+
+[source,xml]
+----
+<dependency>

Review Comment:
   I improved the doc. Let me know if that looks good to you



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-20935: introduce Camel LangChain4j Web Search component [camel]

Posted by "apupier (via GitHub)" <gi...@apache.org>.
apupier commented on code in PR #14928:
URL: https://github.com/apache/camel/pull/14928#discussion_r1689886477


##########
components/camel-ai/camel-langchain4j-web-search/src/main/java/org/apache/camel/component/langchain4j/web/search/LangChain4jWebSearchConfiguration.java:
##########
@@ -0,0 +1,199 @@
+/*
+ * 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.langchain4j.web.search;
+
+import java.util.Map;
+
+import dev.langchain4j.web.search.WebSearchEngine;
+import dev.langchain4j.web.search.WebSearchRequest;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.spi.Configurer;
+import org.apache.camel.spi.Metadata;
+import org.apache.camel.spi.UriParam;
+import org.apache.camel.spi.UriParams;
+
+@Configurer
+@UriParams
+public class LangChain4jWebSearchConfiguration implements Cloneable {
+
+    @Metadata(required = true, autowired = true)
+    @UriParam
+    private WebSearchEngine webSearchEngine;
+
+    @Metadata(required = true, defaultValue = "CONTENT")
+    @UriParam
+    private LangChain4jWebSearchResultType resultType = LangChain4jWebSearchResultType.CONTENT;
+
+    @Metadata(required = true, defaultValue = "1")
+    @UriParam
+    private Integer maxResults = 1;
+    @UriParam
+    private String language;
+    @UriParam
+    private String geoLocation;
+    @UriParam
+    private Integer startPage;
+    @UriParam
+    private Integer startIndex;
+    @UriParam
+    private Boolean safeSearch;
+    @UriParam
+    @Metadata(autowired = true)
+    private Map<String, Object> additionalParams;
+
+    @UriParam(label = "advanced")
+    @Metadata(autowired = true)
+    private WebSearchRequest webSearchRequest;
+
+    public WebSearchEngine getWebSearchEngine() {
+        return webSearchEngine;
+    }
+
+    /**
+     * The {@link WebSearchEngine} engine to use. This is mandatory. Use one of the implementations from Langchain4j web
+     * search engines.
+     */
+    public void setWebSearchEngine(WebSearchEngine webSearchEngine) {
+        this.webSearchEngine = webSearchEngine;
+    }
+
+    public LangChain4jWebSearchResultType getResultType() {
+        return resultType;
+    }
+
+    /**
+     * The {@link #resultType} is the result type of the request. Valid values are
+     * LANGCHAIN4J_WEB_SEARCH_ORGANIC_RESULT, CONTENT, or SNIPPET. CONTENT is the default value; it will return a list
+     * of String . You can also specify to return either the Langchain4j Web Search Organic Result object (using
+     * `LANGCHAIN4J_WEB_SEARCH_ORGNAIC_RESULT`) or snippet (using `SNIPPET`) for each result. If {@link #maxResults} is

Review Comment:
   typo LANGCHAIN4J_WEB_SEARCH_ORGNAIC_RESULT --> LANGCHAIN4J_WEB_SEARCH_ORGANIC_RESULT



##########
components/camel-ai/camel-langchain4j-web-search/pom.xml:
##########
@@ -0,0 +1,87 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <artifactId>camel-ai-parent</artifactId>
+    <groupId>org.apache.camel</groupId>
+    <version>4.8.0-SNAPSHOT</version>
+  </parent>
+
+  <artifactId>camel-langchain4j-web-search</artifactId>
+  <packaging>jar</packaging>
+  <name>Camel :: LangChain4j :: Web Search</name>

Review Comment:
   Other modules are using the AI in the "path" https://github.com/apache/camel/blob/cf19909459848ffd2b0ebb9d5a9221cb99e53c85/components/camel-ai/camel-djl/pom.xml#L31



##########
components/camel-ai/camel-langchain4j-web-search/src/main/java/org/apache/camel/component/langchain4j/web/search/LangChain4jWebSearchConfiguration.java:
##########
@@ -0,0 +1,199 @@
+/*
+ * 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.langchain4j.web.search;
+
+import java.util.Map;
+
+import dev.langchain4j.web.search.WebSearchEngine;
+import dev.langchain4j.web.search.WebSearchRequest;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.spi.Configurer;
+import org.apache.camel.spi.Metadata;
+import org.apache.camel.spi.UriParam;
+import org.apache.camel.spi.UriParams;
+
+@Configurer
+@UriParams
+public class LangChain4jWebSearchConfiguration implements Cloneable {
+
+    @Metadata(required = true, autowired = true)
+    @UriParam
+    private WebSearchEngine webSearchEngine;
+
+    @Metadata(required = true, defaultValue = "CONTENT")
+    @UriParam
+    private LangChain4jWebSearchResultType resultType = LangChain4jWebSearchResultType.CONTENT;
+
+    @Metadata(required = true, defaultValue = "1")
+    @UriParam
+    private Integer maxResults = 1;
+    @UriParam
+    private String language;
+    @UriParam
+    private String geoLocation;
+    @UriParam
+    private Integer startPage;
+    @UriParam
+    private Integer startIndex;
+    @UriParam
+    private Boolean safeSearch;
+    @UriParam
+    @Metadata(autowired = true)
+    private Map<String, Object> additionalParams;
+
+    @UriParam(label = "advanced")
+    @Metadata(autowired = true)
+    private WebSearchRequest webSearchRequest;
+
+    public WebSearchEngine getWebSearchEngine() {
+        return webSearchEngine;
+    }
+
+    /**
+     * The {@link WebSearchEngine} engine to use. This is mandatory. Use one of the implementations from Langchain4j web
+     * search engines.
+     */
+    public void setWebSearchEngine(WebSearchEngine webSearchEngine) {
+        this.webSearchEngine = webSearchEngine;
+    }
+
+    public LangChain4jWebSearchResultType getResultType() {
+        return resultType;
+    }
+
+    /**
+     * The {@link #resultType} is the result type of the request. Valid values are
+     * LANGCHAIN4J_WEB_SEARCH_ORGANIC_RESULT, CONTENT, or SNIPPET. CONTENT is the default value; it will return a list
+     * of String . You can also specify to return either the Langchain4j Web Search Organic Result object (using
+     * `LANGCHAIN4J_WEB_SEARCH_ORGNAIC_RESULT`) or snippet (using `SNIPPET`) for each result. If {@link #maxResults} is
+     * equal to 1, the response will be a single object instead of a list.
+     */
+    public void setResultType(LangChain4jWebSearchResultType resultType) {
+        this.resultType = resultType;
+    }
+
+    /**
+     * The {@link #maxResults} is the expected number of results to be found if the search request were made. Each
+     * search engine may have a different limit for the maximum number of results that can be returned.
+     *
+     * @return
+     */
+    public Integer getMaxResults() {
+        return maxResults;
+    }
+
+    public void setMaxResults(Integer maxResults) {
+        this.maxResults = maxResults;
+    }
+
+    /**
+     * The {@link #language} is the desired language for search results is a string that indicates that the search
+     * client desires search results in the specified language. Each search engine may have a different set of supported
+     * languages.
+     *
+     * @return
+     */
+    public String getLanguage() {
+        return language;
+    }
+
+    public void setLanguage(String language) {
+        this.language = language;
+    }
+
+    public String getGeoLocation() {
+        return geoLocation;
+    }
+
+    /**
+     * The {@link #geoLocation} is the desired geolocation for search results is a string that indicates that the search
+     * client desires search results in the specified geolocation. Each search engine may have a different set of
+     * supported geolocations.
+     */
+    public void setGeoLocation(String geoLocation) {
+        this.geoLocation = geoLocation;
+    }
+
+    public Integer getStartPage() {
+        return startPage;
+    }
+
+    /**
+     * The {@link #startPage} is the start page number for search results is the page number of the set of search
+     * results desired by the search user
+     */
+    public void setStartPage(Integer startPage) {
+        this.startPage = startPage;
+    }
+
+    public Integer getStartIndex() {
+        return startIndex;
+    }
+
+    /**
+     * The {@link #startIndex} is the start index for search results is the index of the first search result desired by
+     * the search user. Each search engine may have a different set of supported start indexes in combination with the
+     * start page number.
+     */
+    public void setStartIndex(Integer startIndex) {
+        this.startIndex = startIndex;
+    }
+
+    public Boolean getSafeSearch() {
+        return safeSearch;
+    }
+
+    /**
+     * The {@link #safeSearch} is the safe search flag is a boolean that indicates that the search client desires search
+     * results with safe search enabled or disabled.
+     */
+    public void setSafeSearch(Boolean safeSearch) {
+        this.safeSearch = safeSearch;
+    }
+
+    public Map<String, Object> getAdditionalParams() {
+        return additionalParams;
+    }
+
+    /**
+     * The {@link #additionalParams} is the additional parameters for the search request are a map of key-value pairs
+     * that represent additional parameters for the search request. It's a way to be flex and add custom param for each

Review Comment:
   I think we should use `flexible` which is an adjective instead of `flex` which is a verb



##########
components/camel-ai/camel-langchain4j-web-search/src/main/java/org/apache/camel/component/langchain4j/web/search/LangChain4jWebSearchConfiguration.java:
##########
@@ -0,0 +1,199 @@
+/*
+ * 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.langchain4j.web.search;
+
+import java.util.Map;
+
+import dev.langchain4j.web.search.WebSearchEngine;
+import dev.langchain4j.web.search.WebSearchRequest;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.spi.Configurer;
+import org.apache.camel.spi.Metadata;
+import org.apache.camel.spi.UriParam;
+import org.apache.camel.spi.UriParams;
+
+@Configurer
+@UriParams
+public class LangChain4jWebSearchConfiguration implements Cloneable {
+
+    @Metadata(required = true, autowired = true)
+    @UriParam
+    private WebSearchEngine webSearchEngine;
+
+    @Metadata(required = true, defaultValue = "CONTENT")
+    @UriParam
+    private LangChain4jWebSearchResultType resultType = LangChain4jWebSearchResultType.CONTENT;
+
+    @Metadata(required = true, defaultValue = "1")
+    @UriParam
+    private Integer maxResults = 1;
+    @UriParam
+    private String language;
+    @UriParam
+    private String geoLocation;
+    @UriParam
+    private Integer startPage;
+    @UriParam
+    private Integer startIndex;
+    @UriParam
+    private Boolean safeSearch;
+    @UriParam
+    @Metadata(autowired = true)
+    private Map<String, Object> additionalParams;
+
+    @UriParam(label = "advanced")
+    @Metadata(autowired = true)
+    private WebSearchRequest webSearchRequest;
+
+    public WebSearchEngine getWebSearchEngine() {
+        return webSearchEngine;
+    }
+
+    /**
+     * The {@link WebSearchEngine} engine to use. This is mandatory. Use one of the implementations from Langchain4j web
+     * search engines.
+     */
+    public void setWebSearchEngine(WebSearchEngine webSearchEngine) {
+        this.webSearchEngine = webSearchEngine;
+    }
+
+    public LangChain4jWebSearchResultType getResultType() {
+        return resultType;
+    }
+
+    /**
+     * The {@link #resultType} is the result type of the request. Valid values are
+     * LANGCHAIN4J_WEB_SEARCH_ORGANIC_RESULT, CONTENT, or SNIPPET. CONTENT is the default value; it will return a list
+     * of String . You can also specify to return either the Langchain4j Web Search Organic Result object (using
+     * `LANGCHAIN4J_WEB_SEARCH_ORGNAIC_RESULT`) or snippet (using `SNIPPET`) for each result. If {@link #maxResults} is
+     * equal to 1, the response will be a single object instead of a list.
+     */
+    public void setResultType(LangChain4jWebSearchResultType resultType) {
+        this.resultType = resultType;
+    }
+
+    /**
+     * The {@link #maxResults} is the expected number of results to be found if the search request were made. Each
+     * search engine may have a different limit for the maximum number of results that can be returned.
+     *
+     * @return
+     */
+    public Integer getMaxResults() {
+        return maxResults;
+    }
+
+    public void setMaxResults(Integer maxResults) {
+        this.maxResults = maxResults;
+    }
+
+    /**
+     * The {@link #language} is the desired language for search results is a string that indicates that the search
+     * client desires search results in the specified language. Each search engine may have a different set of supported
+     * languages.

Review Comment:
   The sentence is quite long. I'm not sure how to split the sentence.
   
   Would it be:
   
   `The {@link #language} is the desired language for search results. It is a string that indicates that the search client desires search results in the specified language. Each search engine may have a different set of supported languages.`
   
   
   Edit: in fact, several are based on the same structure rigth after and I do not understand either



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-20935: introduce Camel LangChain4j Web Search component [camel]

Posted by "zbendhiba (via GitHub)" <gi...@apache.org>.
zbendhiba commented on PR #14928:
URL: https://github.com/apache/camel/pull/14928#issuecomment-2250058290

   Many thanks @oscerd @orpiske @apupier  for the review and constructive feedback.
   
   I pushed improvements. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-20935: introduce Camel LangChain4j Web Search component [camel]

Posted by "zbendhiba (via GitHub)" <gi...@apache.org>.
zbendhiba commented on code in PR #14928:
URL: https://github.com/apache/camel/pull/14928#discussion_r1691193560


##########
components/camel-ai/camel-langchain4j-web-search/src/test/java/org/apache/camel/component/langchain4j/web/search/LangChain4jGoogleWebSearchEngineIT.java:
##########
@@ -0,0 +1,87 @@
+/*
+ * 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.langchain4j.web.search;
+
+import java.util.List;
+
+import dev.langchain4j.web.search.WebSearchEngine;
+import dev.langchain4j.web.search.google.customsearch.GoogleCustomWebSearchEngine;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
+
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+// Instruction to generate one https://developers.google.com/custom-search/v1/overview
+@EnabledIfEnvironmentVariable(named = "GOOGLE_API_KEY", matches = ".*")
+// Instructions to create a Google search engine https://developers.google.com/custom-search/docs/tutorial/creatingcse
+@EnabledIfEnvironmentVariable(named = "GOOGLE_SEARCH_ENGINE_ID", matches = ".*")
+public class LangChain4jGoogleWebSearchEngineIT extends CamelTestSupport {
+    public static final String WEB_SEARCH_URI = "langchain4j-web-search:googleTest";
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext context = super.createCamelContext();
+
+        WebSearchEngine googleSearchEngine = GoogleCustomWebSearchEngine.builder()
+                .apiKey(System.getenv("GOOGLE_API_KEY"))
+                .csi(System.getenv("GOOGLE_SEARCH_ENGINE_ID"))
+                .logRequests(true)
+                .logResponses(true)
+                .build();
+
+        context.getRegistry().bind("web-search-engine", googleSearchEngine);
+
+        return context;
+    }

Review Comment:
   The BindToRegistry annotation is cool 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-20935: introduce Camel LangChain4j Web Search component [camel]

Posted by "zbendhiba (via GitHub)" <gi...@apache.org>.
zbendhiba merged PR #14928:
URL: https://github.com/apache/camel/pull/14928


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-20935: introduce Camel LangChain4j Web Search component [camel]

Posted by "zbendhiba (via GitHub)" <gi...@apache.org>.
zbendhiba commented on code in PR #14928:
URL: https://github.com/apache/camel/pull/14928#discussion_r1691258601


##########
components/camel-ai/camel-langchain4j-web-search/src/test/java/org/apache/camel/component/langchain4j/web/search/LangChain4jGoogleWebSearchEngineIT.java:
##########
@@ -0,0 +1,87 @@
+/*
+ * 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.langchain4j.web.search;
+
+import java.util.List;
+
+import dev.langchain4j.web.search.WebSearchEngine;
+import dev.langchain4j.web.search.google.customsearch.GoogleCustomWebSearchEngine;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
+
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+// Instruction to generate one https://developers.google.com/custom-search/v1/overview
+@EnabledIfEnvironmentVariable(named = "GOOGLE_API_KEY", matches = ".*")
+// Instructions to create a Google search engine https://developers.google.com/custom-search/docs/tutorial/creatingcse
+@EnabledIfEnvironmentVariable(named = "GOOGLE_SEARCH_ENGINE_ID", matches = ".*")
+public class LangChain4jGoogleWebSearchEngineIT extends CamelTestSupport {
+    public static final String WEB_SEARCH_URI = "langchain4j-web-search:googleTest";
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext context = super.createCamelContext();
+
+        WebSearchEngine googleSearchEngine = GoogleCustomWebSearchEngine.builder()
+                .apiKey(System.getenv("GOOGLE_API_KEY"))
+                .csi(System.getenv("GOOGLE_SEARCH_ENGINE_ID"))
+                .logRequests(true)
+                .logResponses(true)
+                .build();
+
+        context.getRegistry().bind("web-search-engine", googleSearchEngine);
+
+        return context;
+    }

Review Comment:
   I improved that part. Let me know if that looks good to you



##########
components/camel-ai/camel-langchain4j-web-search/src/test/java/org/apache/camel/component/langchain4j/web/search/LangChain4jGoogleWebSearchEngineIT.java:
##########
@@ -0,0 +1,87 @@
+/*
+ * 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.langchain4j.web.search;
+
+import java.util.List;
+
+import dev.langchain4j.web.search.WebSearchEngine;
+import dev.langchain4j.web.search.google.customsearch.GoogleCustomWebSearchEngine;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
+
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+// Instruction to generate one https://developers.google.com/custom-search/v1/overview
+@EnabledIfEnvironmentVariable(named = "GOOGLE_API_KEY", matches = ".*")
+// Instructions to create a Google search engine https://developers.google.com/custom-search/docs/tutorial/creatingcse
+@EnabledIfEnvironmentVariable(named = "GOOGLE_SEARCH_ENGINE_ID", matches = ".*")
+public class LangChain4jGoogleWebSearchEngineIT extends CamelTestSupport {
+    public static final String WEB_SEARCH_URI = "langchain4j-web-search:googleTest";
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext context = super.createCamelContext();
+
+        WebSearchEngine googleSearchEngine = GoogleCustomWebSearchEngine.builder()
+                .apiKey(System.getenv("GOOGLE_API_KEY"))
+                .csi(System.getenv("GOOGLE_SEARCH_ENGINE_ID"))
+                .logRequests(true)
+                .logResponses(true)
+                .build();
+
+        context.getRegistry().bind("web-search-engine", googleSearchEngine);
+
+        return context;
+    }
+
+    @Test
+    void testSimpleSearch() {
+
+        String uri = String.format("%s?resultType=%s", WEB_SEARCH_URI, LangChain4jWebSearchResultType.SNIPPET);
+        Exchange result = fluentTemplate.to(uri)
+                .withBody("Who won the European Cup in 2024?")
+                .request(Exchange.class);
+
+        assertNotNull(result);

Review Comment:
   I improved that part. Let me know if that looks good to you



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-20935: introduce Camel LangChain4j Web Search component [camel]

Posted by "zbendhiba (via GitHub)" <gi...@apache.org>.
zbendhiba commented on code in PR #14928:
URL: https://github.com/apache/camel/pull/14928#discussion_r1690015469


##########
components/camel-ai/camel-langchain4j-web-search/src/test/java/org/apache/camel/component/langchain4j/web/search/LangChain4jGoogleWebSearchEngineIT.java:
##########
@@ -0,0 +1,87 @@
+/*
+ * 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.langchain4j.web.search;
+
+import java.util.List;
+
+import dev.langchain4j.web.search.WebSearchEngine;
+import dev.langchain4j.web.search.google.customsearch.GoogleCustomWebSearchEngine;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
+
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+// Instruction to generate one https://developers.google.com/custom-search/v1/overview
+@EnabledIfEnvironmentVariable(named = "GOOGLE_API_KEY", matches = ".*")
+// Instructions to create a Google search engine https://developers.google.com/custom-search/docs/tutorial/creatingcse
+@EnabledIfEnvironmentVariable(named = "GOOGLE_SEARCH_ENGINE_ID", matches = ".*")
+public class LangChain4jGoogleWebSearchEngineIT extends CamelTestSupport {
+    public static final String WEB_SEARCH_URI = "langchain4j-web-search:googleTest";
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext context = super.createCamelContext();
+
+        WebSearchEngine googleSearchEngine = GoogleCustomWebSearchEngine.builder()
+                .apiKey(System.getenv("GOOGLE_API_KEY"))
+                .csi(System.getenv("GOOGLE_SEARCH_ENGINE_ID"))
+                .logRequests(true)
+                .logResponses(true)
+                .build();
+
+        context.getRegistry().bind("web-search-engine", googleSearchEngine);
+
+        return context;
+    }

Review Comment:
   oh thanks 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-20935: introduce Camel LangChain4j Web Search component [camel]

Posted by "zbendhiba (via GitHub)" <gi...@apache.org>.
zbendhiba commented on code in PR #14928:
URL: https://github.com/apache/camel/pull/14928#discussion_r1691256526


##########
components/camel-ai/camel-langchain4j-web-search/src/main/java/org/apache/camel/component/langchain4j/web/search/LangChain4jWebSearchConfiguration.java:
##########
@@ -0,0 +1,199 @@
+/*
+ * 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.langchain4j.web.search;
+
+import java.util.Map;
+
+import dev.langchain4j.web.search.WebSearchEngine;
+import dev.langchain4j.web.search.WebSearchRequest;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.spi.Configurer;
+import org.apache.camel.spi.Metadata;
+import org.apache.camel.spi.UriParam;
+import org.apache.camel.spi.UriParams;
+
+@Configurer
+@UriParams
+public class LangChain4jWebSearchConfiguration implements Cloneable {
+
+    @Metadata(required = true, autowired = true)
+    @UriParam
+    private WebSearchEngine webSearchEngine;
+
+    @Metadata(required = true, defaultValue = "CONTENT")
+    @UriParam
+    private LangChain4jWebSearchResultType resultType = LangChain4jWebSearchResultType.CONTENT;
+
+    @Metadata(required = true, defaultValue = "1")
+    @UriParam
+    private Integer maxResults = 1;
+    @UriParam
+    private String language;
+    @UriParam
+    private String geoLocation;
+    @UriParam
+    private Integer startPage;
+    @UriParam
+    private Integer startIndex;
+    @UriParam
+    private Boolean safeSearch;
+    @UriParam
+    @Metadata(autowired = true)
+    private Map<String, Object> additionalParams;
+
+    @UriParam(label = "advanced")
+    @Metadata(autowired = true)
+    private WebSearchRequest webSearchRequest;
+
+    public WebSearchEngine getWebSearchEngine() {
+        return webSearchEngine;
+    }
+
+    /**
+     * The {@link WebSearchEngine} engine to use. This is mandatory. Use one of the implementations from Langchain4j web
+     * search engines.
+     */
+    public void setWebSearchEngine(WebSearchEngine webSearchEngine) {
+        this.webSearchEngine = webSearchEngine;
+    }
+
+    public LangChain4jWebSearchResultType getResultType() {
+        return resultType;
+    }
+
+    /**
+     * The {@link #resultType} is the result type of the request. Valid values are
+     * LANGCHAIN4J_WEB_SEARCH_ORGANIC_RESULT, CONTENT, or SNIPPET. CONTENT is the default value; it will return a list
+     * of String . You can also specify to return either the Langchain4j Web Search Organic Result object (using
+     * `LANGCHAIN4J_WEB_SEARCH_ORGNAIC_RESULT`) or snippet (using `SNIPPET`) for each result. If {@link #maxResults} is
+     * equal to 1, the response will be a single object instead of a list.
+     */
+    public void setResultType(LangChain4jWebSearchResultType resultType) {
+        this.resultType = resultType;
+    }
+
+    /**
+     * The {@link #maxResults} is the expected number of results to be found if the search request were made. Each
+     * search engine may have a different limit for the maximum number of results that can be returned.
+     *
+     * @return
+     */
+    public Integer getMaxResults() {
+        return maxResults;
+    }
+
+    public void setMaxResults(Integer maxResults) {
+        this.maxResults = maxResults;
+    }
+
+    /**
+     * The {@link #language} is the desired language for search results is a string that indicates that the search
+     * client desires search results in the specified language. Each search engine may have a different set of supported
+     * languages.
+     *
+     * @return
+     */
+    public String getLanguage() {
+        return language;
+    }
+
+    public void setLanguage(String language) {
+        this.language = language;
+    }
+
+    public String getGeoLocation() {
+        return geoLocation;
+    }
+
+    /**
+     * The {@link #geoLocation} is the desired geolocation for search results is a string that indicates that the search
+     * client desires search results in the specified geolocation. Each search engine may have a different set of
+     * supported geolocations.
+     */
+    public void setGeoLocation(String geoLocation) {
+        this.geoLocation = geoLocation;
+    }
+
+    public Integer getStartPage() {
+        return startPage;
+    }
+
+    /**
+     * The {@link #startPage} is the start page number for search results is the page number of the set of search
+     * results desired by the search user
+     */
+    public void setStartPage(Integer startPage) {
+        this.startPage = startPage;
+    }
+
+    public Integer getStartIndex() {
+        return startIndex;
+    }
+
+    /**
+     * The {@link #startIndex} is the start index for search results is the index of the first search result desired by
+     * the search user. Each search engine may have a different set of supported start indexes in combination with the
+     * start page number.
+     */
+    public void setStartIndex(Integer startIndex) {
+        this.startIndex = startIndex;
+    }
+
+    public Boolean getSafeSearch() {
+        return safeSearch;
+    }
+
+    /**
+     * The {@link #safeSearch} is the safe search flag is a boolean that indicates that the search client desires search
+     * results with safe search enabled or disabled.
+     */
+    public void setSafeSearch(Boolean safeSearch) {
+        this.safeSearch = safeSearch;
+    }
+
+    public Map<String, Object> getAdditionalParams() {
+        return additionalParams;
+    }
+
+    /**
+     * The {@link #additionalParams} is the additional parameters for the search request are a map of key-value pairs
+     * that represent additional parameters for the search request. It's a way to be flex and add custom param for each

Review Comment:
   My bad, I copied text from Langchain4j javadoc. I had improved the text a bit. Let me know if that looks good to you.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-20935: introduce Camel LangChain4j Web Search component [camel]

Posted by "orpiske (via GitHub)" <gi...@apache.org>.
orpiske commented on code in PR #14928:
URL: https://github.com/apache/camel/pull/14928#discussion_r1689866714


##########
components/camel-ai/camel-langchain4j-web-search/pom.xml:
##########
@@ -0,0 +1,87 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <artifactId>camel-ai-parent</artifactId>
+    <groupId>org.apache.camel</groupId>
+    <version>4.8.0-SNAPSHOT</version>
+  </parent>
+
+  <artifactId>camel-langchain4j-web-search</artifactId>
+  <packaging>jar</packaging>
+  <name>Camel :: LangChain4j :: Web Search</name>

Review Comment:
   Cosmetic stuff: we recently had a pr that changed the name of all `ai` components to `Camel :: AI :: stuff`



##########
components/camel-ai/camel-langchain4j-web-search/src/main/java/org/apache/camel/component/langchain4j/web/search/LangChain4jWebSearchProducer.java:
##########
@@ -0,0 +1,104 @@
+/*
+ * 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.langchain4j.web.search;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import dev.langchain4j.web.search.WebSearchEngine;
+import dev.langchain4j.web.search.WebSearchOrganicResult;
+import dev.langchain4j.web.search.WebSearchRequest;
+import dev.langchain4j.web.search.WebSearchResults;
+import org.apache.camel.Exchange;
+import org.apache.camel.support.DefaultProducer;
+import org.apache.camel.util.ObjectHelper;
+
+public class LangChain4jWebSearchProducer extends DefaultProducer {
+
+    private WebSearchEngine webSearchEngine;
+
+    public LangChain4jWebSearchProducer(LangChain4jWebSearchEndpoint endpoint) {
+        super(endpoint);
+    }
+
+    @Override
+    public LangChain4jWebSearchEndpoint getEndpoint() {
+        return (LangChain4jWebSearchEndpoint) super.getEndpoint();
+    }
+
+    @Override
+    public void process(Exchange exchange) throws Exception {
+        // check if there's a custom WebSearchRequest -- advanced
+        WebSearchRequest webSearchRequest = getEndpoint().getConfiguration().getWebSearchRequest();
+
+        // build a Web Search Request
+        if (webSearchRequest == null) {
+            final String searchTerms = exchange.getMessage().getMandatoryBody(String.class);
+            webSearchRequest = WebSearchRequest.builder()
+                    .searchTerms(searchTerms)
+                    .maxResults(getEndpoint().getConfiguration().getMaxResults())
+                    .language(getEndpoint().getConfiguration().getLanguage())
+                    .geoLocation(getEndpoint().getConfiguration().getGeoLocation())
+                    .startPage(getEndpoint().getConfiguration().getStartPage())
+                    .startIndex(getEndpoint().getConfiguration().getStartIndex())
+                    .additionalParams(getEndpoint().getConfiguration().getAdditionalParams())
+                    .build();
+        }
+
+        // perform the request
+        WebSearchResults webSearchResults = webSearchEngine.search(webSearchRequest);
+
+        // exrtact the list
+        List<WebSearchOrganicResult> resultList = webSearchResults.results();
+
+        // compute the response
+        computeResponse(resultList, exchange, webSearchRequest.maxResults());
+    }
+
+    @Override
+    protected void doStart() throws Exception {
+        super.doStart();
+        this.webSearchEngine = getEndpoint().getConfiguration().getWebSearchEngine();
+        ObjectHelper.notNull(webSearchEngine, "webSearchEngine");
+    }
+
+    /**
+     * Computes the response of the web search based on the configuration and input results.
+     *
+     * @param webSearchOrganicResults the list of WebSearchOrganicResult objects to process
+     * @param exchange                the Apache Camel Exchange object
+     * @param maxResults              maxResults
+     */
+    private void computeResponse(List<WebSearchOrganicResult> webSearchOrganicResults, Exchange exchange, Integer maxResults) {
+        // return a single object as a response
+        if (maxResults == 1) {
+            switch (getEndpoint().getConfiguration().getResultType()) {
+                case LANGCHAIN4J_WEB_SEARCH_ORGNAIC_RESULT -> exchange.getIn().setBody(webSearchOrganicResults.get(0));

Review Comment:
   I think there's a typo here in "organic"



##########
components/camel-ai/camel-langchain4j-web-search/src/test/java/org/apache/camel/component/langchain4j/web/search/LangChain4jGoogleWebSearchEngineIT.java:
##########
@@ -0,0 +1,87 @@
+/*
+ * 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.langchain4j.web.search;
+
+import java.util.List;
+
+import dev.langchain4j.web.search.WebSearchEngine;
+import dev.langchain4j.web.search.google.customsearch.GoogleCustomWebSearchEngine;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
+
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+// Instruction to generate one https://developers.google.com/custom-search/v1/overview
+@EnabledIfEnvironmentVariable(named = "GOOGLE_API_KEY", matches = ".*")
+// Instructions to create a Google search engine https://developers.google.com/custom-search/docs/tutorial/creatingcse
+@EnabledIfEnvironmentVariable(named = "GOOGLE_SEARCH_ENGINE_ID", matches = ".*")
+public class LangChain4jGoogleWebSearchEngineIT extends CamelTestSupport {
+    public static final String WEB_SEARCH_URI = "langchain4j-web-search:googleTest";
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext context = super.createCamelContext();
+
+        WebSearchEngine googleSearchEngine = GoogleCustomWebSearchEngine.builder()
+                .apiKey(System.getenv("GOOGLE_API_KEY"))
+                .csi(System.getenv("GOOGLE_SEARCH_ENGINE_ID"))
+                .logRequests(true)
+                .logResponses(true)
+                .build();
+
+        context.getRegistry().bind("web-search-engine", googleSearchEngine);
+
+        return context;
+    }
+
+    @Test
+    void testSimpleSearch() {
+
+        String uri = String.format("%s?resultType=%s", WEB_SEARCH_URI, LangChain4jWebSearchResultType.SNIPPET);
+        Exchange result = fluentTemplate.to(uri)
+                .withBody("Who won the European Cup in 2024?")
+                .request(Exchange.class);
+
+        assertNotNull(result);

Review Comment:
   Please add a message for the assertion (this and others)



##########
components/camel-ai/camel-langchain4j-web-search/src/test/java/org/apache/camel/component/langchain4j/web/search/LangChain4jGoogleWebSearchEngineIT.java:
##########
@@ -0,0 +1,87 @@
+/*
+ * 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.langchain4j.web.search;
+
+import java.util.List;
+
+import dev.langchain4j.web.search.WebSearchEngine;
+import dev.langchain4j.web.search.google.customsearch.GoogleCustomWebSearchEngine;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
+
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+// Instruction to generate one https://developers.google.com/custom-search/v1/overview
+@EnabledIfEnvironmentVariable(named = "GOOGLE_API_KEY", matches = ".*")
+// Instructions to create a Google search engine https://developers.google.com/custom-search/docs/tutorial/creatingcse
+@EnabledIfEnvironmentVariable(named = "GOOGLE_SEARCH_ENGINE_ID", matches = ".*")
+public class LangChain4jGoogleWebSearchEngineIT extends CamelTestSupport {
+    public static final String WEB_SEARCH_URI = "langchain4j-web-search:googleTest";
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext context = super.createCamelContext();
+
+        WebSearchEngine googleSearchEngine = GoogleCustomWebSearchEngine.builder()
+                .apiKey(System.getenv("GOOGLE_API_KEY"))
+                .csi(System.getenv("GOOGLE_SEARCH_ENGINE_ID"))
+                .logRequests(true)
+                .logResponses(true)
+                .build();
+
+        context.getRegistry().bind("web-search-engine", googleSearchEngine);
+
+        return context;
+    }

Review Comment:
   This API is becoming more restricted with 4.8 and, in the future, 4.9. I'd suggest using 
   
   `protected void bindToRegistry(Registry registry) throws Exception {`
   
   instead.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-20935: introduce Camel LangChain4j Web Search component [camel]

Posted by "oscerd (via GitHub)" <gi...@apache.org>.
oscerd commented on code in PR #14928:
URL: https://github.com/apache/camel/pull/14928#discussion_r1689953858


##########
components/camel-ai/camel-langchain4j-web-search/src/main/java/org/apache/camel/component/langchain4j/web/search/LangChain4jWebSearchProducer.java:
##########
@@ -0,0 +1,104 @@
+/*
+ * 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.langchain4j.web.search;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import dev.langchain4j.web.search.WebSearchEngine;
+import dev.langchain4j.web.search.WebSearchOrganicResult;
+import dev.langchain4j.web.search.WebSearchRequest;
+import dev.langchain4j.web.search.WebSearchResults;
+import org.apache.camel.Exchange;
+import org.apache.camel.support.DefaultProducer;
+import org.apache.camel.util.ObjectHelper;
+
+public class LangChain4jWebSearchProducer extends DefaultProducer {
+
+    private WebSearchEngine webSearchEngine;
+
+    public LangChain4jWebSearchProducer(LangChain4jWebSearchEndpoint endpoint) {
+        super(endpoint);
+    }
+
+    @Override
+    public LangChain4jWebSearchEndpoint getEndpoint() {
+        return (LangChain4jWebSearchEndpoint) super.getEndpoint();
+    }
+
+    @Override
+    public void process(Exchange exchange) throws Exception {
+        // check if there's a custom WebSearchRequest -- advanced
+        WebSearchRequest webSearchRequest = getEndpoint().getConfiguration().getWebSearchRequest();
+
+        // build a Web Search Request
+        if (webSearchRequest == null) {
+            final String searchTerms = exchange.getMessage().getMandatoryBody(String.class);
+            webSearchRequest = WebSearchRequest.builder()
+                    .searchTerms(searchTerms)
+                    .maxResults(getEndpoint().getConfiguration().getMaxResults())
+                    .language(getEndpoint().getConfiguration().getLanguage())
+                    .geoLocation(getEndpoint().getConfiguration().getGeoLocation())
+                    .startPage(getEndpoint().getConfiguration().getStartPage())
+                    .startIndex(getEndpoint().getConfiguration().getStartIndex())
+                    .additionalParams(getEndpoint().getConfiguration().getAdditionalParams())
+                    .build();
+        }
+
+        // perform the request
+        WebSearchResults webSearchResults = webSearchEngine.search(webSearchRequest);
+
+        // exrtact the list
+        List<WebSearchOrganicResult> resultList = webSearchResults.results();
+
+        // compute the response
+        computeResponse(resultList, exchange, webSearchRequest.maxResults());
+    }
+
+    @Override
+    protected void doStart() throws Exception {
+        super.doStart();
+        this.webSearchEngine = getEndpoint().getConfiguration().getWebSearchEngine();
+        ObjectHelper.notNull(webSearchEngine, "webSearchEngine");
+    }
+
+    /**
+     * Computes the response of the web search based on the configuration and input results.
+     *
+     * @param webSearchOrganicResults the list of WebSearchOrganicResult objects to process
+     * @param exchange                the Apache Camel Exchange object
+     * @param maxResults              maxResults
+     */
+    private void computeResponse(List<WebSearchOrganicResult> webSearchOrganicResults, Exchange exchange, Integer maxResults) {
+        // return a single object as a response
+        if (maxResults == 1) {
+            switch (getEndpoint().getConfiguration().getResultType()) {
+                case LANGCHAIN4J_WEB_SEARCH_ORGNAIC_RESULT -> exchange.getIn().setBody(webSearchOrganicResults.get(0));

Review Comment:
   Are we 100% sure we won't get and IndexOutOfBoundsException?



##########
components/camel-ai/camel-langchain4j-web-search/src/main/docs/langchain4j-web-search-component.adoc:
##########
@@ -0,0 +1,159 @@
+= LangChain4j Web Search Component
+:doctitle: LangChain4j Web Search
+:shortname: langchain4j-web-search
+:artifactid: camel-langchain4j-web-search
+:description: LangChain4j Web Search Engine
+:since: 4.8
+:supportlevel: Preview
+:tabs-sync-option:
+:component-header: Only producer is supported
+//Manually maintained attributes
+:group: AI
+:camel-spring-boot-name: langchain4j-web-search
+
+*Since Camel {since}*
+
+*{component-header}*
+
+The LangChain4j Web Search component provides support to perform a web search using the https://docs.langchain4j.dev/[LangChain4j] Web Search Engines.
+
+Maven users will need to add the following dependency to their `pom.xml`
+for this component:
+
+[source,xml]
+----
+<dependency>
+    <groupId>org.apache.camel</groupId>
+    <artifactId>camel-langchain4j-web-search</artifactId>
+    <version>x.x.x</version>
+    <!-- use the same version as your Camel core version -->
+</dependency>
+----
+
+
+== URI format
+
+[source]
+----
+langchain4j-web-search:searchId[?options]
+----
+
+Where *searchId* can be any string to uniquely identify the endpoint
+
+
+// component-configure options: START
+
+// component-configure options: END
+
+// component options: START
+include::partial$component-configure-options.adoc[]
+include::partial$component-endpoint-options.adoc[]
+// component options: END
+
+// endpoint options: START
+
+// endpoint options: END
+
+// component headers: START
+include::partial$component-endpoint-headers.adoc[]
+// component headers: END
+
+include::spring-boot:partial$starter.adoc[]
+
+
+== Using a specific Web Search Engine
+The Camel LangChain4j web search component provides an abstraction for interacting with various types of Web Search Engines supported by https://github.com/langchain4j/langchain4j[LangChain4j].
+
+To integrate with a specific Web Search Engine, users should follow these steps:
+
+=== Example of integrating with Tavily
+Add the dependency for LangChain4j Tavily Web Search Engine support :
+
+[source,xml]
+----
+<dependency>

Review Comment:
   This could be injected also by looking at the route or the configuration.



##########
components/camel-ai/camel-langchain4j-web-search/src/main/java/org/apache/camel/component/langchain4j/web/search/LangChain4jWebSearchProducer.java:
##########
@@ -0,0 +1,104 @@
+/*
+ * 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.langchain4j.web.search;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import dev.langchain4j.web.search.WebSearchEngine;
+import dev.langchain4j.web.search.WebSearchOrganicResult;
+import dev.langchain4j.web.search.WebSearchRequest;
+import dev.langchain4j.web.search.WebSearchResults;
+import org.apache.camel.Exchange;
+import org.apache.camel.support.DefaultProducer;
+import org.apache.camel.util.ObjectHelper;
+
+public class LangChain4jWebSearchProducer extends DefaultProducer {
+
+    private WebSearchEngine webSearchEngine;
+
+    public LangChain4jWebSearchProducer(LangChain4jWebSearchEndpoint endpoint) {
+        super(endpoint);
+    }
+
+    @Override
+    public LangChain4jWebSearchEndpoint getEndpoint() {
+        return (LangChain4jWebSearchEndpoint) super.getEndpoint();
+    }
+
+    @Override
+    public void process(Exchange exchange) throws Exception {
+        // check if there's a custom WebSearchRequest -- advanced
+        WebSearchRequest webSearchRequest = getEndpoint().getConfiguration().getWebSearchRequest();
+
+        // build a Web Search Request
+        if (webSearchRequest == null) {
+            final String searchTerms = exchange.getMessage().getMandatoryBody(String.class);
+            webSearchRequest = WebSearchRequest.builder()
+                    .searchTerms(searchTerms)
+                    .maxResults(getEndpoint().getConfiguration().getMaxResults())
+                    .language(getEndpoint().getConfiguration().getLanguage())
+                    .geoLocation(getEndpoint().getConfiguration().getGeoLocation())
+                    .startPage(getEndpoint().getConfiguration().getStartPage())
+                    .startIndex(getEndpoint().getConfiguration().getStartIndex())
+                    .additionalParams(getEndpoint().getConfiguration().getAdditionalParams())
+                    .build();
+        }
+
+        // perform the request
+        WebSearchResults webSearchResults = webSearchEngine.search(webSearchRequest);
+
+        // exrtact the list
+        List<WebSearchOrganicResult> resultList = webSearchResults.results();
+
+        // compute the response
+        computeResponse(resultList, exchange, webSearchRequest.maxResults());
+    }
+
+    @Override
+    protected void doStart() throws Exception {
+        super.doStart();
+        this.webSearchEngine = getEndpoint().getConfiguration().getWebSearchEngine();
+        ObjectHelper.notNull(webSearchEngine, "webSearchEngine");
+    }
+
+    /**
+     * Computes the response of the web search based on the configuration and input results.
+     *
+     * @param webSearchOrganicResults the list of WebSearchOrganicResult objects to process
+     * @param exchange                the Apache Camel Exchange object
+     * @param maxResults              maxResults
+     */
+    private void computeResponse(List<WebSearchOrganicResult> webSearchOrganicResults, Exchange exchange, Integer maxResults) {
+        // return a single object as a response
+        if (maxResults == 1) {
+            switch (getEndpoint().getConfiguration().getResultType()) {
+                case LANGCHAIN4J_WEB_SEARCH_ORGNAIC_RESULT -> exchange.getIn().setBody(webSearchOrganicResults.get(0));

Review Comment:
   We are passing the maxResult parameter, but I would add a guard check for looking at the size.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-20935: introduce Camel LangChain4j Web Search component [camel]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #14928:
URL: https://github.com/apache/camel/pull/14928#issuecomment-2248001441

   :star2: Thank you for your contribution to the Apache Camel project! :star2: 
   
   :robot: CI automation will test this PR automatically.
   
   :camel: Apache Camel Committers, please review the following items:
   
   * First-time contributors **require MANUAL approval** for the GitHub Actions to run
   
   * You can use the command `/component-test (camel-)component-name1 (camel-)component-name2..` to request a test from the test bot.
   
   * You can label PRs using `build-all`, `build-dependents`, `skip-tests` and `test-dependents` to fine-tune the checks executed by this PR.
   
   * Build and test logs are available in the Summary page. **Only** [Apache Camel committers](https://camel.apache.org/community/team/#committers) have access to the summary. 
   
   * :warning: Be careful when sharing logs. Review their contents before sharing them publicly.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-20935: introduce Camel LangChain4j Web Search component [camel]

Posted by "zbendhiba (via GitHub)" <gi...@apache.org>.
zbendhiba commented on PR #14928:
URL: https://github.com/apache/camel/pull/14928#issuecomment-2248005221

   Planning to write a blog post when finishing to work on [CAMEL-20968](https://issues.apache.org/jira/browse/CAMEL-20968) feature


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-20935: introduce Camel LangChain4j Web Search component [camel]

Posted by "zbendhiba (via GitHub)" <gi...@apache.org>.
zbendhiba commented on code in PR #14928:
URL: https://github.com/apache/camel/pull/14928#discussion_r1691168620


##########
components/camel-ai/camel-langchain4j-web-search/src/main/java/org/apache/camel/component/langchain4j/web/search/LangChain4jWebSearchProducer.java:
##########
@@ -0,0 +1,104 @@
+/*
+ * 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.langchain4j.web.search;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import dev.langchain4j.web.search.WebSearchEngine;
+import dev.langchain4j.web.search.WebSearchOrganicResult;
+import dev.langchain4j.web.search.WebSearchRequest;
+import dev.langchain4j.web.search.WebSearchResults;
+import org.apache.camel.Exchange;
+import org.apache.camel.support.DefaultProducer;
+import org.apache.camel.util.ObjectHelper;
+
+public class LangChain4jWebSearchProducer extends DefaultProducer {
+
+    private WebSearchEngine webSearchEngine;
+
+    public LangChain4jWebSearchProducer(LangChain4jWebSearchEndpoint endpoint) {
+        super(endpoint);
+    }
+
+    @Override
+    public LangChain4jWebSearchEndpoint getEndpoint() {
+        return (LangChain4jWebSearchEndpoint) super.getEndpoint();
+    }
+
+    @Override
+    public void process(Exchange exchange) throws Exception {
+        // check if there's a custom WebSearchRequest -- advanced
+        WebSearchRequest webSearchRequest = getEndpoint().getConfiguration().getWebSearchRequest();
+
+        // build a Web Search Request
+        if (webSearchRequest == null) {
+            final String searchTerms = exchange.getMessage().getMandatoryBody(String.class);
+            webSearchRequest = WebSearchRequest.builder()
+                    .searchTerms(searchTerms)
+                    .maxResults(getEndpoint().getConfiguration().getMaxResults())
+                    .language(getEndpoint().getConfiguration().getLanguage())
+                    .geoLocation(getEndpoint().getConfiguration().getGeoLocation())
+                    .startPage(getEndpoint().getConfiguration().getStartPage())
+                    .startIndex(getEndpoint().getConfiguration().getStartIndex())
+                    .additionalParams(getEndpoint().getConfiguration().getAdditionalParams())
+                    .build();
+        }
+
+        // perform the request
+        WebSearchResults webSearchResults = webSearchEngine.search(webSearchRequest);
+
+        // exrtact the list
+        List<WebSearchOrganicResult> resultList = webSearchResults.results();
+
+        // compute the response
+        computeResponse(resultList, exchange, webSearchRequest.maxResults());
+    }
+
+    @Override
+    protected void doStart() throws Exception {
+        super.doStart();
+        this.webSearchEngine = getEndpoint().getConfiguration().getWebSearchEngine();
+        ObjectHelper.notNull(webSearchEngine, "webSearchEngine");
+    }
+
+    /**
+     * Computes the response of the web search based on the configuration and input results.
+     *
+     * @param webSearchOrganicResults the list of WebSearchOrganicResult objects to process
+     * @param exchange                the Apache Camel Exchange object
+     * @param maxResults              maxResults
+     */
+    private void computeResponse(List<WebSearchOrganicResult> webSearchOrganicResults, Exchange exchange, Integer maxResults) {
+        // return a single object as a response
+        if (maxResults == 1) {
+            switch (getEndpoint().getConfiguration().getResultType()) {
+                case LANGCHAIN4J_WEB_SEARCH_ORGNAIC_RESULT -> exchange.getIn().setBody(webSearchOrganicResults.get(0));

Review Comment:
   oh yes you're right



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-20935: introduce Camel LangChain4j Web Search component [camel]

Posted by "zbendhiba (via GitHub)" <gi...@apache.org>.
zbendhiba commented on code in PR #14928:
URL: https://github.com/apache/camel/pull/14928#discussion_r1691257784


##########
components/camel-ai/camel-langchain4j-web-search/src/main/java/org/apache/camel/component/langchain4j/web/search/LangChain4jWebSearchProducer.java:
##########
@@ -0,0 +1,104 @@
+/*
+ * 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.langchain4j.web.search;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import dev.langchain4j.web.search.WebSearchEngine;
+import dev.langchain4j.web.search.WebSearchOrganicResult;
+import dev.langchain4j.web.search.WebSearchRequest;
+import dev.langchain4j.web.search.WebSearchResults;
+import org.apache.camel.Exchange;
+import org.apache.camel.support.DefaultProducer;
+import org.apache.camel.util.ObjectHelper;
+
+public class LangChain4jWebSearchProducer extends DefaultProducer {
+
+    private WebSearchEngine webSearchEngine;
+
+    public LangChain4jWebSearchProducer(LangChain4jWebSearchEndpoint endpoint) {
+        super(endpoint);
+    }
+
+    @Override
+    public LangChain4jWebSearchEndpoint getEndpoint() {
+        return (LangChain4jWebSearchEndpoint) super.getEndpoint();
+    }
+
+    @Override
+    public void process(Exchange exchange) throws Exception {
+        // check if there's a custom WebSearchRequest -- advanced
+        WebSearchRequest webSearchRequest = getEndpoint().getConfiguration().getWebSearchRequest();
+
+        // build a Web Search Request
+        if (webSearchRequest == null) {
+            final String searchTerms = exchange.getMessage().getMandatoryBody(String.class);
+            webSearchRequest = WebSearchRequest.builder()
+                    .searchTerms(searchTerms)
+                    .maxResults(getEndpoint().getConfiguration().getMaxResults())
+                    .language(getEndpoint().getConfiguration().getLanguage())
+                    .geoLocation(getEndpoint().getConfiguration().getGeoLocation())
+                    .startPage(getEndpoint().getConfiguration().getStartPage())
+                    .startIndex(getEndpoint().getConfiguration().getStartIndex())
+                    .additionalParams(getEndpoint().getConfiguration().getAdditionalParams())
+                    .build();
+        }
+
+        // perform the request
+        WebSearchResults webSearchResults = webSearchEngine.search(webSearchRequest);
+
+        // exrtact the list
+        List<WebSearchOrganicResult> resultList = webSearchResults.results();
+
+        // compute the response
+        computeResponse(resultList, exchange, webSearchRequest.maxResults());
+    }
+
+    @Override
+    protected void doStart() throws Exception {
+        super.doStart();
+        this.webSearchEngine = getEndpoint().getConfiguration().getWebSearchEngine();
+        ObjectHelper.notNull(webSearchEngine, "webSearchEngine");
+    }
+
+    /**
+     * Computes the response of the web search based on the configuration and input results.
+     *
+     * @param webSearchOrganicResults the list of WebSearchOrganicResult objects to process
+     * @param exchange                the Apache Camel Exchange object
+     * @param maxResults              maxResults
+     */
+    private void computeResponse(List<WebSearchOrganicResult> webSearchOrganicResults, Exchange exchange, Integer maxResults) {
+        // return a single object as a response
+        if (maxResults == 1) {
+            switch (getEndpoint().getConfiguration().getResultType()) {
+                case LANGCHAIN4J_WEB_SEARCH_ORGNAIC_RESULT -> exchange.getIn().setBody(webSearchOrganicResults.get(0));

Review Comment:
   I improved that part. Let me know if that looks good to you



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org