(query, env)
| 383 | |
| 384 | |
| 385 | async 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 | |
| 421 | if __name__ == "__main__": |
| 422 | env = Environment() |
no test coverage detected