imbajin commented on code in PR #110:
URL:
https://github.com/apache/incubator-hugegraph-ai/pull/110#discussion_r1836104982
##########
hugegraph-llm/src/hugegraph_llm/config/config_data.py:
##########
@@ -70,8 +70,10 @@ class ConfigData:
graph_user: Optional[str] = "admin"
graph_pwd: Optional[str] = "xxx"
graph_space: Optional[str] = None
-
-
+ log_auth_key: Optional[str] = "000000"
+
+ enable_login: Optional[str] = False
+ token: Optional[str] = "123456"
Review Comment:
add a comment for them: like "Admin settings"
##########
hugegraph-llm/src/hugegraph_llm/api/models/rag_requests.py:
##########
@@ -70,3 +70,7 @@ class RerankerConfigRequest(BaseModel):
reranker_type: str
api_key: str
cohere_base_url: Optional[str] = None
+
+class LogStreamRequest(BaseModel):
+ log_auth_key: Optional[str] = None
Review Comment:
```suggestion
log_token: Optional[str] = None
```
maybe `token` is enough?
##########
hugegraph-llm/src/hugegraph_llm/demo/rag_demo/app.py:
##########
@@ -94,6 +95,8 @@ def init_rag_ui() -> gr.Interface:
textbox_inp, textbox_answer_prompt_input = create_rag_block()
with gr.Tab(label="3. Others Tools 🚧"):
Review Comment:
```suggestion
with gr.Tab(label="3. Graph Tools 🚧"):
```
##########
hugegraph-llm/src/hugegraph_llm/demo/rag_demo/log_block.py:
##########
@@ -0,0 +1,162 @@
+# 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 gradio as gr
+from hugegraph_llm.config import settings
+from hugegraph_llm.utils.log import log
+import os
+import asyncio
+import requests
+from fastapi import Request
+# Generator to simulate the tail -f behavior
+async def log_stream(log_path: str):
+ """
+ Stream the content of a log file like `tail -f`.
+ This function is asynchronous.
Review Comment:
```suggestion
```
no need to comment this, but could provide some **useful** information for
other devs
##########
hugegraph-llm/src/hugegraph_llm/demo/rag_demo/log_block.py:
##########
@@ -0,0 +1,162 @@
+# 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 gradio as gr
+from hugegraph_llm.config import settings
+from hugegraph_llm.utils.log import log
+import os
+import asyncio
+import requests
+from fastapi import Request
+# Generator to simulate the tail -f behavior
Review Comment:
format the code with empty line
##########
hugegraph-llm/src/hugegraph_llm/demo/rag_demo/log_block.py:
##########
@@ -0,0 +1,162 @@
+# 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 gradio as gr
+from hugegraph_llm.config import settings
+from hugegraph_llm.utils.log import log
+import os
+import asyncio
+import requests
+from fastapi import Request
+# Generator to simulate the tail -f behavior
+async def log_stream(log_path: str):
+ """
+ Stream the content of a log file like `tail -f`.
+ This function is asynchronous.
+ """
+ try:
+ with open(log_path, 'r') as file:
+ # Move the cursor to the end of the file
+ # file.seek(0, os.SEEK_END)
+ while True:
+ line = file.readline()
+ if line:
+ yield line
+ else:
+ await asyncio.sleep(0.1) # Non-blocking sleep
+ except FileNotFoundError:
+ raise Exception(f"Log file not found: {log_path}")
+ except Exception as e:
+ raise Exception(f"An error occurred while reading the log: {str(e)}")
+
+# Functions to read each log file
+def read_llm_server_log():
+ try:
+ with open("logs/llm-server.log", "r") as f:
+ return f.read()
+ except FileNotFoundError:
+ return "LLM Server log file not found."
+
+def read_output_log():
+ try:
+ with open("logs/output.log", "r") as f:
+ return f.read()
+ except FileNotFoundError:
+ return "Output log file not found."
+
+# Functions to clear each log file
+def clear_llm_server_log():
+ with open("logs/llm-server.log", "w") as f:
+ f.truncate(0) # Clear contents of the file
+ return "LLM Server log cleared."
+
+def clear_output_log():
+ with open("logs/output.log", "w") as f:
+ f.truncate(0) # Clear contents of the file
+ return "Output log cleared."
+
+# Function to validate password and control access to logs
+def check_password(password, request:Request):
+ client_ip = request.client.host if request else "Unknown IP"
+ if password == settings.log_auth_key:
+ # Return logs and update visibility
+ llm_log, output_log = read_llm_server_log(), read_output_log()
+ visible_update = gr.update(visible=True)
+ hidden_update = gr.update(visible=False)
+
+ # Log the successful access with the IP address
+ log.info(f"Logs accessed successfully from IP: {client_ip}")
+
+ return llm_log, output_log, visible_update, visible_update,
visible_update, hidden_update
+ else:
+ # Log the failed attempt with IP address
+ log.error(f"Incorrect password attempt from IP: {client_ip}")
+ return "", "", gr.update(visible=False), gr.update(visible=False),
gr.update(visible=False), gr.update(value="Incorrect password. Access denied.",
visible=True)
Review Comment:
Note: max_chars for one line is **120** now (py code)
so as other modification
--
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]