fix: Solve the problem of invalid subgraph naming when creating tugraph (#1731)

This commit is contained in:
A-Salty-Fish 2024-07-22 19:13:52 +08:00 committed by GitHub
parent f889fa3775
commit 84988b89fe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,5 +1,6 @@
import json
import logging
import re
from datetime import datetime
from dbgpt._private.config import Config
@ -79,6 +80,10 @@ class KnowledgeService:
)
if request.vector_type == "VectorStore":
request.vector_type = CFG.VECTOR_STORE_TYPE
if request.vector_type == "KnowledgeGraph":
knowledge_space_name_pattern = r"^[a-zA-Z0-9\u4e00-\u9fa5]+$"
if not re.match(knowledge_space_name_pattern, request.name):
raise Exception(f"space name:{request.name} invalid")
spaces = knowledge_space_dao.get_knowledge_space(query)
if len(spaces) > 0:
raise Exception(f"space name:{request.name} have already named")