feat:init
This commit is contained in:
19
xservice-service/pom.xml
Normal file
19
xservice-service/pom.xml
Normal file
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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>
|
||||
<groupId>com.xiang</groupId>
|
||||
<artifactId>xservice-ai-center</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>xservice-service</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
</project>
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.xiang.xservice.ai.config;
|
||||
import com.alibaba.cloud.ai.dashscope.chat.DashScopeChatOptions;
|
||||
import com.alibaba.cloud.ai.memory.jdbc.MysqlChatMemoryRepository;
|
||||
import org.springframework.ai.chat.client.ChatClient;
|
||||
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
|
||||
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
|
||||
import org.springframework.ai.chat.memory.ChatMemory;
|
||||
import org.springframework.ai.chat.memory.MessageWindowChatMemory;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
|
||||
/**
|
||||
* 初始化llm客户端
|
||||
*/
|
||||
|
||||
@Configuration
|
||||
public class LlmClientConfig {
|
||||
|
||||
private static final String DEFAULT_PROMPT = "你是一个友好的AI助手,可以根据用户提出的问题进行解答";
|
||||
|
||||
@Bean
|
||||
public ChatClient initChatCLient(ChatClient.Builder charClientBuilder, ChatMemory chatMemory) {
|
||||
return charClientBuilder
|
||||
.defaultSystem(DEFAULT_PROMPT)
|
||||
.defaultAdvisors(
|
||||
new SimpleLoggerAdvisor(),
|
||||
MessageChatMemoryAdvisor.builder(chatMemory).build()
|
||||
)
|
||||
.defaultOptions(
|
||||
DashScopeChatOptions.builder().withTemperature(1.2).build()
|
||||
).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ChatMemory initChatMemory(JdbcTemplate jdbcTemplate) {
|
||||
return MessageWindowChatMemory.builder()
|
||||
.chatMemoryRepository(MysqlChatMemoryRepository.mysqlBuilder()
|
||||
.jdbcTemplate(jdbcTemplate)
|
||||
.build())
|
||||
.maxMessages(100)
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user