vichayturen commented on code in PR #64:
URL: 
https://github.com/apache/incubator-hugegraph-ai/pull/64#discussion_r1719170313


##########
hugegraph-llm/src/hugegraph_llm/demo/rag_web_demo.py:
##########
@@ -433,6 +486,78 @@ def apply_embedding_configuration(arg1, arg2, arg3):
             out = gr.Textbox(label="Output", show_copy_button=True)
         btn = gr.Button("(BETA) Init HugeGraph test data (🚧WIP)")
         btn.click(fn=init_hg_test_data, inputs=inp, outputs=out)  # pylint: 
disable=no-member
+    return hugegraph_llm
+
+
+def rag_web_http_api():
+    @app.post("/rag")
+    def graph_rag_api(req: RAGRequest):
+        result = graph_rag(req.query, req.raw_llm, req.vector_only, 
req.graph_only, req.graph_vector)
+        return {key: value for key, value in zip(
+            ["raw_llm", "vector_only", "graph_only", "graph_vector"], result) 
if getattr(req, key)}
+
+    @app.post("/graph/config")
+    def graph_config_api(req: GraphConfigRequest):
+        # Accept status code
+        status_code = apply_graph_configuration(req.ip, req.port, req.name, 
req.user, req.pwd, req.gs)
+        
+        if status_code == -1:
+            return {"message":"Unsupported HTTP method"}
+        
+        if 200 <= status_code < 300:
+            return {"message":"Connection successful. Configured finished."}
+        else:
+            return {"message":f"Connection failed with status code: 
{status_code}"}
+    
+    @app.post("/llm/config")
+    def llm_config_api(req: LLMConfigRequest):
+        settings.llm_type = req.llm_type
+        
+        if req.llm_type == "openai":
+            status_code = apply_llm_configuration(req.api_key, req.api_base, 
req.language_model, req.max_tokens)
+        elif req.llm_type == "qianfan_wenxin":
+            status_code = apply_llm_configuration(req.api_key, req.secret_key, 
req.language_model, None)
+        else:
+            status_code = apply_llm_configuration(req.host, req.port, 
req.language_model, None)
+        
+        if status_code == -1:
+            return {"message":"Unsupported HTTP method"}
+
+        if 200 <= status_code < 300:
+            return {"message":"Connection successful. Configured finished."}
+        else:
+            return {"message":f"Connection failed with status code: 
{status_code}"}
+        
+    @app.post("/embedding/config")
+    def embedding_config_api(req: LLMConfigRequest):
+        settings.embedding_type = req.llm_type
+
+        if req.llm_type == "openai":
+            status_code = apply_embedding_configuration(req.api_key, 
req.api_base, req.language_model)
+        elif req.llm_type == "qianfan_wenxin":
+            status_code = apply_embedding_configuration(req.api_key, 
req.api_base, None)

Review Comment:
   At present, this function does not return a value



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