Copilot commented on code in PR #258:
URL:
https://github.com/apache/incubator-hugegraph-ai/pull/258#discussion_r2107331586
##########
hugegraph-llm/src/hugegraph_llm/api/models/rag_requests.py:
##########
@@ -116,3 +116,12 @@ class RerankerConfigRequest(BaseModel):
class LogStreamRequest(BaseModel):
admin_token: Optional[str] = None
log_file: Optional[str] = "llm-server.log"
+
+class GremlinGenerateRequest(BaseModel):
+ query: str
+ example_num: int
+ schema_str: str
+ gremlin_prompt: Optional[str] = Query(
+ prompt.gremlin_generate_prompt,
Review Comment:
Using FastAPI's Query inside a Pydantic BaseModel for a request body field
won't be treated as a query parameter and may lead to unexpected defaults.
Consider using pydantic.Field with a default value or moving this parameter to
the endpoint signature.
```suggestion
gremlin_prompt: Optional[str] = Field(
default=prompt.gremlin_generate_prompt,
```
##########
hugegraph-llm/src/hugegraph_llm/api/rag_api.py:
##########
@@ -178,3 +180,30 @@ def rerank_config_api(req: RerankerConfigRequest):
else:
res = status.HTTP_501_NOT_IMPLEMENTED
return generate_response(RAGResponse(status_code=res, message="Missing
Value"))
+
+ @router.post("/text2gremlin", status_code=status.HTTP_200_OK)
+ def text2gremlin_api(req: GremlinGenerateRequest):
Review Comment:
This endpoint returns a raw dict instead of using the project’s standard
generate_response wrapper, which may cause inconsistent response formats.
Consider wrapping the payload in generate_response(RAGResponse(...)) or a
unified response schema.
##########
hugegraph-llm/src/hugegraph_llm/api/rag_api.py:
##########
@@ -178,3 +180,30 @@ def rerank_config_api(req: RerankerConfigRequest):
else:
res = status.HTTP_501_NOT_IMPLEMENTED
return generate_response(RAGResponse(status_code=res, message="Missing
Value"))
+
+ @router.post("/text2gremlin", status_code=status.HTTP_200_OK)
+ def text2gremlin_api(req: GremlinGenerateRequest):
+ try:
+ match_result, template_gremlin, raw_gremlin,
template_execution_result, raw_execution_result = (
+ gremlin_generate_func(
+ inp=req.query,
+ example_num=req.example_num,
+ schema=req.schema_str,
+ gremlin_prompt=req.gremlin_prompt or
prompt.gremlin_generate_prompt,
+ )
+ )
+ return {
+ "match_result": match_result,
+ "template_gremlin": template_gremlin,
+ "raw_gremlin": raw_gremlin,
+ "template_execution_result": template_execution_result,
+ "raw_execution_result": raw_execution_result,
+ }
+ except HTTPException as e:
+ raise e
+ except Exception as e:
+ log.error(f"Error in text2gremlin_api: {e}")
Review Comment:
[nitpick] Catching a broad Exception can mask specific errors. It’s
preferable to narrow the exception types or use log.exception to capture the
full stack trace for easier debugging.
```suggestion
log.exception("Error in text2gremlin_api")
```
--
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]