Skip to content

Commit

Permalink
Merge pull request #212 from PolarishT/main
Browse files Browse the repository at this point in the history
[reactor]:  rename catalogue
  • Loading branch information
chickenlj authored Dec 18, 2024
2 parents e3fe09f + 3a621cd commit e705118
Show file tree
Hide file tree
Showing 230 changed files with 264 additions and 26,820 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<relativePath>../../../pom.xml</relativePath>
</parent>

<artifactId>spring-ai-alibaba-starter-plugin-amap</artifactId>
<artifactId>spring-ai-alibaba-starter-function-calling-amap</artifactId>
<name>spring-ai-alibaba-starter-plugin-amap</name>
<description>Gao De Map tool for Spring AI Alibaba</description>

Expand All @@ -50,9 +50,8 @@
</dependency>

<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.83</version>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>

</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* limitations under the License.
*/

package com.alibaba.cloud.ai.plugin.gaode;
package com.alibaba.cloud.ai.functioncalling.amp;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
Expand All @@ -29,15 +29,15 @@
* @author YunLong
*/
@Configuration
@EnableConfigurationProperties(GaoDeProperties.class)
@EnableConfigurationProperties(AmapProperties.class)
@ConditionalOnProperty(prefix = "spring.ai.alibaba.plugin.gaode", name = "enabled", havingValue = "true")
public class GaoDeConfiguration {
public class AmapConfiguration {

@Bean
@ConditionalOnMissingBean
@Description("Get weather information according to address.")
public WeatherSearchService gaoDeGetAddressWeatherFunction(GaoDeProperties gaoDeProperties) {
return new WeatherSearchService(gaoDeProperties);
public WeatherSearchService gaoDeGetAddressWeatherFunction(AmapProperties amapProperties) {
return new WeatherSearchService(amapProperties);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@
* limitations under the License.
*/

package com.alibaba.cloud.ai.plugin.gaode;
package com.alibaba.cloud.ai.functioncalling.amp;

import org.springframework.boot.context.properties.ConfigurationProperties;

/**
* @author YunLong
*/
@ConfigurationProperties(prefix = "spring.ai.alibaba.plugin.gaode")
public class GaoDeProperties {
public class AmapProperties {

// Official Document Address: https://lbs.amap.com/api/webservice/summary
private String webApiKey;

public GaoDeProperties() {
public AmapProperties () {
}

public GaoDeProperties(String webApiKey) {
public AmapProperties (String webApiKey) {
this.webApiKey = webApiKey;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* 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 com.alibaba.cloud.ai.functioncalling.amp;

import com.fasterxml.jackson.annotation.JsonClassDescription;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import java.util.function.Function;

/**
* @author YunLong
*/
public class WeatherSearchService implements Function<WeatherSearchService.Request, WeatherSearchService.Response> {

private final WeatherTools weatherTools;

public WeatherSearchService (AmapProperties amapProperties) {
this.weatherTools = new WeatherTools(amapProperties);
}

@Override
public Response apply (Request request) {

String responseBody = weatherTools.getAddressCityCode(request.address);

String adcode = "";

try {
JsonObject jsonObject = JsonParser.parseString(responseBody).getAsJsonObject();
JsonArray geocodesArray = jsonObject.getAsJsonArray("geocodes");
if (geocodesArray != null && !geocodesArray.isEmpty()) {
JsonObject firstGeocode = geocodesArray.get(0).getAsJsonObject();
adcode = firstGeocode.get("adcode").getAsString();
}
}
catch (Exception e) {
return new Response("Error occurred while processing the request.");
}

String weather = weatherTools.getWeather(adcode);

return new Response(weather);
}

@JsonClassDescription("Get the weather conditions for a specified address.")
public record Request(
@JsonProperty(required = true, value = "address") @JsonPropertyDescription("The address") String address) {
}

public record Response(String message) {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package com.alibaba.cloud.ai.plugin.gaode;
package com.alibaba.cloud.ai.functioncalling.amp;

import java.net.URI;
import java.net.http.HttpClient;
Expand All @@ -31,16 +31,16 @@ public class WeatherTools {

private final String baseUrl = "https://restapi.amap.com/v3";

private final GaoDeProperties gaoDeProperties;
private final AmapProperties amapProperties;

private final HttpClient httpClient;

public WeatherTools(GaoDeProperties gaoDeProperties) {
this.gaoDeProperties = gaoDeProperties;
public WeatherTools(AmapProperties amapProperties) {
this.amapProperties = amapProperties;

this.httpClient = HttpClient.newBuilder().version(HttpClient.Version.HTTP_2).build();

if (Objects.isNull(gaoDeProperties.getWebApiKey())) {
if (Objects.isNull(amapProperties.getWebApiKey())) {
throw new RuntimeException("Please configure your GaoDe API key in the application.yml file.");
}
}
Expand All @@ -52,7 +52,7 @@ public WeatherTools(GaoDeProperties gaoDeProperties) {
*/
public String getAddressCityCode(String address) {

String path = String.format("/geocode/geo?key=%s&address=%s", gaoDeProperties.getWebApiKey(), address);
String path = String.format("/geocode/geo?key=%s&address=%s", amapProperties.getWebApiKey(), address);

HttpRequest httpRequest = createGetRequest(path);

Expand All @@ -74,7 +74,7 @@ public String getAddressCityCode(String address) {
* @return https://lbs.amap.com/api/webservice/guide/api/weatherinfo#s0
*/
public String getWeather(String cityCode) {
String path = String.format("/weather/weatherInfo?key=%s&city=%s&extensions=%s", gaoDeProperties.getWebApiKey(),
String path = String.format("/weather/weatherInfo?key=%s&city=%s&extensions=%s", amapProperties.getWebApiKey(),
cityCode, "all");

HttpRequest httpRequest = createGetRequest(path);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.alibaba.cloud.ai.functioncalling.amp.AmapConfiguration
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<version>${revision}</version>
<relativePath>../../../pom.xml</relativePath>
</parent>
<artifactId>spring-ai-alibaba-starter-plugin-baidusearch</artifactId>
<artifactId>spring-ai-alibaba-starter-function-calling-baidusearch</artifactId>
<name>spring-ai-alibaba-starter-plugin-baidusearch</name>

<description>Baidu search tool for Spring AI Alibaba</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package com.alibaba.cloud.ai.plugin.baidu;
package com.alibaba.cloud.ai.functioncalling.baidusearch;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
Expand All @@ -27,13 +27,13 @@
* @author KrakenZJC
**/
@ConditionalOnClass(BaiduSearchService.class)
@ConditionalOnProperty(value = "spring.ai.alibaba.plugin.baidusearch", name = "enabled", havingValue = "true")
@ConditionalOnProperty(value = "spring.ai.alibaba.functioncalling.baidusearch", name = "enabled", havingValue = "true")
public class BaiduSearchAutoConfiguration {

@Bean
@ConditionalOnMissingBean
@Description("Use baidu search engine to query for the latest news.")
public BaiduSearchService baiduSearchService() {
public BaiduSearchService baiduSearchFunction() {
return new BaiduSearchService();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package com.alibaba.cloud.ai.plugin.baidu;
package com.alibaba.cloud.ai.functioncalling.baidusearch;

import com.fasterxml.jackson.annotation.JsonClassDescription;
import com.fasterxml.jackson.annotation.JsonInclude;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.alibaba.cloud.ai.functioncalling.baidusearch.BaiduSearchAutoConfiguration
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<version>${revision}</version>
<relativePath>../../../pom.xml</relativePath>
</parent>
<artifactId>spring-ai-alibaba-starter-plugin-bingsearch</artifactId>
<artifactId>spring-ai-alibaba-starter-function-calling-bingsearch</artifactId>
<name>spring-ai-alibaba-starter-plugin-bingsearch</name>

<description>Bing search tool for Spring AI Alibaba</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package com.alibaba.cloud.ai.plugin.bing;
package com.alibaba.cloud.ai.functioncalling.bingsearch;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
Expand All @@ -29,13 +29,14 @@
**/
@ConditionalOnClass(BingSearchService.class)
@EnableConfigurationProperties(BingSearchProperties.class)
@ConditionalOnProperty(prefix = "spring.ai.alibaba.functioncalling.bingsearch", name = "enabled", havingValue = "true")
public class BingSearchAutoConfiguration {

@Bean
@ConditionalOnMissingBean
@Description("Use bing search engine to query for the latest news.")
@ConditionalOnProperty(prefix = "spring.ai.alibaba.plugin.bing", name = "enabled", havingValue = "true")
public BingSearchService bingSearchService(BingSearchProperties properties) {
public BingSearchService bingSearchFunction(BingSearchProperties properties) {
return new BingSearchService(properties);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.alibaba.cloud.ai.plugin.bing;
package com.alibaba.cloud.ai.functioncalling.bingsearch;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package com.alibaba.cloud.ai.plugin.bing;
package com.alibaba.cloud.ai.functioncalling.bingsearch;

import com.fasterxml.jackson.annotation.JsonClassDescription;
import com.fasterxml.jackson.annotation.JsonInclude;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
com.alibaba.cloud.ai.functioncalling.bingsearch.BingSearchAutoConfiguration

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<relativePath>../../../pom.xml</relativePath>
</parent>

<artifactId>spring-ai-alibaba-starter-plugin-crawler</artifactId>
<artifactId>spring-ai-alibaba-starter-function-calling-crawler</artifactId>
<packaging>jar</packaging>
<name>Spring Ai Alibaba Starter Plugin Crawler</name>
<url>https://github.com/alibaba/spring-ai-alibaba</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.alibaba.cloud.ai.plugin.crawler.service;
package com.alibaba.cloud.ai.functioncalling.crawler;

import java.io.BufferedReader;
import java.io.IOException;
Expand All @@ -27,10 +26,6 @@
import java.util.Map;
import java.util.Objects;

import com.alibaba.cloud.ai.plugin.crawler.CrawlerJinaProperties;
import com.alibaba.cloud.ai.plugin.crawler.exception.CrawlerServiceException;
import com.alibaba.cloud.ai.plugin.crawler.util.UrlValidator;

import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
Expand All @@ -39,7 +34,6 @@
* @author yuluo
* @author <a href="mailto:[email protected]">yuluo</a>
*/

public abstract class AbstractCrawlerService implements CrawlerService {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.cloud.ai.functioncalling.crawler;

package com.alibaba.cloud.ai.plugin.crawler;

import com.alibaba.cloud.ai.plugin.crawler.service.impl.CrawlerFirecrawlServiceImpl;
import com.alibaba.cloud.ai.plugin.crawler.service.impl.CrawlerJinaServiceImpl;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
Expand All @@ -30,28 +27,27 @@
/**
* @author yuluo
*/
@EnableConfigurationProperties({CrawlerJinaProperties.class, CrawlerFirecrawlProperties.class})
@ConditionalOnProperty(prefix = CrawlerJinaProperties.JINA_PROPERTIES_PREFIX, name = "enabled",
havingValue = "true")
@EnableConfigurationProperties({ CrawlerJinaProperties.class, CrawlerFirecrawlProperties.class })
@ConditionalOnProperty(prefix = CrawlerJinaProperties.JINA_PROPERTIES_PREFIX, name = "enabled", havingValue = "true")
public class CrawlerAutoConfiguration {

@Bean
@ConditionalOnMissingBean
@Description("Jina Reader Service Plugin")
public CrawlerJinaServiceImpl jinaService (CrawlerJinaProperties jinaProperties, ObjectMapper objectMapper) {
@Bean
@ConditionalOnMissingBean
@Description("Jina Reader Service Plugin.")
public CrawlerJinaServiceImpl jinaFunction(CrawlerJinaProperties jinaProperties, ObjectMapper objectMapper) {

Assert.notNull(jinaProperties, "Jina reader api token must not be empty");
return new CrawlerJinaServiceImpl(jinaProperties, objectMapper);
}
Assert.notNull(jinaProperties, "Jina reader api token must not be empty");
return new CrawlerJinaServiceImpl(jinaProperties, objectMapper);
}

@Bean
@ConditionalOnMissingBean
@Description("Firecrawl Service Plugin")
public CrawlerFirecrawlServiceImpl firecrawlService (CrawlerFirecrawlProperties firecrawlProperties,
ObjectMapper objectMapper) {
@Bean
@ConditionalOnMissingBean
@Description("Firecrawl Service Plugin.")
public CrawlerFirecrawlServiceImpl firecrawlFunction(CrawlerFirecrawlProperties firecrawlProperties,
ObjectMapper objectMapper) {

Assert.notNull(firecrawlProperties.getToken(), "Firecrawl api token must not be empty");
return new CrawlerFirecrawlServiceImpl(firecrawlProperties, objectMapper);
}
Assert.notNull(firecrawlProperties.getToken(), "Firecrawl api token must not be empty");
return new CrawlerFirecrawlServiceImpl(firecrawlProperties, objectMapper);
}

}
Loading

0 comments on commit e705118

Please sign in to comment.