This is an automated email from the ASF dual-hosted git repository.
jin pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-hugegraph-ai.git
The following commit(s) were added to refs/heads/main by this push:
new 9a9de77 fix(llm): enable fastapi auto reload function (#164)
9a9de77 is described below
commit 9a9de7738f382acf278e793188ca38c14871b5b0
Author: Aryan Kumar Baghel <[email protected]>
AuthorDate: Thu Feb 20 12:57:06 2025 +0530
fix(llm): enable fastapi auto reload function (#164)
---------
Co-authored-by: imbajin <[email protected]>
---
.../src/hugegraph_llm/demo/rag_demo/app.py | 27 ++++++++++++----------
1 file changed, 15 insertions(+), 12 deletions(-)
diff --git a/hugegraph-llm/src/hugegraph_llm/demo/rag_demo/app.py
b/hugegraph-llm/src/hugegraph_llm/demo/rag_demo/app.py
index 83b027b..fc1646b 100644
--- a/hugegraph-llm/src/hugegraph_llm/demo/rag_demo/app.py
+++ b/hugegraph-llm/src/hugegraph_llm/demo/rag_demo/app.py
@@ -155,17 +155,11 @@ def init_rag_ui() -> gr.Interface:
return hugegraph_llm_ui
-if __name__ == "__main__":
- parser = argparse.ArgumentParser()
- parser.add_argument("--host", type=str, default="0.0.0.0", help="host")
- parser.add_argument("--port", type=int, default=8001, help="port")
- args = parser.parse_args()
+def create_app():
app = FastAPI(lifespan=lifespan)
-
# we don't need to manually check the env now
# settings.check_env()
prompt.update_yaml_file()
-
auth_enabled = admin_settings.enable_login.lower() == "true"
log.info("(Status) Authentication is %s now.", "enabled" if auth_enabled
else "disabled")
api_auth = APIRouter(dependencies=[Depends(authenticate)] if auth_enabled
else [])
@@ -184,13 +178,22 @@ if __name__ == "__main__":
admin_http_api(api_auth, log_stream)
app.include_router(api_auth)
-
+ # Mount Gradio inside FastAPI
# TODO: support multi-user login when need
app = gr.mount_gradio_app(
app, hugegraph_llm, path="/", auth=("rag", admin_settings.user_token)
if auth_enabled else None
)
- # TODO: we can't use reload now due to the config 'app' of uvicorn.run
- # ❎:f'{__name__}:app' / rag_web_demo:app /
hugegraph_llm.demo.rag_web_demo:app
- # TODO: merge unicorn log to avoid duplicate log output (should be
unified/fixed later)
- uvicorn.run(app, host=args.host, port=args.port, reload=False)
+ return app
+
+
+if __name__ == "__main__":
+ parser = argparse.ArgumentParser()
+ parser.add_argument("--host", type=str, default="0.0.0.0", help="host")
+ parser.add_argument("--port", type=int, default=8001, help="port")
+ args = parser.parse_args()
+
+ import logging
+ logging.getLogger("uvicorn.access").propagate = False
+
+ uvicorn.run("hugegraph_llm.demo.rag_demo.app:create_app", host=args.host,
port=args.port, reload=True)