MCPcopy Create free account
hub / github.com/RUC-NLPIR/WebThinker / process_query_async

Function process_query_async

demo/run_logit.py:385–419  ·  view source on GitHub ↗
(query, env)

Source from the content-addressed store, hash-verified

383
384
385async def process_query_async(query, env):
386 env, prompt = prepare_init_prompt(query, env)
387 while True:
388 prompt = env.prompt
389 collected_step = ""
390 async for text_chunk in generate_response(
391 client=env.client,
392 prompt=prompt,
393 temperature=env.temperature,
394 top_p=env.top_p,
395 max_tokens=env.max_tokens,
396 repetition_penalty=env.repetition_penalty,
397 top_k=env.top_k,
398 min_p=env.min_p,
399 model_name=env.use_model_name,
400 stop=[env.END_SEARCH_QUERY]
401 ):
402 collected_step += text_chunk
403 yield text_chunk.replace('</think>','')
404 new_step = collected_step.replace('</think>\n', '')
405 env.update_step(new_step)
406
407 if not new_step.endswith(env.END_SEARCH_QUERY):
408 break
409
410 if env.search_count >= env.max_search_limit or env.total_tokens >= env.max_path_tokens:
411 append_text = f"\n\n{env.BEGIN_SEARCH_RESULT}You have reached the search limit. You are not allowed to search.{env.END_SEARCH_RESULT}\n\n"
412 else:
413 async for (flag, chunk) in run_search_chain(env, new_step):
414 if flag:
415 yield chunk
416 append_text = chunk
417
418 if append_text != '':
419 env.update_step(append_text)
420
421if __name__ == "__main__":
422 env = Environment()

Callers 2

appFunction · 0.90
run_logit.pyFile · 0.85

Calls 4

prepare_init_promptFunction · 0.85
run_search_chainFunction · 0.85
update_stepMethod · 0.80
generate_responseFunction · 0.70

Tested by

no test coverage detected