-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CAMEL-21022 - Create Camel Langchain4j Web Search Starter
Signed-off-by: Andrea Cosentino <[email protected]>
- Loading branch information
Showing
12 changed files
with
528 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...main/resources/org/apache/camel/springboot/catalog/components/langchain4j-web-search.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"component": { | ||
"kind": "component", | ||
"name": "langchain4j-web-search", | ||
"title": "LangChain4j Web Search", | ||
"description": "LangChain4j Web Search Engine", | ||
"deprecated": false, | ||
"firstVersion": "4.8.0", | ||
"label": "ai", | ||
"javaType": "org.apache.camel.component.langchain4j.web.search.LangChain4jWebSearchComponent", | ||
"supportLevel": "Preview", | ||
"groupId": "org.apache.camel.springboot", | ||
"artifactId": "camel-langchain4j-web-search-starter", | ||
"version": "4.8.0-SNAPSHOT", | ||
"scheme": "langchain4j-web-search", | ||
"extendsScheme": "", | ||
"syntax": "langchain4j-web-search:searchId", | ||
"async": false, | ||
"api": false, | ||
"consumerOnly": false, | ||
"producerOnly": true, | ||
"lenientProperties": false, | ||
"remote": true | ||
}, | ||
"componentProperties": { | ||
"lazyStartProducer": { "index": 0, "kind": "property", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing." }, | ||
"autowiredEnabled": { "index": 1, "kind": "property", "displayName": "Autowired Enabled", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc." } | ||
}, | ||
"properties": { | ||
"searchId": { "index": 0, "kind": "path", "displayName": "Search Id", "group": "producer", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The id" }, | ||
"additionalParams": { "index": 1, "kind": "parameter", "displayName": "Additional Params", "group": "producer", "label": "", "required": false, "type": "object", "javaType": "java.util.Map<java.lang.String, java.lang.Object>", "deprecated": false, "deprecationNote": "", "autowired": true, "secret": false, "configurationClass": "org.apache.camel.component.langchain4j.web.search.LangChain4jWebSearchConfiguration", "configurationField": "configuration", "description": "The additionalParams is the additional parameters for the search request are a map of key-value pairs that represent additional parameters for the search request." }, | ||
"geoLocation": { "index": 2, "kind": "parameter", "displayName": "Geo Location", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.langchain4j.web.search.LangChain4jWebSearchConfiguration", "configurationField": "configuration", "description": "The geoLocation is the desired geolocation for search results. Each search engine may have a different set of supported geolocations." }, | ||
"language": { "index": 3, "kind": "parameter", "displayName": "Language", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.langchain4j.web.search.LangChain4jWebSearchConfiguration", "configurationField": "configuration", "description": "The language is the desired language for search results. The expected values may vary depending on the search engine." }, | ||
"maxResults": { "index": 4, "kind": "parameter", "displayName": "Max Results", "group": "producer", "label": "", "required": true, "type": "integer", "javaType": "java.lang.Integer", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "defaultValue": "1", "configurationClass": "org.apache.camel.component.langchain4j.web.search.LangChain4jWebSearchConfiguration", "configurationField": "configuration", "description": "The 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." }, | ||
"resultType": { "index": 5, "kind": "parameter", "displayName": "Result Type", "group": "producer", "label": "", "required": true, "type": "object", "javaType": "org.apache.camel.component.langchain4j.web.search.LangChain4jWebSearchResultType", "enum": [ "LANGCHAIN4J_WEB_SEARCH_ORGANIC_RESULT", "CONTENT", "SNIPPET" ], "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "defaultValue": "CONTENT", "configurationClass": "org.apache.camel.component.langchain4j.web.search.LangChain4jWebSearchConfiguration", "configurationField": "configuration", "description": "The 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_ORGANIC_RESULT) or snippet (using SNIPPET) for each result. If maxResults is equal to 1, the response will be a single object instead of a list." }, | ||
"safeSearch": { "index": 6, "kind": "parameter", "displayName": "Safe Search", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.langchain4j.web.search.LangChain4jWebSearchConfiguration", "configurationField": "configuration", "description": "The safeSearch is the safe search flag, indicating whether to enable or disable safe search." }, | ||
"startIndex": { "index": 7, "kind": "parameter", "displayName": "Start Index", "group": "producer", "label": "", "required": false, "type": "integer", "javaType": "java.lang.Integer", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.langchain4j.web.search.LangChain4jWebSearchConfiguration", "configurationField": "configuration", "description": "The startIndex is the start index for search results, which may vary depending on the search engine." }, | ||
"startPage": { "index": 8, "kind": "parameter", "displayName": "Start Page", "group": "producer", "label": "", "required": false, "type": "integer", "javaType": "java.lang.Integer", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.langchain4j.web.search.LangChain4jWebSearchConfiguration", "configurationField": "configuration", "description": "The startPage is the start page number for search results" }, | ||
"webSearchEngine": { "index": 9, "kind": "parameter", "displayName": "Web Search Engine", "group": "producer", "label": "", "required": true, "type": "object", "javaType": "dev.langchain4j.web.search.WebSearchEngine", "deprecated": false, "deprecationNote": "", "autowired": true, "secret": false, "configurationClass": "org.apache.camel.component.langchain4j.web.search.LangChain4jWebSearchConfiguration", "configurationField": "configuration", "description": "The WebSearchEngine engine to use. This is mandatory. Use one of the implementations from Langchain4j web search engines." }, | ||
"lazyStartProducer": { "index": 10, "kind": "parameter", "displayName": "Lazy Start Producer", "group": "producer (advanced)", "label": "producer,advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing." }, | ||
"webSearchRequest": { "index": 11, "kind": "parameter", "displayName": "Web Search Request", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "dev.langchain4j.web.search.WebSearchRequest", "deprecated": false, "deprecationNote": "", "autowired": true, "secret": false, "configurationClass": "org.apache.camel.component.langchain4j.web.search.LangChain4jWebSearchConfiguration", "configurationField": "configuration", "description": "The webSearchRequest is the custom WebSearchRequest - advanced" } | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
components-starter/camel-langchain4j-web-search-starter/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?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/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.apache.camel.springboot</groupId> | ||
<artifactId>components-starter</artifactId> | ||
<version>4.8.0-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>camel-langchain4j-web-search-starter</artifactId> | ||
<packaging>jar</packaging> | ||
<name>Camel SB Starters :: langchain4j-web-search</name> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter</artifactId> | ||
<version>${spring-boot-version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.camel</groupId> | ||
<artifactId>camel-langchain4j-web-search</artifactId> | ||
<version>${camel-version}</version> | ||
</dependency> | ||
<!--START OF GENERATED CODE--> | ||
<dependency> | ||
<groupId>org.apache.camel.springboot</groupId> | ||
<artifactId>camel-core-starter</artifactId> | ||
</dependency> | ||
<!--END OF GENERATED CODE--> | ||
</dependencies> | ||
</project> |
43 changes: 43 additions & 0 deletions
43
...ts-starter/camel-langchain4j-web-search-starter/src/main/docs/langchain4j-web-search.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"groups": [ | ||
{ | ||
"name": "camel.component.langchain4j-web-search", | ||
"type": "org.apache.camel.component.langchain4j.web.search.springboot.LangChain4jWebSearchComponentConfiguration", | ||
"sourceType": "org.apache.camel.component.langchain4j.web.search.springboot.LangChain4jWebSearchComponentConfiguration" | ||
}, | ||
{ | ||
"name": "camel.component.langchain4j-web-search.customizer", | ||
"type": "org.apache.camel.spring.boot.ComponentConfigurationPropertiesCommon$CustomizerProperties", | ||
"sourceType": "org.apache.camel.component.langchain4j.web.search.springboot.LangChain4jWebSearchComponentConfiguration", | ||
"sourceMethod": "getCustomizer()" | ||
} | ||
], | ||
"properties": [ | ||
{ | ||
"name": "camel.component.langchain4j-web-search.autowired-enabled", | ||
"type": "java.lang.Boolean", | ||
"description": "Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.", | ||
"sourceType": "org.apache.camel.component.langchain4j.web.search.springboot.LangChain4jWebSearchComponentConfiguration", | ||
"defaultValue": true | ||
}, | ||
{ | ||
"name": "camel.component.langchain4j-web-search.customizer.enabled", | ||
"type": "java.lang.Boolean", | ||
"sourceType": "org.apache.camel.spring.boot.ComponentConfigurationPropertiesCommon$CustomizerProperties" | ||
}, | ||
{ | ||
"name": "camel.component.langchain4j-web-search.enabled", | ||
"type": "java.lang.Boolean", | ||
"description": "Whether to enable auto configuration of the langchain4j-web-search component. This is enabled by default.", | ||
"sourceType": "org.apache.camel.component.langchain4j.web.search.springboot.LangChain4jWebSearchComponentConfiguration" | ||
}, | ||
{ | ||
"name": "camel.component.langchain4j-web-search.lazy-start-producer", | ||
"type": "java.lang.Boolean", | ||
"description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.", | ||
"sourceType": "org.apache.camel.component.langchain4j.web.search.springboot.LangChain4jWebSearchComponentConfiguration", | ||
"defaultValue": false | ||
} | ||
], | ||
"hints": [] | ||
} |
77 changes: 77 additions & 0 deletions
77
...ent/langchain4j/web/search/springboot/LangChain4jWebSearchComponentAutoConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* 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.springboot; | ||
|
||
import org.apache.camel.CamelContext; | ||
import org.apache.camel.Component; | ||
import org.apache.camel.component.langchain4j.web.search.LangChain4jWebSearchComponent; | ||
import org.apache.camel.spi.ComponentCustomizer; | ||
import org.apache.camel.spring.boot.CamelAutoConfiguration; | ||
import org.apache.camel.spring.boot.ComponentConfigurationProperties; | ||
import org.apache.camel.spring.boot.util.CamelPropertiesHelper; | ||
import org.apache.camel.spring.boot.util.ConditionalOnCamelContextAndAutoConfigurationBeans; | ||
import org.apache.camel.spring.boot.util.ConditionalOnHierarchicalProperties; | ||
import org.apache.camel.spring.boot.util.HierarchicalPropertiesEvaluator; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.autoconfigure.AutoConfigureAfter; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Conditional; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Lazy; | ||
|
||
/** | ||
* Generated by camel-package-maven-plugin - do not edit this file! | ||
*/ | ||
@Configuration(proxyBeanMethods = false) | ||
@Conditional(ConditionalOnCamelContextAndAutoConfigurationBeans.class) | ||
@EnableConfigurationProperties({ComponentConfigurationProperties.class,LangChain4jWebSearchComponentConfiguration.class}) | ||
@ConditionalOnHierarchicalProperties({"camel.component", "camel.component.langchain4j-web-search"}) | ||
@AutoConfigureAfter(CamelAutoConfiguration.class) | ||
public class LangChain4jWebSearchComponentAutoConfiguration { | ||
|
||
@Autowired | ||
private ApplicationContext applicationContext; | ||
private final CamelContext camelContext; | ||
@Autowired | ||
private LangChain4jWebSearchComponentConfiguration configuration; | ||
|
||
public LangChain4jWebSearchComponentAutoConfiguration( | ||
org.apache.camel.CamelContext camelContext) { | ||
this.camelContext = camelContext; | ||
} | ||
|
||
@Lazy | ||
@Bean | ||
public ComponentCustomizer configureLangChain4jWebSearchComponent() { | ||
return new ComponentCustomizer() { | ||
@Override | ||
public void configure(String name, Component target) { | ||
CamelPropertiesHelper.copyProperties(camelContext, configuration, target); | ||
} | ||
@Override | ||
public boolean isEnabled(String name, Component target) { | ||
return HierarchicalPropertiesEvaluator.evaluate( | ||
applicationContext, | ||
"camel.component.customizer", | ||
"camel.component.langchain4j-web-search.customizer") | ||
&& target instanceof LangChain4jWebSearchComponent; | ||
} | ||
}; | ||
} | ||
} |
Oops, something went wrong.