Re: [PR] support log output in RAG platform in ui and curl command [incubator-hugegraph-ai]
imbajin commented on code in PR #110: URL: https://github.com/apache/incubator-hugegraph-ai/pull/110#discussion_r1844923792 ## hugegraph-llm/src/hugegraph_llm/demo/rag_demo/admin_block.py: ## @@ -0,0 +1,152 @@ +# 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 asyncio +import os + +import gradio as gr +from gradio import Request + +from hugegraph_llm.utils.log import log + + +async def log_stream(log_path: str): +""" +Stream the content of a log file like `tail -f`. +""" +try: +with open(log_path, 'r') as file: +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() Review Comment: ```suggestion # TODO: avoid read the whole file (read latest N lines instead) return f.read() ``` -- 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-unsubscr...@hugegraph.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org - To unsubscribe, e-mail: issues-unsubscr...@hugegraph.apache.org For additional commands, e-mail: issues-h...@hugegraph.apache.org
Re: [PR] support log output in RAG platform in ui and curl command [incubator-hugegraph-ai]
imbajin commented on code in PR #110: URL: https://github.com/apache/incubator-hugegraph-ai/pull/110#discussion_r1841979741 ## hugegraph-llm/src/hugegraph_llm/demo/rag_demo/admin_block.py: ## @@ -0,0 +1,152 @@ +# 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 asyncio +import os + +import gradio as gr +from gradio import Request + +from hugegraph_llm.utils.log import log + + +async def log_stream(log_path: str): +""" +Stream the content of a log file like `tail -f`. +""" +try: +with open(log_path, 'r') as file: +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() Review Comment: `lines = file.readlines()[-num_lines:]` (maybe?) -- 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-unsubscr...@hugegraph.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org - To unsubscribe, e-mail: issues-unsubscr...@hugegraph.apache.org For additional commands, e-mail: issues-h...@hugegraph.apache.org
Re: [PR] support log output in RAG platform in ui and curl command [incubator-hugegraph-ai]
imbajin commented on code in PR #110: URL: https://github.com/apache/incubator-hugegraph-ai/pull/110#discussion_r1841550642 ## hugegraph-llm/src/hugegraph_llm/demo/rag_demo/admin_block.py: ## @@ -0,0 +1,158 @@ +# 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 asyncio + +import gradio as gr +from gradio import Request + +from hugegraph_llm.config import settings +from hugegraph_llm.utils.log import log + + +async def log_stream(log_path: str): +""" +Stream the content of a log file like `tail -f`. +""" +try: +with open(log_path, 'r') as file: +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." + + +# Functions to clear each log file +def clear_llm_server_log(): +with open("logs/llm-server.log", "w") as f: +f.truncate(0) # Clear the 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 the contents of the file +return "Output log cleared." Review Comment: do we still need it? ## hugegraph-llm/src/hugegraph_llm/demo/rag_demo/other_block.py: ## Review Comment: no need to modify the filename(not visible to users) OK to keep `file_block` -- 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-unsubscr...@hugegraph.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org - To unsubscribe, e-mail: issues-unsubscr...@hugegraph.apache.org For additional commands, e-mail: issues-h...@hugegraph.apache.org
Re: [PR] support log output in RAG platform in ui and curl command [incubator-hugegraph-ai]
imbajin commented on PR #110: URL: https://github.com/apache/incubator-hugegraph-ai/pull/110#issuecomment-2473566270 merge it after #111 (need update the code) -- 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-unsubscr...@hugegraph.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org - To unsubscribe, e-mail: issues-unsubscr...@hugegraph.apache.org For additional commands, e-mail: issues-h...@hugegraph.apache.org
Re: [PR] support log output in RAG platform in ui and curl command [incubator-hugegraph-ai]
imbajin commented on code in PR #110: URL: https://github.com/apache/incubator-hugegraph-ai/pull/110#discussion_r1836213163 ## 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_token: Optional[str] = None +log_file: Optional[str] = 'llm-server.log' Review Comment: ```suggestion log_file: Optional[str] = 'llm-server.log' ``` add a empty line in EOF (better to set it in IDE settings) ## hugegraph-llm/src/hugegraph_llm/api/rag_api.py: ## @@ -49,7 +52,7 @@ def graph_rag_recall( def rag_http_api( -router: APIRouter, rag_answer_func, apply_graph_conf, apply_llm_conf, apply_embedding_conf, apply_reranker_conf +router: APIRouter, rag_answer_func, apply_graph_conf, apply_llm_conf, apply_embedding_conf, apply_reranker_conf, log_stream Review Comment: line chars > 120 (better to move it outside) refer ↓ ## hugegraph-llm/src/hugegraph_llm/api/rag_api.py: ## @@ -126,3 +129,14 @@ def rerank_config_api(req: RerankerConfigRequest): else: res = status.HTTP_501_NOT_IMPLEMENTED return generate_response(RAGResponse(status_code=res, message="Missing Value")) + +@router.post("/logs", status_code=status.HTTP_200_OK) Review Comment: prefer to separate it in a single api file (like `util_api.py` or `admin_api.py`) ## hugegraph-llm/src/hugegraph_llm/demo/rag_demo/log_block.py: ## @@ -0,0 +1,167 @@ +# 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 + + +async def log_stream(log_path: str): +""" +Stream the content of a log file like `tail -f`. +""" +try: +with open(log_path, 'r') as file: +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 = None): +client_ip = request.client.host if request else "Unknown IP" +if password == settings.log_token: +# 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
Re: [PR] support log output in RAG platform in ui and curl command [incubator-hugegraph-ai]
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] = "00" + +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 +# Gen