Process a single sequence through its entire reasoning chain
(
seq: Dict,
client: AsyncOpenAI,
semaphore: asyncio.Semaphore,
args: argparse.Namespace,
search_cache: Dict,
url_cache: Dict,
batch_output_records: List[Dict],
turn: int = 0,
)
| 400 | return new_reasoning_steps |
| 401 | |
| 402 | async def process_single_sequence( |
| 403 | seq: Dict, |
| 404 | client: AsyncOpenAI, |
| 405 | semaphore: asyncio.Semaphore, |
| 406 | args: argparse.Namespace, |
| 407 | search_cache: Dict, |
| 408 | url_cache: Dict, |
| 409 | batch_output_records: List[Dict], |
| 410 | turn: int = 0, |
| 411 | ) -> Dict: |
| 412 | """Process a single sequence through its entire reasoning chain""" |
| 413 | |
| 414 | while not seq['finished'] and turn < args.max_turn: |
| 415 | # Generate next step in reasoning |
| 416 | text = await generate_response( |
| 417 | client=client, |
| 418 | prompt=seq['prompt'], |
| 419 | semaphore=semaphore, |
| 420 | temperature=args.temperature, |
| 421 | top_p=args.top_p, |
| 422 | max_tokens=args.max_tokens, |
| 423 | repetition_penalty=args.repetition_penalty, |
| 424 | top_k=args.top_k_sampling, |
| 425 | min_p=args.min_p, |
| 426 | model_name=args.model_name, |
| 427 | ) |
| 428 | |
| 429 | seq['history'].append(text) |
| 430 | seq['prompt'] += text |
| 431 | seq['output'] += text |
| 432 | |
| 433 | # Extract search query |
| 434 | search_query = extract_between(text, BEGIN_SEARCH_QUERY, END_SEARCH_QUERY) |
| 435 | |
| 436 | if search_query and seq['output'].rstrip().endswith(END_SEARCH_QUERY): |
| 437 | # Remove the </think> tag from the prompt and output |
| 438 | seq['prompt'] = seq['prompt'].replace('</think>\n','') |
| 439 | seq['output'] = seq['output'].replace('</think>\n','') |
| 440 | if seq['search_count'] < args.max_search_limit and search_query not in seq['executed_search_queries']: |
| 441 | # Execute search |
| 442 | results = {} |
| 443 | if search_query in search_cache: |
| 444 | results = search_cache[search_query] |
| 445 | else: |
| 446 | try: |
| 447 | if args.search_engine == "bing": |
| 448 | results = bing_web_search(search_query, args.bing_subscription_key, args.bing_endpoint) |
| 449 | elif args.search_engine == "serper": |
| 450 | results = google_serper_search(search_query, args.serper_api_key) |
| 451 | search_cache[search_query] = results |
| 452 | except Exception as e: |
| 453 | print(f"Error during search query '{search_query}' using {args.search_engine}: {e}") |
| 454 | search_cache[search_query] = {} |
| 455 | results = {} |
| 456 | |
| 457 | if args.search_engine == "bing": |
| 458 | relevant_info = extract_relevant_info(results)[:args.top_k] |
| 459 | elif args.search_engine == "serper": |
no test coverage detected