(task, config, llm, system_prompt_template, max_turns, output_path, processed_ids)
| 71 | lock = threading.Lock() |
| 72 | |
| 73 | def process_task(task, config, llm, system_prompt_template, max_turns, output_path, processed_ids): |
| 74 | index = task["index"] |
| 75 | cell_path="Cells" |
| 76 | if index in processed_ids: |
| 77 | return |
| 78 | |
| 79 | file_path = ",".join(task["file_paths"]) |
| 80 | user_query = task["user"] |
| 81 | |
| 82 | nb = nbformat.v4.new_notebook() |
| 83 | client = NotebookClient(nb, allow_errors=True) |
| 84 | client.km = client.create_kernel_manager() |
| 85 | client.start_new_kernel() |
| 86 | client.start_new_kernel_client() |
| 87 | Kernel = client.kc |
| 88 | |
| 89 | logger.info("==" * 80) |
| 90 | logger.info(f"Task index: {index}") |
| 91 | logger.info(f"Task:\n{user_query}") |
| 92 | logger.info(f"File path: {file_path}") |
| 93 | |
| 94 | messages = [ |
| 95 | {"role": "system", "content": system_prompt_template}, |
| 96 | {"role": "user", "content": f"[INFO]The data is uploaded to {file_path}"}, |
| 97 | {"role": "user", "content": user_query}, |
| 98 | ] |
| 99 | cells = [ |
| 100 | {"role": "system", "text": system_prompt_template}, |
| 101 | {"role": "user", "text": f"[INFO]The data is uploaded to {file_path}"}, |
| 102 | {"role": "user", "text": user_query}, |
| 103 | ] |
| 104 | |
| 105 | try: |
| 106 | for count in range(max_turns): # max 5 turn interaction |
| 107 | logger.info("--" * 10 + f"Round: {count}" + "--" * 10) |
| 108 | #logger.info(f"input messages: {messages}") |
| 109 | try: |
| 110 | out_msg, debug_info = llm.generate(messages) |
| 111 | except: |
| 112 | break |
| 113 | #logger.info(f"output msg: {message2dict(out_msg)}") |
| 114 | |
| 115 | reasoning, code_script = parse_code_action( |
| 116 | out_msg.content, |
| 117 | mode=config["mode"], |
| 118 | code_start_token=config["code_start_token"], |
| 119 | code_end_token=config["code_end_token"], |
| 120 | tool_call_token=config["tool_call_token"], |
| 121 | ) |
| 122 | #logger.info(f"Reasoning: {reasoning}") |
| 123 | #logger.info(f"Code script: {code_script}") |
| 124 | if code_script is None or code_script.strip() == "": |
| 125 | messages.append({"role": "assistant", "content": reasoning}) |
| 126 | cells.append({"role": "assistant", "text": reasoning}) |
| 127 | else: |
| 128 | messages.append( |
| 129 | { |
| 130 | "role": "assistant", |
nothing calls this directly
no test coverage detected