Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.
Go agentagenticaichatbotdsh-pluginembeddingsevaluationgenerative-aigolangknowledge-basellmmulti-tenantollamaopenaiquestion-answeringragrerankingsemantic-searchvector-searchwiki
refactor: update LLM configuration to model ID in API and frontend
wizardchen6abc688ea291
diff --git a/frontend/src/api/initialization/index.ts b/frontend/src/api/initialization/index.tsindex 21640130c..928cec6e1 100644--- a/frontend/src/api/initialization/index.ts+++ b/frontend/src/api/initialization/index.ts@@ -412,7 +412,7 @@ export function testMultimodalFunction(testData: {export interface TextRelationExtractionRequest {text: string;tags: string[];- llm_config: LLMConfig;+ model_id: string;}export interface Node {@@ -426,13 +426,6 @@ export interface Relation {type: string;}-export interface LLMConfig {- source: 'local' | 'remote';- model_name: string;- base_url: string;- api_key: string;-}-export interface TextRelationExtractionResponse {nodes: Node[];relations: Relation[];@@ -454,7 +447,7 @@ export function extractTextRelations(request: TextRelationExtractionRequest): Prexport interface FabriTextRequest {tags: string[];- llm_config: LLMConfig;+ model_id: string;}export interface FabriTextResponse {@@ -476,7 +469,6 @@ export function fabriText(request: FabriTextRequest): Promise<FabriTextResponse>}export interface FabriTagRequest {- llm_config: LLMConfig;}export interface FabriTagResponse {diff --git a/frontend/src/views/knowledge/KnowledgeBaseEditorModal.vue b/frontend/src/views/knowledge/KnowledgeBaseEditorModal.vueindex 4316de9f7..a7cf584e1 100644--- a/frontend/src/views/knowledge/KnowledgeBaseEditorModal.vue+++ b/frontend/src/views/knowledge/KnowledgeBaseEditorModal.vue@@ -150,6 +150,7 @@<GraphSettingsv-if="formData":graph-extract="formData.nodeExtractConfig"+ :model-id="formData.modelConfig.llmModelId":all-models="allModels"@update:graphExtract="handleNodeExtractUpdate"/>diff --git a/frontend/src/views/knowledge/settings/GraphSettings.vue b/frontend/src/views/knowledge/settings/GraphSettings.vueindex a548a1a59..ba243f711 100644--- a/frontend/src/views/knowledge/settings/GraphSettings.vue+++ b/frontend/src/views/knowledge/settings/GraphSettings.vue@@ -296,8 +296,7 @@import { ref, watch, onMounted, computed } from 'vue'import { MessagePlugin } from 'tdesign-vue-next'import { useI18n } from 'vue-i18n'-import { extractTextRelations, fabriText, fabriTag, type Node, type Relation, type LLMConfig } from '@/api/initialization'-import { listModels } from '@/api/model'+import { extractTextRelations, fabriText, fabriTag, type Node, type Relation } from '@/api/initialization'import { getSystemInfo } from '@/api/system'const { t } = useI18n()@@ -312,6 +311,7 @@ interface GraphExtractConfig {interface Props {graphExtract: GraphExtractConfig+ modelId: stringallModels?: any[]}@@ -333,14 +333,6 @@ const tagFabring = ref(false)const textFabring = ref(false)const extracting = ref(false)-// 模型状态-const modelStatus = ref({- llm: {- available: false,- config: null as LLMConfig | null- }-})-// 系统信息const systemInfo = ref<any>(null)@@ -438,16 +430,9 @@ const removeRelation = (index: number) => {// 生成随机标签const handleFabriTag = async () => {- if (!modelStatus.value.llm.available || !modelStatus.value.llm.config) {- MessagePlugin.warning(t('graphSettings.completeModelConfig'))- return- }-tagFabring.value = truetry {- const response = await fabriTag({- llm_config: modelStatus.value.llm.config- })+ const response = await fabriTag({})localGraphExtract.value.tags = response.tags || []handleTagsChange()MessagePlugin.success(t('graphSettings.tagsGenerated'))@@ -461,7 +446,7 @@ const handleFabriTag = async () => {// 生成随机文本const handleFabriText = async () => {- if (!modelStatus.value.llm.available || !modelStatus.value.llm.config) {+ if (!props.modelId) {MessagePlugin.warning(t('graphSettings.completeModelConfig'))return}@@ -470,7 +455,7 @@ const handleFabriText = async () => {try {const response = await fabriText({tags: localGraphExtract.value.tags,- llm_config: modelStatus.value.llm.config+ model_id: props.modelId})localGraphExtract.value.text = response.text || ''handleTextChange()@@ -485,7 +470,7 @@ const handleFabriText = async () => {// 提取实体关系const handleExtract = async () => {- if (!modelStatus.value.llm.available || !modelStatus.value.llm.config) {+ if (!props.modelId) {MessagePlugin.warning(t('graphSettings.completeModelConfig'))return}@@ -500,7 +485,7 @@ const handleExtract = async () => {const response = await extractTextRelations({text: localGraphExtract.value.text,tags: localGraphExtract.value.tags,- llm_config: modelStatus.value.llm.config+ model_id: props.modelId})localGraphExtract.value.nodes = response.nodes || []localGraphExtract.value.relations = response.relations || []@@ -543,28 +528,6 @@ const clearExtractExample = () => {MessagePlugin.success(t('graphSettings.exampleCleared'))}-// 加载模型状态-const loadModelStatus = async () => {- try {- const models = await listModels()-- // 查找可用的KnowledgeQA模型(对话模型)- const llmModels = models.filter((m: any) => m.type === 'KnowledgeQA')- if (llmModels.length > 0) {- const llmModel = llmModels[0]- modelStatus.value.llm.available = true- modelStatus.value.llm.config = {- source: llmModel.source,- model_name: llmModel.name,- base_url: llmModel.parameters?.base_url || '',- api_key: llmModel.parameters?.api_key || ''- }- }- } catch (error: any) {- console.error('Failed to load model status:', error)- }-}-// 加载系统信息const loadSystemInfo = async () => {try {@@ -586,10 +549,7 @@ const handleOpenGraphGuide = () => {// 初始化onMounted(async () => {- await Promise.all([- loadModelStatus(),- loadSystemInfo()- ])+ await loadSystemInfo()})</script>diff --git a/internal/handler/initialization.go b/internal/handler/initialization.goindex 4f77bd8a4..79c36c5c6 100644--- a/internal/handler/initialization.go+++ b/internal/handler/initialization.go@@ -1952,16 +1952,9 @@ func (h *InitializationHandler) testMultimodalWithDocReader(// TextRelationExtractionRequest 文本关系提取请求结构type TextRelationExtractionRequest struct {- Text string `json:"text" binding:"required"`- Tags []string `json:"tags" binding:"required"`- LLMConfig LLMConfig `json:"llm_config"`-}--type LLMConfig struct {- Source string `json:"source"`- ModelName string `json:"model_name"`- BaseUrl string `json:"base_url"`- ApiKey string `json:"api_key"`+ Text string `json:"text" binding:"required"`+ Tags []string `json:"tags" binding:"required"`+ ModelID string `json:"model_id" binding:"required"`}// TextRelationExtractionResponse 文本关系提取响应结构@@ -2009,8 +2002,16 @@ func (h *InitializationHandler) ExtractTextRelations(c *gin.Context) {return}+ // 根据模型ID获取chat模型+ chatModel, err := h.modelService.GetChatModel(ctx, req.ModelID)+ if err != nil {+ logger.Error(ctx, "获取模型失败", err)+ c.Error(errors.NewBadRequestError("获取模型失败: " + err.Error()))+ return+ }+// 调用模型服务进行文本关系提取- result, err := h.extractRelationsFromText(ctx, req.Text, req.Tags, req.LLMConfig)+ result, err := h.extractRelationsFromText(ctx, req.Text, req.Tags, chatModel)if err != nil {logger.Error(ctx, "文本关系提取失败", err)c.Error(errors.NewInternalServerError("文本关系提取失败: " + err.Error()))@@ -2028,20 +2029,8 @@ func (h *InitializationHandler) extractRelationsFromText(ctx context.Context,text string,tags []string,- llm LLMConfig,+ chatModel chat.Chat,) (*TextRelationExtractionResponse, error) {- chatModel, err := chat.NewChat(&chat.ChatConfig{- ModelID: "initialization",- APIKey: llm.ApiKey,- BaseURL: llm.BaseUrl,- ModelName: llm.ModelName,- Source: types.ModelSource(llm.Source),- }, h.ollamaService)- if err != nil {- logger.Error(ctx, "初始化模型服务失败", err)- return nil, err- }-template := &types.PromptTemplateStructured{Description: h.config.ExtractManager.ExtractGraph.Description,Tags: tags,@@ -2066,8 +2055,8 @@ func (h *InitializationHandler) extractRelationsFromText(// FabriTextRequest is a request for generating example texttype FabriTextRequest struct {- Tags []string `json:"tags"`- LLMConfig LLMConfig `json:"llm_config"`+ Tags []string `json:"tags"`+ ModelID string `json:"model_id" binding:"required"`}// FabriTextResponse is a response for generating example text@@ -2097,7 +2086,14 @@ func (h *InitializationHandler) FabriText(c *gin.Context) {return}- result, err := h.fabriText(ctx, req.Tags, req.LLMConfig)+ chatModel, err := h.modelService.GetChatModel(ctx, req.ModelID)+ if err != nil {+ logger.Error(ctx, "获取模型失败", err)+ c.Error(errors.NewBadRequestError("获取模型失败: " + err.Error()))+ return+ }++ result, err := h.fabriText(ctx, req.Tags, chatModel)if err != nil {logger.Error(ctx, "failed to generate fabri text", err)c.Error(errors.NewInternalServerError("failed to generate fabri text: " + err.Error()))@@ -2111,19 +2107,7 @@ func (h *InitializationHandler) FabriText(c *gin.Context) {}// fabriText generates example text-func (h *InitializationHandler) fabriText(ctx context.Context, tags []string, llm LLMConfig) (string, error) {- chatModel, err := chat.NewChat(&chat.ChatConfig{- ModelID: "initialization",- APIKey: llm.ApiKey,- BaseURL: llm.BaseUrl,- ModelName: llm.ModelName,- Source: types.ModelSource(llm.Source),- }, h.ollamaService)- if err != nil {- logger.Error(ctx, "初始化模型服务失败", err)- return "", err- }-+func (h *InitializationHandler) fabriText(ctx context.Context, tags []string, chatModel chat.Chat) (string, error) {content := h.config.ExtractManager.FabriText.WithNoTagif len(tags) > 0 {tagStr, _ := json.Marshal(tags)@@ -2146,9 +2130,7 @@ func (h *InitializationHandler) fabriText(ctx context.Context, tags []string, ll}// FabriTagRequest is a request for generating tags-type FabriTagRequest struct {- LLMConfig LLMConfig `json:"llm_config"`-}+type FabriTagRequest struct{}// FabriTagResponse is a response for generating tagstype FabriTagResponse struct {