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

fix(llm): enable tasks concurrency configs in Gradio #188

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions hugegraph-llm/src/hugegraph_llm/demo/rag_demo/rag_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@

from hugegraph_llm.config import resource_path, prompt, huge_settings, llm_settings
from hugegraph_llm.operators.graph_rag_task import RAGPipeline
from hugegraph_llm.utils.decorators import with_task_id
from hugegraph_llm.operators.llm_op.answer_synthesize import AnswerSynthesize
from hugegraph_llm.utils.log import log


@with_task_id
def rag_answer(
text: str,
raw_answer: bool,
Expand Down Expand Up @@ -212,6 +214,7 @@ def create_rag_block():
gr.Markdown("""## 1. HugeGraph RAG Query""")
with gr.Row():
with gr.Column(scale=2):
# with gr.Blocks().queue(max_size=20, default_concurrency_limit=5):
inp = gr.Textbox(value=prompt.default_question, label="Question", show_copy_button=True, lines=3)

# TODO: Only support inline formula now. Should support block formula
Expand All @@ -237,6 +240,7 @@ def create_rag_block():
show_copy_button=True,
lines=7,
)

with gr.Column(scale=1):
with gr.Row():
raw_radio = gr.Radio(choices=[True, False], value=False, label="Basic LLM Answer")
Expand Down Expand Up @@ -290,6 +294,9 @@ def toggle_slider(enable):
example_num,
],
outputs=[raw_out, vector_only_out, graph_only_out, graph_vector_out],
queue=True, # Enable queueing for this event
concurrency_limit=5, # Maximum of 5 concurrent executions
concurrency_id="rag_answer_task"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so as here

)

gr.Markdown(
Expand Down
10 changes: 10 additions & 0 deletions hugegraph-llm/src/hugegraph_llm/utils/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,13 @@ def wrapper(*args: Any, **kwargs: Any) -> Any:
log.debug("%s QPS: %f/s", args[0].__class__.__name__, qps)
return result
return wrapper

def with_task_id(func: Callable) -> Callable:
def wrapper(*args: Any, **kwargs: Any) -> Any:
import uuid
task_id = str(uuid.uuid4())
log.info("New task created with id: %s", task_id)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested it locally and didn't see when this log will be output? There was no occurrence during concurrent use

# Optionally, you could also pass the task_id to the function if needed:
# kwargs['task_id'] = task_id
return func(*args, **kwargs)
return wrapper
13 changes: 8 additions & 5 deletions hugegraph-python-client/src/pyhugegraph/utils/huge_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# under the License.

import re
import sys
import traceback
from dataclasses import dataclass, field
from typing import List, Optional
Expand Down Expand Up @@ -63,8 +64,10 @@ def __post_init__(self):
)

except Exception as e: # pylint: disable=broad-exception-caught
traceback.print_exception(e)
self.gs_supported = False
log.warning(
"Failed to retrieve API version information from the server, reverting to default v1."
)
try:
traceback.print_exception(e)
self.gs_supported = False
except Exception: # pylint: disable=broad-exception-caught
exc_type, exc_value, tb = sys.exc_info()
traceback.print_exception(exc_type, exc_value, tb)
log.warning("Failed to retrieve API version information from the server, reverting to default v1.")
Loading