Skip to content

Commit

Permalink
[improve] : fix AiService getType method data type,complete informati…
Browse files Browse the repository at this point in the history
…on for LICENSE (#2141)

Co-authored-by: Logic <[email protected]>
Co-authored-by: tomsun28 <[email protected]>
  • Loading branch information
3 people authored Jun 25, 2024
1 parent ec1c41c commit a54d8cd
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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.hertzbeat.common.constants;

/**
* Ai type Enum
*/
public enum AiTypeEnum {

/**
* 智普
*/
zhiPu;


/**
* get type
*/
public static AiTypeEnum getTypeByName(String type) {
for (AiTypeEnum aiTypeEnum : values()) {
if (aiTypeEnum.name().equals(type)) {
return aiTypeEnum;
}

}
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.hertzbeat.manager.service;


import org.apache.hertzbeat.common.constants.AiTypeEnum;
import org.springframework.http.codec.ServerSentEvent;
import reactor.core.publisher.Flux;

Expand All @@ -31,7 +32,7 @@ public interface AiService {
* get AI type
* @return type
*/
String getType();
AiTypeEnum getType();

/**
* AI response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.function.Function;
import java.util.stream.Collectors;
import javax.annotation.PostConstruct;
import org.apache.hertzbeat.common.constants.AiTypeEnum;
import org.apache.hertzbeat.manager.service.AiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
Expand All @@ -37,7 +38,7 @@ public class AiServiceFactoryImpl {
@Autowired
private List<AiService> aiService;

private Map<String, AiService> aiServiceFactoryMap = new HashMap<>();
private Map<AiTypeEnum, AiService> aiServiceFactoryMap = new HashMap<>();

@PostConstruct
public void init() {
Expand All @@ -47,7 +48,9 @@ public void init() {

public AiService getAiServiceImplBean(String type) {
Assert.notNull(type, "type is null");
AiService aiServiceImpl = aiServiceFactoryMap.get(type);
AiTypeEnum typeByName = AiTypeEnum.getTypeByName(type);
Assert.notNull(typeByName, "The current type is not supported");
AiService aiServiceImpl = aiServiceFactoryMap.get(typeByName);
Assert.notNull(aiServiceImpl, "No bean for current type found");
return aiServiceImpl;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import javax.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.apache.hertzbeat.common.constants.AiConstants;
import org.apache.hertzbeat.common.constants.AiTypeEnum;
import org.apache.hertzbeat.manager.pojo.dto.AiMessage;
import org.apache.hertzbeat.manager.pojo.dto.ZhiPuAiResponse;
import org.apache.hertzbeat.manager.pojo.dto.ZhiPuRequestParamDTO;
Expand Down Expand Up @@ -66,8 +67,8 @@ private void init() {
}

@Override
public String getType() {
return "0";
public AiTypeEnum getType() {
return AiTypeEnum.zhiPu;
}

@Override
Expand Down
3 changes: 3 additions & 0 deletions material/licenses/LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,9 @@ The text of each license is the standard Apache 2.0 license.
https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-logging/3.2.3 Apache-2.0
https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-mail/3.2.3 Apache-2.0
https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-thymeleaf/3.2.3 Apache-2.0
https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-webflux/3.2.3 Apache-2.0
https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-reactor-netty/3.2.3 Apache-2.0
https://mvnrepository.com/artifact/org.springframework/spring-webflux/6.1.4 Apache-2.0
https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-tomcat/3.2.3 Apache-2.0
https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-validation/3.2.3 Apache-2.0
https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web/3.2.3 Apache-2.0
Expand Down
3 changes: 3 additions & 0 deletions material/licenses/backend/LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,9 @@ The text of each license is the standard Apache 2.0 license.
https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-logging/3.2.3 Apache-2.0
https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-mail/3.2.3 Apache-2.0
https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-thymeleaf/3.2.3 Apache-2.0
https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-webflux/3.2.3 Apache-2.0
https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-reactor-netty/3.2.3 Apache-2.0
https://mvnrepository.com/artifact/org.springframework/spring-webflux/6.1.4 Apache-2.0
https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-tomcat/3.2.3 Apache-2.0
https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-validation/3.2.3 Apache-2.0
https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web/3.2.3 Apache-2.0
Expand Down

0 comments on commit a54d8cd

Please sign in to comment.