imbajin commented on code in PR #75:
URL: 
https://github.com/apache/incubator-hugegraph-ai/pull/75#discussion_r1761229839


##########
hugegraph-llm/src/hugegraph_llm/utils/graph_index_utils.py:
##########
@@ -0,0 +1,121 @@
+# 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 os
+import traceback
+from typing import Dict, Any, Union
+
+import gradio as gr
+from .hugegraph_utils import get_hg_client, clean_hg_data
+from .log import log
+from .vector_index_utils import read_documents
+from ..config import resource_path, settings, prompt
+from ..indices.vector_index import VectorIndex
+from ..models.embeddings.init_embedding import Embeddings
+from ..models.llms.init_llm import LLMs
+from ..operators.kg_construction_task import KgBuilder
+
+
+def get_graph_index_info():
+    builder = KgBuilder(LLMs().get_llm(), Embeddings().get_embedding(), 
get_hg_client())
+    context = builder.fetch_graph_data().run()
+    vector_index = VectorIndex.from_index_file(str(os.path.join(resource_path, 
settings.graph_name, "graph_vids")))
+    context["vid_index"] = {
+        "embed_dim": vector_index.index.d,
+        "num_vectors": vector_index.index.ntotal,
+        "num_vids": len(vector_index.properties)
+    }
+    return json.dumps(context, ensure_ascii=False, indent=2)
+
+
+def clean_all_graph_index():
+    clean_hg_data()
+    VectorIndex.clean(str(os.path.join(resource_path, settings.graph_name, 
"graph_vids")))
+    gr.Info("Clean graph index successfully!")
+
+
+def extract_graph(input_file, input_text, schema, example_prompt) -> str:
+    # update env variables: schema and example_prompt
+    if prompt.graph_schema != schema or prompt.extract_graph_prompt != 
example_prompt:
+        prompt.graph_schema = schema
+        prompt.extract_graph_prompt = example_prompt
+        prompt.update_yaml_file()
+
+    texts = read_documents(input_file, input_text)
+    builder = KgBuilder(LLMs().get_llm(), Embeddings().get_embedding(), 
get_hg_client())
+
+    if schema:
+        try:
+            schema = json.loads(schema.strip())
+            builder.import_schema(from_user_defined=schema)
+        except json.JSONDecodeError:
+            log.info("Get schema from graph!")

Review Comment:
   what's for? (a little confused)



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