Commit 62500905 authored by 林洋洋's avatar 林洋洋

修改适配VLLM

parent 2d0f6bc2
......@@ -59,13 +59,19 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-model-ollama</artifactId>
</dependency>
<!-- undertow容器 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
<dependency>
<groupId>io.projectreactor.netty</groupId>
<artifactId>reactor-netty-http</artifactId>
</dependency>
<!-- SpringBoot Actuator -->
<dependency>
<groupId>org.springframework.boot</groupId>
......
......@@ -11,13 +11,18 @@ import org.springframework.ai.chat.memory.repository.jdbc.JdbcChatMemoryReposito
import org.springframework.ai.chat.prompt.PromptTemplate;
import org.springframework.ai.deepseek.DeepSeekChatModel;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.ai.openai.api.OpenAiApi;
import org.springframework.ai.rag.advisor.RetrievalAugmentationAdvisor;
import org.springframework.ai.rag.generation.augmentation.ContextualQueryAugmenter;
import org.springframework.ai.rag.retrieval.search.VectorStoreDocumentRetriever;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.netty.http.HttpProtocol;
import reactor.netty.http.client.HttpClient;
import java.util.ArrayList;
import java.util.List;
......@@ -25,7 +30,13 @@ import java.util.List;
@Configuration
public class CommonConfiguration {
@Bean
public WebClient.Builder openAiWebClientBuilder() {
return WebClient.builder()
.clientConnector(new ReactorClientHttpConnector(
HttpClient.create().protocol(HttpProtocol.HTTP11)
));
}
@Bean
public ChatMemory chatMemory(JdbcTemplate jdbcTemplate, PostgresChatMemoryDialect postgresChatMemoryDialect) {
ChatMemoryRepository chatMemoryRepository = JdbcChatMemoryRepository.builder()
......
......@@ -109,7 +109,7 @@ public class ChatController {
Message userMessage = new UserMessage(message);
Prompt prompt = new Prompt(List.of(systemMessage, userMessage));
return FluxUtils.wrapDeepSeekStream(openAiChatClient.prompt(prompt)
return FluxUtils.wrapDeepSeekStream(deepseekChatClient.prompt(prompt)
.advisors(messageChatMemoryAdvisor)
.advisors(a -> a.param(ChatMemory.CONVERSATION_ID, conversationId))
.stream()
......@@ -145,7 +145,7 @@ public class ChatController {
String userPrompt = ragPromptService.createRagPrompt(message, context, historyMemory);
StringBuilder contentBuilder = new StringBuilder();
return FluxUtils.wrapDeepSeekStream(openAiChatClient.prompt()
return FluxUtils.wrapDeepSeekStream(deepseekChatClient.prompt()
.user(userPrompt)
.system("你是一个智能助手,基于以下上下文和历史对话回答问题,请用简洁的语言回答问题,并确保答案准确,要求" +
"1.以 Markdown 格式输出")
......
......@@ -42,7 +42,7 @@ import java.util.stream.Collectors;
public class AskVectorStoreServiceImpl extends ServiceImpl<AskVectorStoreMapper, AskVectorStore> implements AskVectorStoreService {
@Autowired
private EmbeddingModel embeddingModel;
private EmbeddingModel ollamaEmbeddingModel;
@Autowired
private JdbcTemplate jdbcTemplate;
......@@ -74,7 +74,7 @@ public class AskVectorStoreServiceImpl extends ServiceImpl<AskVectorStoreMapper,
String result = (title == null || title.trim().isEmpty()) ?
(content == null ? "" : content) :
title.trim() + "\n" + (content == null ? "" : content);
return embeddingModel.embed(result);
return ollamaEmbeddingModel.embed(result);
})
.toList();
......
......@@ -18,6 +18,8 @@ spring:
password: e5d039e4ba5246068
driver-class-name: org.postgresql.Driver
ai:
model:
embedding: ollama
vectorstore:
pgvector:
index-type: HNSW
......@@ -38,11 +40,7 @@ spring:
chat:
options:
model: deepseek-r1-0528
embedding:
base-url: https://dashscope.aliyuncs.com/compatible-mode
api-key: sk-ae96ff281ff644c992843c64a711a950
options:
model: text-embedding-v4
deepseek:
base-url: https://dashscope.aliyuncs.com/compatible-mode/v1
api-key: sk-ae96ff281ff644c992843c64a711a950
......@@ -50,6 +48,11 @@ spring:
enabled: true
options:
model: deepseek-r1-0528
ollama:
base-url: http://127.0.0.1:11434
embedding:
options:
model: nomic-embed-text
mybatis-plus:
mapper-locations: classpath*:/mapper/*Mapper.xml # mapper文件位置
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment