Files
ai-video-fullstack/backend/tests/test_pipeline_knowledge.py
Xin Wang 32aef14ddb Add workflow support and enhance runtime configuration in models and services
- Introduce RuntimeModelResource and RuntimeKnowledgeBase classes to manage workflow resources.
- Update AssistantConfig to include workflow_model_resources and workflow_knowledge_bases for better integration.
- Refactor validation and processing logic in routes and services to accommodate workflow types.
- Implement dynamic variable support for workflow assistants and enhance graph normalization.
- Add ToolExecutor for reusable tool execution across different assistant types.
- Update various services to ensure compatibility with new workflow features and improve error handling.
2026-07-13 16:13:27 +08:00

62 lines
2.1 KiB
Python

import unittest
from models import AssistantConfig
from services.pipecat.pipeline import (
KNOWLEDGE_CONTEXT_MARKER,
KnowledgeRetrievalProcessor,
_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)
def test_workflow_knowledge_uses_system_role(self):
processor = KnowledgeRetrievalProcessor(None)
messages = [
{"role": "assistant", "content": "你好"},
{
"role": "developer",
"content": f"{KNOWLEDGE_CONTEXT_MARKER}\n旧检索结果",
},
]
processor._set_context(
messages,
f"{KNOWLEDGE_CONTEXT_MARKER}\n新检索结果",
)
self.assertEqual(messages[0]["role"], "system")
self.assertIn("新检索结果", messages[0]["content"])
self.assertFalse(any(message["role"] == "developer" for message in messages))
if __name__ == "__main__":
unittest.main()