20250329 通过application配置apikey以及model
This commit is contained in:
parent
4fbeca899b
commit
ee3f64a5c6
@ -13,6 +13,7 @@ import dev.langchain4j.service.AiServices;
|
|||||||
import dev.langchain4j.store.embedding.EmbeddingStoreIngestor;
|
import dev.langchain4j.store.embedding.EmbeddingStoreIngestor;
|
||||||
import dev.langchain4j.store.embedding.inmemory.InMemoryEmbeddingStore;
|
import dev.langchain4j.store.embedding.inmemory.InMemoryEmbeddingStore;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
@ -24,11 +25,17 @@ public class AssistantInit {
|
|||||||
|
|
||||||
// All files in a directory, txt seems to be faster
|
// All files in a directory, txt seems to be faster
|
||||||
|
|
||||||
|
@Value("${langchain4j.api-key}")
|
||||||
|
private String apiKey;
|
||||||
|
|
||||||
|
@Value("${langchain4j.model}")
|
||||||
|
private String model;
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public Assist init() {
|
public Assist init() {
|
||||||
ChatLanguageModel qwenModel = QwenChatModel.builder()
|
ChatLanguageModel qwenModel = QwenChatModel.builder()
|
||||||
.apiKey("sk-2f703a41fff0488e9b6888013d2ee58a")
|
.apiKey(apiKey)
|
||||||
.modelName("deepseek-v3")
|
.modelName(model)
|
||||||
.build();
|
.build();
|
||||||
List<Document> documents = FileSystemDocumentLoader.loadDocuments("E:\\ideaProject\\liang-ai");
|
List<Document> documents = FileSystemDocumentLoader.loadDocuments("E:\\ideaProject\\liang-ai");
|
||||||
// for simplicity, we will use an in-memory one:
|
// for simplicity, we will use an in-memory one:
|
||||||
@ -38,7 +45,7 @@ public class AssistantInit {
|
|||||||
.chatMemoryProvider(memoryId -> MessageWindowChatMemory.withMaxMessages(10))
|
.chatMemoryProvider(memoryId -> MessageWindowChatMemory.withMaxMessages(10))
|
||||||
.chatLanguageModel(qwenModel)
|
.chatLanguageModel(qwenModel)
|
||||||
.contentRetriever(EmbeddingStoreContentRetriever.from(embeddingStore))
|
.contentRetriever(EmbeddingStoreContentRetriever.from(embeddingStore))
|
||||||
.tools(new MyCalculator())
|
// .tools(new MyCalculator())
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,3 +2,7 @@ server.port=8080
|
|||||||
|
|
||||||
langchain4j.community.dashscope.chat-model.api-key=sk-2f703a41fff0488e9b6888013d2ee58a
|
langchain4j.community.dashscope.chat-model.api-key=sk-2f703a41fff0488e9b6888013d2ee58a
|
||||||
langchain4j.community.dashscope.chat-model.model-name=deepseek-v3
|
langchain4j.community.dashscope.chat-model.model-name=deepseek-v3
|
||||||
|
|
||||||
|
|
||||||
|
langchain4j.api-key=sk-2f703a41fff0488e9b6888013d2ee58a
|
||||||
|
langchain4j.model=deepseek-v3
|
Loading…
Reference in New Issue
Block a user