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


##########
hugegraph-llm/src/hugegraph_llm/demo/rag_web_demo.py:
##########
@@ -0,0 +1,314 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+
+import json
+
+import requests
+import uvicorn
+import docx
+import gradio as gr
+from fastapi import FastAPI
+
+from hugegraph_llm.models.llms.init_llm import LLMs
+from hugegraph_llm.models.embeddings.init_embedding import Embeddings
+from hugegraph_llm.operators.graph_rag_task import GraphRAG
+from hugegraph_llm.operators.kg_construction_task import KgBuilder
+from hugegraph_llm.config import settings
+from hugegraph_llm.utils.hugegraph_utils import (
+    init_hg_test_data,
+    get_hg_client,
+    run_gremlin_query
+)
+
+
+def graph_rag(text, vector_search: str):
+    searcher = GraphRAG().extract_keyword(text=text).query_graph_for_rag()
+    if vector_search == "true":
+        searcher.query_vector_index_for_rag()
+    return searcher.merge_dedup_rerank().synthesize_answer().run(verbose=True)
+
+
+def build_kg(file, schema, disambiguate_word_sense, commit_to_hugegraph, 
build_vector_index):
+    if str(file).endswith(".txt"):
+        with open(str(file), "r", encoding="utf-8") as f:
+            text = f.read()
+    elif str(file).endswith(".docx"):
+        text = ""
+        doc = docx.Document(file)
+        for para in doc.paragraphs:
+            text += para.text
+            text += "\n"
+    elif str(file).endswith(".pdf"):
+        raise Exception("ERROR: PDF will be supported later!")
+    else:
+        return "ERROR: please input txt or docx file."
+    builder = KgBuilder(LLMs().get_llm(), Embeddings().get_embedding())
+    if schema:
+        try:
+            schema = json.loads(schema.strip())
+            builder.import_schema(from_user_defined=schema)
+        except json.JSONDecodeError as e:
+            print(e)
+            builder.import_schema(from_hugegraph=schema)
+    else:
+        return "ERROR: please input schema."
+    builder.extract_triples(text)
+    if disambiguate_word_sense == "true":
+        builder.disambiguate_word_sense()
+    if commit_to_hugegraph == "true":
+        client = get_hg_client()
+        client.graphs().clear_graph_all_data()
+        builder.commit_to_hugegraph()
+    if build_vector_index == "true":
+        builder.do_triples_embedding()
+        builder.build_vector_index()
+    return builder.run()
+
+
+if __name__ == "__main__":
+    app = FastAPI()
+    with gr.Blocks() as hugegraph_llm:
+        gr.Markdown(
+            """# HugeGraph LLM RAG Demo
+        1. Set up the HugeGraph server."""
+        )
+        with gr.Row():
+            graph_config_input = [
+                gr.Textbox(value=settings.graph_ip, label="ip"),
+                gr.Textbox(value=str(settings.graph_port), label="port"),
+                gr.Textbox(value=settings.graph_user, label="user"),
+                gr.Textbox(value=settings.graph_pwd, label="pwd"),
+                gr.Textbox(value=settings.graph_name, label="graph")
+            ]
+        graph_config_button = gr.Button("apply configuration")
+
+
+        def test_api_connection(url, method="GET", ak=None, sk=None, 
headers=None, body=None):
+
+            # TODO: use fastapi.request / starlette instead?
+            response = requests.get(url)

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



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