Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions backend/app/services/graph_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,13 @@ def safe_attr_name(attr_name: str) -> str:
annotations = {}

for attr_def in entity_def.get("attributes", []):
attr_name = safe_attr_name(attr_def["name"]) # 使用安全名称
attr_desc = attr_def.get("description", attr_name)
# LLM may return attributes as strings instead of dicts
if isinstance(attr_def, str):
attr_name = safe_attr_name(attr_def)
attr_desc = attr_def
else:
attr_name = safe_attr_name(attr_def["name"]) # 使用安全名称
attr_desc = attr_def.get("description", attr_name)
# Zep API 需要 Field 的 description,这是必需的
attrs[attr_name] = Field(description=attr_desc, default=None)
annotations[attr_name] = Optional[EntityText] # 类型注解
Expand All @@ -257,8 +262,13 @@ def safe_attr_name(attr_name: str) -> str:
annotations = {}

for attr_def in edge_def.get("attributes", []):
attr_name = safe_attr_name(attr_def["name"]) # 使用安全名称
attr_desc = attr_def.get("description", attr_name)
# LLM may return attributes as strings instead of dicts
if isinstance(attr_def, str):
attr_name = safe_attr_name(attr_def)
attr_desc = attr_def
else:
attr_name = safe_attr_name(attr_def["name"]) # 使用安全名称
attr_desc = attr_def.get("description", attr_name)
# Zep API 需要 Field 的 description,这是必需的
attrs[attr_name] = Field(description=attr_desc, default=None)
annotations[attr_name] = Optional[str] # 边属性用str类型
Expand Down
10 changes: 10 additions & 0 deletions backend/app/services/ontology_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@ def _validate_and_process(self, result: Dict[str, Any]) -> Dict[str, Any]:
entity_name_map[original_name] = entity["name"]
if "attributes" not in entity:
entity["attributes"] = []
# Normalize attributes: LLM may return strings instead of dicts
entity["attributes"] = [
attr if isinstance(attr, dict) else {"name": attr, "type": "text", "description": attr}
for attr in entity["attributes"]
]
if "examples" not in entity:
entity["examples"] = []
# 确保description不超过100字符
Expand All @@ -322,6 +327,11 @@ def _validate_and_process(self, result: Dict[str, Any]) -> Dict[str, Any]:
edge["source_targets"] = []
if "attributes" not in edge:
edge["attributes"] = []
# Normalize attributes: LLM may return strings instead of dicts
edge["attributes"] = [
attr if isinstance(attr, dict) else {"name": attr, "type": "text", "description": attr}
for attr in edge["attributes"]
]
if len(edge.get("description", "")) > 100:
edge["description"] = edge["description"][:97] + "..."

Expand Down