Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(llm): timely execute vid embedding & enhance some HTTP logic #141

Merged
merged 21 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hugegraph-llm/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ python-dotenv>=1.0.1
pyarrow~=17.0.0 # TODO: a temporary dependency for pandas, figure out why ImportError
pandas~=2.2.2
openpyxl~=3.1.5
pydantic-settings~=2.6.1
pydantic-settings~=2.6.1
MrJs133 marked this conversation as resolved.
Show resolved Hide resolved
29 changes: 27 additions & 2 deletions hugegraph-llm/src/hugegraph_llm/demo/rag_demo/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@


import argparse
import asyncio
from contextlib import asynccontextmanager

import gradio as gr
import uvicorn
Expand All @@ -40,10 +42,10 @@
from hugegraph_llm.demo.rag_demo.vector_graph_block import create_vector_graph_block
from hugegraph_llm.resources.demo.css import CSS
from hugegraph_llm.utils.log import log
from hugegraph_llm.utils.graph_index_utils import fit_vid_index

sec = HTTPBearer()


def authenticate(credentials: HTTPAuthorizationCredentials = Depends(sec)):
correct_token = admin_settings.user_token
if credentials.credentials != correct_token:
Expand All @@ -55,6 +57,29 @@ def authenticate(credentials: HTTPAuthorizationCredentials = Depends(sec)):
headers={"WWW-Authenticate": "Bearer"},
)

async def schedule_fit_vid_index():
try:
while True:
log.info("Executing fit_vid_index function...")
await asyncio.to_thread(fit_vid_index)
log.info("fit_vid_index function executed successfully.")
await asyncio.sleep(3600)
except Exception as e: #pylint: disable=W0718
log.error(e)

@asynccontextmanager
async def lifespan(app: FastAPI): #pylint: disable=W0621
log.info("Starting periodic task...")
task = asyncio.create_task(schedule_fit_vid_index())

yield

log.info("Stopping periodic task...")
task.cancel()
try:
await task
except asyncio.CancelledError:
log.info("Periodic task has been cancelled.")

# pylint: disable=C0301
def init_rag_ui() -> gr.Interface:
Expand Down Expand Up @@ -158,7 +183,7 @@ def refresh_ui_config_prompt() -> tuple:
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()
app = FastAPI()
app = FastAPI(lifespan=lifespan)

# we don't need to manually check the env now
# settings.check_env()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ def create_vector_graph_block():
graph_index_btn1 = gr.Button("Clear Graph Data & Index", size="sm")

vector_import_bt = gr.Button("Import into Vector", variant="primary")
graph_index_rebuild_bt = gr.Button("Rebuild vid Index")
graph_extract_bt = gr.Button("Extract Graph Data (1)", variant="primary")
graph_loading_bt = gr.Button("Load into GraphDB (2)", interactive=True)
graph_index_rebuild_bt = gr.Button("Rebuild vid Index")

vector_index_btn0.click(get_vector_index_info, outputs=out).then(
store_prompt,
Expand Down Expand Up @@ -122,6 +122,9 @@ def create_vector_graph_block():
graph_loading_bt.click(import_graph_data, inputs=[out, input_schema], outputs=[out]).then(
store_prompt,
inputs=[input_schema, info_extract_template],
).then(fit_vid_index).then(
store_prompt,
inputs=[input_schema, info_extract_template],
)

def on_tab_select(input_f, input_t, evt: gr.SelectData):
Expand Down
Loading