AI智能工牌的建表语句
This commit is contained in:
68
src/main/java/com/rj/config/CommonConfig.java
Normal file
68
src/main/java/com/rj/config/CommonConfig.java
Normal file
@@ -0,0 +1,68 @@
|
||||
package com.rj.config;
|
||||
|
||||
import com.rj.aiservice.CstAIService;
|
||||
import com.rj.repository.RedisChatMemoryStore;
|
||||
import dev.langchain4j.memory.ChatMemory;
|
||||
import dev.langchain4j.memory.chat.ChatMemoryProvider;
|
||||
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
|
||||
import dev.langchain4j.model.openai.OpenAiChatModel;
|
||||
import dev.langchain4j.service.AiServices;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* Author: 李中华 wx: spllzh email(qq): 28668817@qq.com
|
||||
* Date: 2025/8/4 10:24
|
||||
**/
|
||||
@Configuration
|
||||
public class CommonConfig {
|
||||
|
||||
@Autowired
|
||||
private OpenAiChatModel openAiChatModel;
|
||||
|
||||
// @Bean
|
||||
public CstAIService cstAIService() {
|
||||
|
||||
CstAIService cstAIService = AiServices.builder(CstAIService.class)
|
||||
.chatModel(openAiChatModel)
|
||||
.build();
|
||||
|
||||
return cstAIService;
|
||||
}
|
||||
@Bean
|
||||
public ChatMemory chatMemory() {
|
||||
|
||||
MessageWindowChatMemory build = MessageWindowChatMemory.builder()
|
||||
.maxMessages(10)
|
||||
.build();
|
||||
return build;
|
||||
}
|
||||
|
||||
|
||||
@Autowired
|
||||
RedisChatMemoryStore redisChatMemoryStore;
|
||||
|
||||
|
||||
|
||||
@Bean
|
||||
public ChatMemoryProvider chatMemoryProvider() {
|
||||
|
||||
ChatMemoryProvider chatMemoryProvider = new ChatMemoryProvider() {
|
||||
@Override
|
||||
public ChatMemory get(Object memoryId) {
|
||||
|
||||
MessageWindowChatMemory chatMemory = MessageWindowChatMemory.builder()
|
||||
.id(memoryId)
|
||||
.maxMessages(10)
|
||||
.chatMemoryStore(redisChatMemoryStore)
|
||||
.build();
|
||||
return chatMemory;
|
||||
}
|
||||
};
|
||||
|
||||
return chatMemoryProvider;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
82
src/main/java/com/rj/config/SwaggerOpenAPI.java
Normal file
82
src/main/java/com/rj/config/SwaggerOpenAPI.java
Normal file
@@ -0,0 +1,82 @@
|
||||
package com.rj.config;
|
||||
|
||||
//import io.swagger.models.Info;
|
||||
|
||||
//import io.swagger.annotations.Info;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.info.Contact;
|
||||
import io.swagger.v3.oas.models.info.Info;
|
||||
import io.swagger.v3.oas.models.servers.Server;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springdoc.core.models.GroupedOpenApi;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* http://localhost:9060/swagger-ui/index.html#/
|
||||
* https://index.huayang-star.com/swagger-ui/index.html#/ai-card-bag-controller
|
||||
*
|
||||
* Author: 李中华 wx: spllzh email(qq): 28668817@qq.com
|
||||
* Date: 2025/6/30 9:55
|
||||
**/
|
||||
@Slf4j
|
||||
@Configuration
|
||||
public class SwaggerOpenAPI {
|
||||
|
||||
@Value("${swagger.api.base-url}")
|
||||
private String baseUrl;
|
||||
|
||||
@Value("${langchain4j.community.dashscope.chat-model.api-key}")
|
||||
private String apiKey;
|
||||
|
||||
|
||||
@Configuration
|
||||
public class JacksonConfig {
|
||||
@Bean
|
||||
public ObjectMapper objectMapper() {
|
||||
return new ObjectMapper()
|
||||
.registerModule(new JavaTimeModule())
|
||||
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||
}
|
||||
}
|
||||
|
||||
@Bean
|
||||
public OpenAPI customOpenAPI() {
|
||||
log.info("baseUrl = " + baseUrl);
|
||||
return new OpenAPI()
|
||||
.servers(List.of(new Server().url(baseUrl))) // 强制HTTPS
|
||||
.info(new Info()
|
||||
.title("AI Card API")
|
||||
.version("1.0.0")
|
||||
.description("Spring Boot 3.4 + Knife4j 集成 API")
|
||||
.contact(new Contact().name("Support").email("support@huayang-star.com"))
|
||||
);
|
||||
}
|
||||
@Bean
|
||||
public GroupedOpenApi publicApi() {
|
||||
return GroupedOpenApi.builder()
|
||||
.group("public-api")
|
||||
.pathsToMatch("/api/**")
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public GroupedOpenApi adminApi() {
|
||||
return GroupedOpenApi.builder()
|
||||
.group("admin-api")
|
||||
.pathsToMatch("/admin/**")
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user