(self, index: int, session: Session)
| 77 | return list(range(len(self.dataset))) |
| 78 | |
| 79 | async def start_sample(self, index: int, session: Session) -> TaskSampleExecutionResult: |
| 80 | self.env_controller.loop = asyncio.get_running_loop() |
| 81 | if not self.env_controller_background_task: |
| 82 | self.env_controller_background_task = asyncio.create_task(self.env_controller.background_task()) |
| 83 | weakref.finalize(self, self.env_controller_background_task.cancel) |
| 84 | |
| 85 | database: Optional[Database] = None |
| 86 | try: |
| 87 | entry = self.dataset[index][0] |
| 88 | ground_truth = self.dataset[index][1] |
| 89 | |
| 90 | use_sqlite = entry.get("user_sqlite", False) |
| 91 | if use_sqlite: |
| 92 | db_dir = entry['create']['database'] |
| 93 | init_file = entry['create']['init'] |
| 94 | sqlite_path = os.path.join(self.db_root_dir, db_dir, init_file) |
| 95 | database = SQLiteDatabase(sqlite_path) |
| 96 | await database.initialize() |
| 97 | else: |
| 98 | init_sql = self._build_init_sql(entry) |
| 99 | database = MySQLDatabase(self.env_controller) |
| 100 | await database.initialize() |
| 101 | await database.batch_execute(init_sql) |
| 102 | |
| 103 | session.inject(ChatCompletionSystemMessageParam( |
| 104 | role='system', |
| 105 | content=SYSTEM_PROMPT |
| 106 | )) |
| 107 | |
| 108 | user_prompt = "" |
| 109 | if "evidence" in entry and entry['evidence'] != "": |
| 110 | user_prompt += "Evidence about the question: " + entry["evidence"] + "\n" |
| 111 | if "add_description" in entry and entry['add_description'] != "": |
| 112 | user_prompt += "Additional table information about the question: " + entry["add_description"] + "\n" |
| 113 | user_prompt += "Question: " + entry["description"] + "\n" |
| 114 | session.inject(ChatCompletionUserMessageParam( |
| 115 | role='user', |
| 116 | content=user_prompt |
| 117 | )) |
| 118 | |
| 119 | for current_round in range(self.max_round): |
| 120 | response = await session.action() |
| 121 | |
| 122 | tool_calls = [] |
| 123 | for message in response.messages: |
| 124 | tool_calls.extend(message.get('tool_calls', []) or []) |
| 125 | |
| 126 | if not tool_calls: |
| 127 | session.inject(ChatCompletionUserMessageParam( |
| 128 | role='user', |
| 129 | content='Internal error: No tool calls found despite finish reason.' |
| 130 | )) |
| 131 | continue |
| 132 | |
| 133 | for tool_call in tool_calls: |
| 134 | call_id = tool_call.get('id', '') |
| 135 | try: |
| 136 | function_name = tool_call.get('function', {}).get('name', '') |
nothing calls this directly
no test coverage detected