Skip to content

Commit 6461d88

Browse files
committed
update web
1 parent b182cf5 commit 6461d88

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

‎manager.py‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,24 @@ async def run_shell() -> None:
6969
def run_web() -> None:
7070
import gradio as gr
7171

72+
check_law_chain = get_check_law_chain(config)
73+
chain = get_law_chain(config, out_callback=None)
74+
7275
async def chat(message, history):
73-
check_law_chain = get_check_law_chain(config)
74-
out_callback = OutCallbackHandler()
75-
chain = get_law_chain(config, out_callback=out_callback)
7676

77+
out_callback = OutCallbackHandler()
7778
is_law = check_law_chain.invoke({"question": message})
7879
if not is_law:
7980
yield "不好意思,我是法律AI助手,请提问和法律有关的问题。"
8081
return
8182

8283
task = asyncio.create_task(
83-
chain.ainvoke({"question": message}))
84+
chain.ainvoke({"question": message}, config={"callbacks": [out_callback]}))
85+
86+
async for new_token in out_callback.aiter():
87+
pass
88+
89+
out_callback.done.clear()
8490

8591
response = ""
8692
async for new_token in out_callback.aiter():
@@ -92,12 +98,14 @@ async def chat(message, history):
9298
response += new_token
9399
yield response
94100

101+
out_callback.done.clear()
102+
95103
demo = gr.ChatInterface(
96104
fn=chat, examples=["故意杀了一个人,会判几年?", "杀人自首会减刑吗?"], title="法律AI小助手")
97105

106+
demo.queue()
98107
demo.launch(
99108
server_name=config.WEB_HOST, server_port=config.WEB_PORT,
100-
enable_queue=True,
101109
auth=(config.WEB_USERNAME, config.WEB_PASSWORD),
102110
auth_message="默认用户名密码: username / password")
103111

0 commit comments

Comments
 (0)