Add knowledge retrieval configuration to Assistant model and related components
- Introduce new fields for knowledge retrieval configuration in AssistantConfig and Assistant models, including mode, top_n, and score_threshold. - Implement KnowledgeRetrievalConfig schema with validation for top_n. - Update backend services and routes to handle knowledge retrieval settings. - Enhance frontend components to support knowledge retrieval configuration, including a new dialog for advanced settings. - Add tests for knowledge retrieval configuration validation and description generation.
This commit is contained in:
38
backend/tests/test_pipeline_knowledge.py
Normal file
38
backend/tests/test_pipeline_knowledge.py
Normal file
@@ -0,0 +1,38 @@
|
||||
import unittest
|
||||
|
||||
from models import AssistantConfig
|
||||
from services.pipecat.pipeline import _knowledge_tool_description
|
||||
|
||||
|
||||
class KnowledgeToolDescriptionTest(unittest.TestCase):
|
||||
def test_includes_bound_knowledge_scope(self):
|
||||
description = _knowledge_tool_description(
|
||||
AssistantConfig(
|
||||
knowledge_base_name="产品服务知识库",
|
||||
knowledge_base_description="产品价格、售后政策和退换货条件",
|
||||
)
|
||||
)
|
||||
|
||||
self.assertIn("知识库名称:产品服务知识库", description)
|
||||
self.assertIn("资料适用范围:产品价格、售后政策和退换货条件", description)
|
||||
self.assertIn("与该范围无关的问题不要调用", description)
|
||||
|
||||
def test_falls_back_when_metadata_is_empty(self):
|
||||
description = _knowledge_tool_description(AssistantConfig())
|
||||
|
||||
self.assertEqual(
|
||||
description,
|
||||
"在当前助手绑定的知识库中检索与问题最相关的资料片段。",
|
||||
)
|
||||
|
||||
def test_compacts_and_limits_description(self):
|
||||
description = _knowledge_tool_description(
|
||||
AssistantConfig(knowledge_base_description=("范围\n 内容 " * 200))
|
||||
)
|
||||
|
||||
self.assertNotIn("\n ", description)
|
||||
self.assertLess(len(description), 1000)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user