You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hugegraph.apache.org by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org> on 2024/08/17 14:42:59 UTC

Re: [PR] feat(llm): support basic rag api(v1) [incubator-hugegraph-ai]

github-advanced-security[bot] commented on code in PR #64:
URL: https://github.com/apache/incubator-hugegraph-ai/pull/64#discussion_r1720786578


##########
hugegraph-llm/src/hugegraph_llm/demo/rag_web_demo.py:
##########
@@ -116,38 +111,139 @@
             return "ERROR: please input schema."
     builder.chunk_split(text, "paragraph", "zh")
 
-    # TODO: avoid hardcoding the "build_mode" strings (use var/constant instead)
-    if build_mode == "Rebuild Vector":
+    if build_mode == BuildMode.REBUILD_VECTOR:
         builder.fetch_graph_data()
     else:
         builder.extract_info(example_prompt, "property_graph")
     # "Test Mode", "Import Mode", "Clear and Import", "Rebuild Vector"
-    if build_mode != "Test Mode":
-        if build_mode in ("Clear and Import", "Rebuild Vector"):
+    if build_mode != BuildMode.TEST_MODE:
+        if build_mode in (BuildMode.CLEAR_AND_IMPORT, BuildMode.REBUILD_VECTOR):
             clean_vector_index()
         builder.build_vector_index()
-    if build_mode == "Clear and Import":
+    if build_mode == BuildMode.CLEAR_AND_IMPORT:
         clean_hg_data()
-    if build_mode in ("Clear and Import", "Import Mode"):
+    if build_mode in (BuildMode.CLEAR_AND_IMPORT, BuildMode.IMPORT_MODE):
         builder.commit_to_hugegraph()
-    if build_mode != "Test Mode":
+    if build_mode != BuildMode.TEST_MODE:
         builder.build_vertex_id_semantic_index()
     log.debug(builder.operators)
     try:
         context = builder.run()
-        return context
+        return str(context)
     except Exception as e:  # pylint: disable=broad-exception-caught
         log.error(e)
         raise gr.Error(str(e))
 
 
-if __name__ == "__main__":
-    parser = argparse.ArgumentParser()
-    parser.add_argument("--host", type=str, default="0.0.0.0", help="host")
-    parser.add_argument("--port", type=int, default=8001, help="port")
-    args = parser.parse_args()
-    app = FastAPI()
-
+def test_api_connection(url, method="GET", headers=None, body=None, auth=None, origin_call=None) -> int:
+    # TODO: use fastapi.request / starlette instead?
+    response = None
+    log.debug("Request URL: %s", url)
+    try:
+        if method.upper() == "GET":
+            response = requests.get(url, headers=headers, timeout=5, auth=auth)

Review Comment:
   ## Full server-side request forgery
   
   The full URL of this request depends on a [user-provided value](1).
   The full URL of this request depends on a [user-provided value](2).
   The full URL of this request depends on a [user-provided value](3).
   The full URL of this request depends on a [user-provided value](4).
   
   [Show more details](https://github.com/apache/incubator-hugegraph-ai/security/code-scanning/13)



##########
hugegraph-llm/src/hugegraph_llm/demo/rag_web_demo.py:
##########
@@ -116,38 +111,139 @@
             return "ERROR: please input schema."
     builder.chunk_split(text, "paragraph", "zh")
 
-    # TODO: avoid hardcoding the "build_mode" strings (use var/constant instead)
-    if build_mode == "Rebuild Vector":
+    if build_mode == BuildMode.REBUILD_VECTOR:
         builder.fetch_graph_data()
     else:
         builder.extract_info(example_prompt, "property_graph")
     # "Test Mode", "Import Mode", "Clear and Import", "Rebuild Vector"
-    if build_mode != "Test Mode":
-        if build_mode in ("Clear and Import", "Rebuild Vector"):
+    if build_mode != BuildMode.TEST_MODE:
+        if build_mode in (BuildMode.CLEAR_AND_IMPORT, BuildMode.REBUILD_VECTOR):
             clean_vector_index()
         builder.build_vector_index()
-    if build_mode == "Clear and Import":
+    if build_mode == BuildMode.CLEAR_AND_IMPORT:
         clean_hg_data()
-    if build_mode in ("Clear and Import", "Import Mode"):
+    if build_mode in (BuildMode.CLEAR_AND_IMPORT, BuildMode.IMPORT_MODE):
         builder.commit_to_hugegraph()
-    if build_mode != "Test Mode":
+    if build_mode != BuildMode.TEST_MODE:
         builder.build_vertex_id_semantic_index()
     log.debug(builder.operators)
     try:
         context = builder.run()
-        return context
+        return str(context)
     except Exception as e:  # pylint: disable=broad-exception-caught
         log.error(e)
         raise gr.Error(str(e))
 
 
-if __name__ == "__main__":
-    parser = argparse.ArgumentParser()
-    parser.add_argument("--host", type=str, default="0.0.0.0", help="host")
-    parser.add_argument("--port", type=int, default=8001, help="port")
-    args = parser.parse_args()
-    app = FastAPI()
-
+def test_api_connection(url, method="GET", headers=None, body=None, auth=None, origin_call=None) -> int:
+    # TODO: use fastapi.request / starlette instead?
+    response = None
+    log.debug("Request URL: %s", url)
+    try:
+        if method.upper() == "GET":
+            response = requests.get(url, headers=headers, timeout=5, auth=auth)
+        elif method.upper() == "POST":
+            response = requests.post(url, headers=headers, json=body, timeout=5, auth=auth)

Review Comment:
   ## Full server-side request forgery
   
   The full URL of this request depends on a [user-provided value](1).
   The full URL of this request depends on a [user-provided value](2).
   The full URL of this request depends on a [user-provided value](3).
   The full URL of this request depends on a [user-provided value](4).
   
   [Show more details](https://github.com/apache/incubator-hugegraph-ai/security/code-scanning/14)



-- 
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: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org