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

Function process_single_sequence

scripts/run_web_thinker_report.py:433–872  ·  view source on GitHub ↗

Process a single sequence through its entire reasoning chain with MAX_TOKENS limit

(
    seq: Dict,
    client: AsyncOpenAI,
    aux_client: AsyncOpenAI,
    semaphore: asyncio.Semaphore,
    args: argparse.Namespace,
    search_cache: Dict,
    url_cache: Dict,
    batch_output_records: List[Dict],
)

Source from the content-addressed store, hash-verified

431
432
433async def process_single_sequence(
434 seq: Dict,
435 client: AsyncOpenAI,
436 aux_client: AsyncOpenAI,
437 semaphore: asyncio.Semaphore,
438 args: argparse.Namespace,
439 search_cache: Dict,
440 url_cache: Dict,
441 batch_output_records: List[Dict],
442) -> Dict:
443 """Process a single sequence through its entire reasoning chain with MAX_TOKENS limit"""
444
445 # Initialize limits
446 MAX_TOKENS = 50000
447 MAX_INTERACTIONS = 80 # Maximum number of total interactions,应对复读
448 total_interactions = 0 # Track total interactions
449
450 # Generate search plan first
451 print(f"Generating search plan...")
452 question = seq['item']['Question']
453 _, search_plan = await generate_response(
454 client=aux_client,
455 model_name=args.aux_model_name,
456 prompt=get_search_plan_instruction(question),
457 semaphore=semaphore,
458 max_tokens=args.max_tokens // 2,
459 bad_words=[f"{END_SEARCH_QUERY}{tokenizer.eos_token}"],
460 )
461
462 print(f"---Search plan:---\n{search_plan}")
463
464 # Generate the full instruction with the plan
465 user_prompt = get_report_webthinker_instruction(question, search_plan)
466 seq['prompt'] = user_prompt
467
468 # Initialize token counter with prompt tokens
469 total_tokens = len(seq['prompt'].split())
470
471 # Initialize web explorer interactions list and article-related variables
472 seq['web_explorer'] = []
473 article = ""
474 summarized_article = ""
475 document_memory = [] # Store all retrieved web page content
476
477 # Initialize BM25 for document retrieval
478 tokenized_docs = []
479 bm25 = None
480
481 # First response uses chat completion
482 formatted_prompt, response = await generate_response(
483 client=client,
484 model_name=args.model_name,
485 prompt=seq['prompt'],
486 semaphore=semaphore,
487 temperature=args.temperature,
488 top_p=args.top_p,
489 max_tokens=args.max_tokens,
490 repetition_penalty=args.repetition_penalty,

Callers 1

main_asyncFunction · 0.70

Tested by

no test coverage detected