LRriver commented on code in PR #361:
URL: https://github.com/apache/hugegraph-ai/pull/361#discussion_r3379134606


##########
hugegraph-llm/src/hugegraph_llm/operators/hugegraph_op/commit_to_hugegraph.py:
##########
@@ -27,31 +27,51 @@
 
 
 class Commit2Graph:
-    def __init__(self):
+    def __init__(self, graph_config=None):
+        graph_config = graph_config or {}
         self.client = PyHugeClient(
-            url=huge_settings.graph_url,
-            graph=huge_settings.graph_name,
-            user=huge_settings.graph_user,
-            pwd=huge_settings.graph_pwd,
-            graphspace=huge_settings.graph_space,
+            url=graph_config.get("url") or huge_settings.graph_url,
+            graph=graph_config.get("graph") or huge_settings.graph_name,
+            user=graph_config.get("user") or huge_settings.graph_user,
+            pwd=graph_config.get("pwd") or huge_settings.graph_pwd,
+            graphspace=graph_config.get("gs") or huge_settings.graph_space,
         )
         self.schema = self.client.schema()
 
+    def _empty_import_result(self, vertices=None, edges=None, triples=None) -> 
Dict[str, Any]:
+        return {
+            "vertices_attempted": len(vertices or []),
+            "vertices_created": 0,
+            "vertices_skipped": 0,
+            "edges_attempted": len(edges or []),
+            "edges_created": 0,
+            "edges_skipped": 0,
+            "triples_attempted": len(triples or []),
+            "triples_created": 0,
+            "triples_skipped": 0,
+            "errors": [],
+        }
+
     def run(self, data: dict) -> Dict[str, Any]:
         schema = data.get("schema")
-        vertices = data.get("vertices", [])
-        edges = data.get("edges", [])
-        if not vertices and not edges:
+        vertices = data.get("vertices", []) or []
+        edges = data.get("edges", []) or []
+        triples = data.get("triples", []) or []
+        if not vertices and not edges and not triples:
             log.critical("(Loading) Both vertices and edges are empty. Please 
check the input data again.")
             raise ValueError("Both vertices and edges input are empty.")
 
         if not schema:
             # TODO: ensure the function works correctly (update the logic 
later)
-            self.schema_free_mode(data.get("triples", []))
+            import_result = self.schema_free_mode(triples)
             log.warning("Using schema_free mode, could try schema_define mode 
for better effect!")
         else:
+            if not vertices and not edges:
+                log.critical("(Loading) Both vertices and edges are empty. 
Please check the input data again.")
+                raise ValueError("Both vertices and edges input are empty.")

Review Comment:
   Fixed in 7850be7. Empty input messages now mention vertices, edges, and 
triples. Schema-free mode rejects vertices or edges, and schema mode rejects 
triples so mixed inputs are not silently dropped. Added regression coverage.



##########
hugegraph-llm/src/hugegraph_llm/api/graph_extract_api.py:
##########
@@ -15,55 +15,270 @@
 # specific language governing permissions and limitations
 # under the License.
 
-import json
+from typing import Optional
 
-from fastapi import APIRouter, HTTPException, status
+from fastapi import APIRouter, HTTPException, Request, status
+from fastapi.exceptions import RequestValidationError
+from fastapi.responses import JSONResponse
+from fastapi.routing import APIRoute
 
-from hugegraph_llm.api.models.graph_extract_requests import GraphExtractRequest
-from hugegraph_llm.api.models.graph_extract_responses import 
GraphExtractResponse
-from hugegraph_llm.config import prompt
-from hugegraph_llm.flows import FlowName
-from hugegraph_llm.flows.scheduler import SchedulerSingleton
+from hugegraph_llm.api.models.graph_extract_requests import (
+    GraphExtractAndImportRequest,
+    GraphExtractRequest,
+    GraphImportRequest,
+)
+from hugegraph_llm.api.models.graph_extract_responses import (
+    GraphExtractAndImportResponse,
+    GraphExtractError,
+    GraphExtractJobCreateResponse,
+    GraphExtractJobStatusResponse,
+    GraphExtractResponse,
+    GraphImportResponse,
+)
+from hugegraph_llm.services.graph_extract_jobs import (
+    GraphExtractJob,
+    GraphExtractJobStatus,
+    InMemoryGraphExtractJobStore,
+)
+from hugegraph_llm.services.graph_extract_service import GraphExtractService, 
GraphImportService
 from hugegraph_llm.utils.log import log
 
 
-class GraphExtractService:
-    @staticmethod
-    def extract_sync(req: GraphExtractRequest) -> GraphExtractResponse:
+def _error(code: str, message: str, phase: str, job_id: Optional[str] = None) 
-> dict:
+    return GraphExtractError(code=code, message=message, phase=phase, 
job_id=job_id).model_dump(exclude_none=True)
+
+
+def _job_ts(value) -> Optional[str]:
+    return value.isoformat() if value else None
+
+
+def _job_status_response(job: GraphExtractJob) -> 
GraphExtractJobStatusResponse:
+    return GraphExtractJobStatusResponse(
+        job_id=job.job_id,
+        status=job.status,
+        created_at=_job_ts(job.created_at),
+        updated_at=_job_ts(job.updated_at),
+        started_at=_job_ts(job.started_at),
+        finished_at=_job_ts(job.finished_at),
+        expires_at=_job_ts(job.expires_at),
+        error=job.error,
+    )
+
+
+class GraphExtractAPIRoute(APIRoute):
+    def get_route_handler(self):
+        original_route_handler = super().get_route_handler()
+
+        async def custom_route_handler(request: Request):
+            try:
+                return await original_route_handler(request)
+            except RequestValidationError as exc:
+                return JSONResponse(
+                    status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
+                    content={
+                        "detail": _error(
+                            "GRAPH_EXTRACT_VALIDATION_ERROR",
+                            str(exc),
+                            "request",
+                        )
+                    },
+                )

Review Comment:
   Fixed in 7850be7. Validation responses now use sanitized loc, msg, and type 
summaries from exc.errors() and omit raw input values. Added coverage for 
password and URL not being echoed.



-- 
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]

Reply via email to