batch
run_batch_task_gen(gen_task, items, input_map=lambda x: str(x), output_map=lambda x: x, stop_on_first_result=False, sequential=True, batch_size=None, turns=-1, message=None, handle_exceptions=False, max_cost=0.0, max_tokens=0)
¶
Generate and run copies of a task async/concurrently one per item in items
list.
For each item, apply input_map
to get the initial message to process.
For each result, apply output_map
to get the final result.
Args:
gen_task (Callable[[int], Task]): generates the tasks to run
items (list[T]): list of items to process
input_map (Callable[[T], str|ChatDocument]): function to map item to
initial message to process
output_map (Callable[[ChatDocument|str], U]): function to map result
to final result. If stop_on_first_result is enabled, then
map any invalid output to None. We continue until some non-None
result is obtained.
stop_on_first_result (bool): whether to stop after the first valid
(not-None) result. In this case all other tasks are
cancelled, and their corresponding result is None in the
returned list.
sequential (bool): whether to run sequentially
(e.g. some APIs such as ooba don't support concurrent requests)
batch_size (Optional[int]): The number of tasks to run at a time,
if None, unbatched
turns (int): number of turns to run, -1 for infinite
message (Optional[str]): optionally overrides the console status messages
handle_exceptions: bool: Whether to replace exceptions with outputs of None
max_cost: float: maximum cost to run the task (default 0.0 for unlimited)
max_tokens: int: maximum token usage (in and out) (default 0 for unlimited)
Returns:
Type | Description |
---|---|
list[Optional[U]]
|
list[Optional[U]]: list of final results. Always list[U] if |
list[Optional[U]]
|
|
Source code in langroid/agent/batch.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
|
run_batch_tasks(task, items, input_map=lambda x: str(x), output_map=lambda x: x, stop_on_first_result=False, sequential=True, batch_size=None, turns=-1, max_cost=0.0, max_tokens=0)
¶
Run copies of task
async/concurrently one per item in items
list.
For each item, apply input_map
to get the initial message to process.
For each result, apply output_map
to get the final result.
Args:
task (Task): task to run
items (list[T]): list of items to process
input_map (Callable[[T], str|ChatDocument]): function to map item to
initial message to process
output_map (Callable[[ChatDocument|str], U]): function to map result
to final result
sequential (bool): whether to run sequentially
(e.g. some APIs such as ooba don't support concurrent requests)
batch_size (Optional[int]): The number of tasks to run at a time,
if None, unbatched
turns (int): number of turns to run, -1 for infinite
max_cost: float: maximum cost to run the task (default 0.0 for unlimited)
max_tokens: int: maximum token usage (in and out) (default 0 for unlimited)
Returns:
Type | Description |
---|---|
List[Optional[U]]
|
list[Optional[U]]: list of final results. Always list[U] if |
List[Optional[U]]
|
|
Source code in langroid/agent/batch.py
run_batch_agent_method(agent, method, items, input_map=lambda x: str(x), output_map=lambda x: x, sequential=True, stop_on_first_result=False)
¶
Run the method
on copies of agent
, async/concurrently one per
item in items
list.
ASSUMPTION: The method
is an async method and has signature:
method(self, input: str|ChatDocument|None) -> ChatDocument|None
So this would typically be used for the agent's "responder" methods,
e.g. llm_response_async
or agent_responder_async
.
For each item, apply input_map
to get the initial message to process.
For each result, apply output_map
to get the final result.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent |
Agent
|
agent whose method to run |
required |
method |
str
|
Async method to run on copies of |
required |
input_map |
Callable[[Any], str | ChatDocument]
|
function to map item to initial message to process |
lambda x: str(x)
|
output_map |
Callable[[ChatDocument | str], Any]
|
function to map result to final result |
lambda x: x
|
sequential |
bool
|
whether to run sequentially (e.g. some APIs such as ooba don't support concurrent requests) |
True
|
Returns: List[Any]: list of final results
Source code in langroid/agent/batch.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 |
|