Perf: set timeout for building chunks. (#8940)

### What problem does this PR solve?


### Type of change

- [x] Performance Improvement
This commit is contained in:
Kevin Hu
2025-07-21 15:56:45 +08:00
committed by GitHub
parent e101c35c0b
commit c783d90ba3
3 changed files with 14 additions and 10 deletions

View File

@ -676,12 +676,14 @@ async def is_strong_enough(chat_model, embedding_model):
@timeout(30, 2)
async def _is_strong_enough():
nonlocal chat_model, embedding_model
with trio.fail_after(3):
_ = await trio.to_thread.run_sync(lambda: embedding_model.encode(["Are you strong enough!?"]))
with trio.fail_after(30):
res = await trio.to_thread.run_sync(lambda: chat_model.chat("Nothing special.", [{"role":"user", "content": "Are you strong enough!?"}], {}))
if res.find("**ERROR**") >= 0:
raise Exception(res)
if embedding_model:
with trio.fail_after(3):
_ = await trio.to_thread.run_sync(lambda: embedding_model.encode(["Are you strong enough!?"]))
if chat_model:
with trio.fail_after(30):
res = await trio.to_thread.run_sync(lambda: chat_model.chat("Nothing special.", [{"role":"user", "content": "Are you strong enough!?"}], {}))
if res.find("**ERROR**") >= 0:
raise Exception(res)
# Pressure test for GraphRAG task
async with trio.open_nursery() as nursery: