mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-15 17:30:13 +08:00
feat: remove tips from knowledge base creation form and add persistent hints for field modifications
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from ..context import PipelineContext
|
||||
from astrbot.core.provider.entities import ProviderRequest
|
||||
from astrbot.api import logger
|
||||
from astrbot.api import logger, sp
|
||||
|
||||
|
||||
async def inject_kb_context(
|
||||
@@ -15,7 +15,6 @@ async def inject_kb_context(
|
||||
p_ctx: Pipeline context
|
||||
req: Provider request
|
||||
"""
|
||||
from astrbot.core import sp
|
||||
|
||||
kb_mgr = p_ctx.plugin_manager.context.kb_manager
|
||||
|
||||
@@ -23,12 +22,12 @@ async def inject_kb_context(
|
||||
session_config = await sp.session_get(umo, "kb_config", default={})
|
||||
|
||||
if session_config and "kb_ids" in session_config:
|
||||
# 使用会话级配置
|
||||
# 会话级配置
|
||||
kb_ids = session_config.get("kb_ids", [])
|
||||
|
||||
# 如果配置为空列表,明确表示不使用知识库
|
||||
if not kb_ids:
|
||||
logger.info(f"[KB注入] 会话 {umo} 已配置为不使用知识库")
|
||||
logger.info(f"[知识库] 会话 {umo} 已被配置为不使用知识库")
|
||||
return
|
||||
|
||||
top_k = session_config.get("top_k", 5)
|
||||
@@ -41,33 +40,29 @@ async def inject_kb_context(
|
||||
if kb_helper:
|
||||
kb_names.append(kb_helper.kb.kb_name)
|
||||
else:
|
||||
logger.warning(f"[KB注入] 知识库不存在或未加载: {kb_id}")
|
||||
logger.warning(f"[知识库] 知识库不存在或未加载: {kb_id}")
|
||||
invalid_kb_ids.append(kb_id)
|
||||
|
||||
if invalid_kb_ids:
|
||||
logger.warning(
|
||||
f"[KB注入] 会话 {umo} 配置的以下知识库无效: {invalid_kb_ids}"
|
||||
f"[知识库] 会话 {umo} 配置的以下知识库无效: {invalid_kb_ids}"
|
||||
)
|
||||
|
||||
if not kb_names:
|
||||
logger.warning(
|
||||
f"[KB注入] 会话 {umo} 配置的所有知识库都无效,跳过知识库上下文注入"
|
||||
)
|
||||
return
|
||||
|
||||
logger.debug(f"[KB注入] 使用会话级配置,知识库数量: {len(kb_names)}")
|
||||
logger.debug(f"[知识库] 使用会话级配置,知识库数量: {len(kb_names)}")
|
||||
else:
|
||||
# 回退到全局配置
|
||||
kb_names = p_ctx.astrbot_config.get("kb_names", [])
|
||||
top_k = p_ctx.astrbot_config.get("kb_final_top_k", 5)
|
||||
logger.debug(f"[KB注入] 使用全局配置,知识库数量: {len(kb_names)}")
|
||||
logger.debug(f"[知识库] 使用全局配置,知识库数量: {len(kb_names)}")
|
||||
|
||||
top_k_fusion = p_ctx.astrbot_config.get("kb_fusion_top_k", 20)
|
||||
|
||||
if not kb_names:
|
||||
return
|
||||
|
||||
logger.debug(f"[KB注入] 开始检索知识库,数量: {len(kb_names)}, top_k={top_k}")
|
||||
logger.debug(f"[知识库] 开始检索知识库,数量: {len(kb_names)}, top_k={top_k}")
|
||||
kb_context = await kb_mgr.retrieve(
|
||||
query=req.prompt,
|
||||
kb_names=kb_names,
|
||||
@@ -81,5 +76,5 @@ async def inject_kb_context(
|
||||
formatted = kb_context.get("context_text", "")
|
||||
if formatted:
|
||||
results = kb_context.get("results", [])
|
||||
logger.debug(f"[KB注入] 为会话 {umo} 注入了 {len(results)} 条相关知识块")
|
||||
logger.debug(f"[知识库] 为会话 {umo} 注入了 {len(results)} 条相关知识块")
|
||||
req.system_prompt = f"{formatted}\n\n{req.system_prompt or ''}"
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
"rerankModelLabel": "Rerank Model (Optional)",
|
||||
"providerInfo": "Provider: {id} | Dimensions: {dimensions}",
|
||||
"rerankProviderInfo": "Provider: {id}",
|
||||
"tips": "Tip: Once you select an embedding model, do not modify the model or vector dimensions, as this will severely affect recall rate.",
|
||||
"cancel": "Cancel",
|
||||
"submit": "Create",
|
||||
"nameRequired": "Please enter knowledge base name"
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
"rerankModelLabel": "重排序模型 (Rerank Model, 可选)",
|
||||
"providerInfo": "提供商: {id} | 维度: {dimensions}",
|
||||
"rerankProviderInfo": "提供商: {id}",
|
||||
"tips": "提示: 一旦选择了嵌入模型,请不要修改该提供商的模型或向量维度,否则将严重影响召回率。",
|
||||
"cancel": "取消",
|
||||
"submit": "创建",
|
||||
"nameRequired": "请输入知识库名称"
|
||||
|
||||
@@ -87,14 +87,14 @@
|
||||
<v-form ref="formRef" @submit.prevent="submitForm">
|
||||
<v-text-field v-model="formData.kb_name" :label="t('create.nameLabel')"
|
||||
:placeholder="t('create.namePlaceholder')" variant="outlined"
|
||||
:rules="[v => !!v || t('create.nameRequired')]" required class="mb-4" />
|
||||
:rules="[v => !!v || t('create.nameRequired')]" required class="mb-4" hint="后续如修改知识库名称,需重新在配置文件更新。" persistent-hint />
|
||||
|
||||
<v-textarea v-model="formData.description" :label="t('create.descriptionLabel')"
|
||||
:placeholder="t('create.descriptionPlaceholder')" variant="outlined" rows="3" class="mb-4" />
|
||||
|
||||
<v-select v-model="formData.embedding_provider_id" :items="embeddingProviders"
|
||||
:item-title="item => item.embedding_model || item.id" :item-value="'id'"
|
||||
:label="t('create.embeddingModelLabel')" variant="outlined" class="mb-4" :disabled="editingKB !== null">
|
||||
:label="t('create.embeddingModelLabel')" variant="outlined" class="mb-4" :disabled="editingKB !== null" hint="嵌入模型选择后无法修改,如需更换请创建新的知识库。" persistent-hint>
|
||||
<template #item="{ props, item }">
|
||||
<v-list-item v-bind="props">
|
||||
<template #subtitle>
|
||||
@@ -118,10 +118,6 @@
|
||||
</v-list-item>
|
||||
</template>
|
||||
</v-select>
|
||||
|
||||
<v-alert type="info" variant="tonal" density="compact" class="mt-4">
|
||||
{{ t('create.tips') }}
|
||||
</v-alert>
|
||||
</v-form>
|
||||
</v-card-text>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user