Spaces:
Sleeping
Sleeping
Download src/modules/knowledge/application/catalog.py from dellweb3/VibeCoding: direct link, hf CLI and curl.
- Browser
- Download file 1.87 kB
-
https://huggingface.co/spaces/dellweb3/VibeCoding/resolve/main/src/modules/knowledge/application/catalog.py
- Command line
-
hf download hf://spaces/dellweb3/VibeCoding/src/modules/knowledge/application/catalog.py
-
curl -L -o catalog.py https://huggingface.co/spaces/dellweb3/VibeCoding/resolve/main/src/modules/knowledge/application/catalog.py
1.87 kB
| """Knowledge management/query use cases; corpus IO and indexes stay in adapters.""" | |
| from src.modules.skill.domain.models import SkillError | |
| class KnowledgeCatalog: | |
| def __init__(self, repository): | |
| self.repository = repository | |
| def collections(self, actor): | |
| return self.repository.collections(actor) | |
| def resolve(self, actor, binding): | |
| collection = self.repository.collection(actor, binding.collection_id) | |
| if collection["revision"] != binding.revision: | |
| raise SkillError("KNOWLEDGE_REVISION_MISMATCH", "知识版本不匹配。", 409) | |
| if collection["status"] != "reference_ready": | |
| raise SkillError("KNOWLEDGE_NOT_READY", "知识库尚不可用于检索。", 409) | |
| if binding.usage == "enterprise-rule" and not collection["enterprise_approved"]: | |
| raise SkillError("ENTERPRISE_RULE_NOT_APPROVED", "公开参考资料不是企业已批准规约。", 409) | |
| return {"collection_id": collection["collection_id"], "revision": collection["revision"], | |
| "digest": collection["digest"], "scope": binding.usage, | |
| "quality_status": collection["quality_status"], "enterprise_approved": collection["enterprise_approved"]} | |
| def search(self, actor, query, collection_ids, limit=8, *, for_code_reuse=False): | |
| if not query.strip() or len(query) > 300 or not 1 <= len(collection_ids) <= 10 or not 1 <= limit <= 20: | |
| raise SkillError("INVALID_SEARCH", "检索条件超出范围。") | |
| for cid in collection_ids: | |
| collection = self.repository.collection(actor, cid) | |
| if collection["status"] != "reference_ready": | |
| raise SkillError("KNOWLEDGE_NOT_READY", "知识库不可用于检索。", 409) | |
| return self.repository.search(actor, query, collection_ids, limit, for_code_reuse=for_code_reuse) | |