Copilot commented on code in PR #351:
URL: https://github.com/apache/hugegraph-ai/pull/351#discussion_r3330297071
##########
hugegraph-llm/src/hugegraph_llm/api/models/rag_requests.py:
##########
@@ -164,3 +165,43 @@ def validate_prompt_placeholders(cls, v):
if missing:
raise ValueError(f"Prompt template is missing required
placeholders: {', '.join(missing)}")
return v
+
+
+class GraphExtractRequest(BaseModel):
+ model_config = ConfigDict(populate_by_name=True)
+
+ texts: Union[str, List[str]] = Field(..., description="Text or list of
texts to extract a graph from.")
+ graph_schema: Union[str, Dict[str, Any]] = Field(
+ ...,
+ alias="schema",
+ description="Graph schema as a JSON string/object, or an existing
graph name.",
+ )
+ example_prompt: Optional[str] = Query(None, description="Optional graph
extraction prompt header.")
+ extract_type: str = Query("property_graph", description="Extraction type.")
Review Comment:
`extract_type` is exposed as an unconstrained string, but `ExtractNode` only
supports `"triples"` and `"property_graph"`. Any other value passes request
validation and then fails during flow initialization, which this endpoint
converts to a 500 instead of a client-side 422.
##########
hugegraph-llm/src/hugegraph_llm/api/models/rag_requests.py:
##########
@@ -164,3 +165,43 @@ def validate_prompt_placeholders(cls, v):
if missing:
raise ValueError(f"Prompt template is missing required
placeholders: {', '.join(missing)}")
return v
+
+
+class GraphExtractRequest(BaseModel):
+ model_config = ConfigDict(populate_by_name=True)
+
+ texts: Union[str, List[str]] = Field(..., description="Text or list of
texts to extract a graph from.")
+ graph_schema: Union[str, Dict[str, Any]] = Field(
+ ...,
+ alias="schema",
+ description="Graph schema as a JSON string/object, or an existing
graph name.",
+ )
+ example_prompt: Optional[str] = Query(None, description="Optional graph
extraction prompt header.")
+ extract_type: str = Query("property_graph", description="Extraction type.")
+ language: Literal["zh", "en"] = Query("zh", description="Language for
chunk splitting.")
+ split_type: Literal["document", "paragraph", "sentence"] =
Query("document", description="Chunk split granularity.")
+ include_meta: bool = Query(False, description="Include vertex/edge/text
counts in the response.")
+
+ @field_validator("texts")
+ @classmethod
+ def normalize_texts(cls, v):
+ items = [v] if isinstance(v, str) else list(v)
+ items = [t for t in items if t and t.strip()]
+ if not items:
+ raise ValueError("texts must not be empty.")
+ return items
+
+ @field_validator("graph_schema")
+ @classmethod
+ def normalize_schema(cls, v):
+ if isinstance(v, dict):
+ return json.dumps(v, ensure_ascii=False)
+ v = v.strip()
+ if not v:
+ raise ValueError("schema must not be empty.")
+ if v.startswith("{"):
+ try:
+ json.loads(v)
+ except json.JSONDecodeError as e:
+ raise ValueError(f"Invalid JSON schema: {e}") from e
+ return v
Review Comment:
Object schemas are accepted after only being JSON-serialized, so inputs that
the flow cannot use (for example `{"vertexlabels": []}` without `edgelabels`)
pass validation and later fail inside `CheckSchema`, producing a 500. Validate
the JSON schema shape here so bad client input is returned as a 422 before
scheduling the flow.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]