lm-deluge 0.0.39__py3-none-any.whl → 0.0.40__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of lm-deluge might be problematic. Click here for more details.

lm_deluge/client.py CHANGED
@@ -1,6 +1,6 @@
1
1
  import asyncio
2
2
  import random
3
- from typing import Any, Callable, Literal, Self, Sequence, overload
3
+ from typing import Any, AsyncGenerator, Callable, Literal, Self, Sequence, overload
4
4
 
5
5
  import numpy as np
6
6
  import yaml
@@ -557,6 +557,42 @@ class _LLMClient(BaseModel):
557
557
  task_ids = list(self._tasks.keys())
558
558
  return [await self.wait_for(tid) for tid in task_ids]
559
559
 
560
+ async def as_completed(
561
+ self, task_ids: Sequence[int] | None = None
562
+ ) -> AsyncGenerator[tuple[int, APIResponse | None], None]:
563
+ """Yield ``(task_id, result)`` pairs as tasks complete.
564
+
565
+ Args:
566
+ task_ids: Optional sequence of task IDs to wait on. If ``None``,
567
+ all queued tasks are watched.
568
+
569
+ Yields:
570
+ Tuples of task ID and ``APIResponse`` as each task finishes.
571
+ """
572
+
573
+ if task_ids is None:
574
+ tasks_map: dict[asyncio.Task, int] = {
575
+ task: tid for tid, task in self._tasks.items()
576
+ }
577
+ else:
578
+ tasks_map = {
579
+ self._tasks[tid]: tid for tid in task_ids if tid in self._tasks
580
+ }
581
+
582
+ # Yield any tasks that have already completed
583
+ for task in list(tasks_map.keys()):
584
+ if task.done():
585
+ tid = tasks_map.pop(task)
586
+ yield tid, self._results.get(tid, await task)
587
+
588
+ while tasks_map:
589
+ done, _ = await asyncio.wait(
590
+ set(tasks_map.keys()), return_when=asyncio.FIRST_COMPLETED
591
+ )
592
+ for task in done:
593
+ tid = tasks_map.pop(task)
594
+ yield tid, self._results.get(tid, await task)
595
+
560
596
  async def stream(
561
597
  self,
562
598
  prompt: str | Conversation,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lm_deluge
3
- Version: 0.0.39
3
+ Version: 0.0.40
4
4
  Summary: Python utility for using LLM API models.
5
5
  Author-email: Benjamin Anderson <ben@trytaylor.ai>
6
6
  Requires-Python: >=3.10
@@ -111,14 +111,17 @@ await client.process_prompts_async(
111
111
 
112
112
  ### Queueing individual prompts
113
113
 
114
- You can queue prompts one at a time and track progress explicitly:
114
+ You can queue prompts one at a time and track progress explicitly. Iterate over
115
+ results as they finish with `as_completed` (or gather them all at once with
116
+ `wait_for_all`):
115
117
 
116
118
  ```python
117
119
  client = LLMClient("gpt-4.1-mini", progress="tqdm")
118
120
  client.open()
119
- task_id = client.start_nowait("hello there")
121
+ client.start_nowait("hello there")
120
122
  # ... queue more tasks ...
121
- results = await client.wait_for_all()
123
+ async for task_id, result in client.as_completed():
124
+ print(task_id, result.completion)
122
125
  client.close()
123
126
  ```
124
127
 
@@ -3,7 +3,7 @@ lm_deluge/agent.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
3
  lm_deluge/batches.py,sha256=vJXVnuuGkIQnXoDPODPERrvdG9X1Ov1jnXExnPe6ZAc,21772
4
4
  lm_deluge/cache.py,sha256=VB1kv8rM2t5XWPR60uhszFcxLDnVKOe1oA5hYjVDjIo,4375
5
5
  lm_deluge/cli.py,sha256=Ilww5gOw3J5v0NReq_Ra4hhxU4BCIJBl1oTGxJZKedc,12065
6
- lm_deluge/client.py,sha256=sXsONU7j0KnhsE8iDKYpqwTmuNtSMnpn_v7o_9Vdioo,32824
6
+ lm_deluge/client.py,sha256=ddLk9p4nHMQdDKTV2klPJ9D5Xoj89WepWMHcFFo0we0,34102
7
7
  lm_deluge/config.py,sha256=H1tQyJDNHGFuwxqQNL5Z-CjWAC0luHSBA3iY_pxmACM,932
8
8
  lm_deluge/embed.py,sha256=CO-TOlC5kOTAM8lcnicoG4u4K664vCBwHF1vHa-nAGg,13382
9
9
  lm_deluge/errors.py,sha256=oHjt7YnxWbh-eXMScIzov4NvpJMo0-2r5J6Wh5DQ1tk,209
@@ -64,8 +64,8 @@ lm_deluge/util/logprobs.py,sha256=UkBZakOxWluaLqHrjARu7xnJ0uCHVfLGHJdnYlEcutk,11
64
64
  lm_deluge/util/spatial.py,sha256=BsF_UKhE-x0xBirc-bV1xSKZRTUhsOBdGqsMKme20C8,4099
65
65
  lm_deluge/util/validation.py,sha256=hz5dDb3ebvZrZhnaWxOxbNSVMI6nmaOODBkk0htAUhs,1575
66
66
  lm_deluge/util/xml.py,sha256=Ft4zajoYBJR3HHCt2oHwGfymGLdvp_gegVmJ-Wqk4Ck,10547
67
- lm_deluge-0.0.39.dist-info/licenses/LICENSE,sha256=uNNXGXPCw2TC7CUs7SEBkA-Mz6QBQFWUUEWDMgEs1dU,1058
68
- lm_deluge-0.0.39.dist-info/METADATA,sha256=Z7KCxlMkG9WBp3rVJyjy-OCQDHy2ebMM6yXu67bjpaA,13295
69
- lm_deluge-0.0.39.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
70
- lm_deluge-0.0.39.dist-info/top_level.txt,sha256=hqU-TJX93yBwpgkDtYcXyLr3t7TLSCCZ_reytJjwBaE,10
71
- lm_deluge-0.0.39.dist-info/RECORD,,
67
+ lm_deluge-0.0.40.dist-info/licenses/LICENSE,sha256=uNNXGXPCw2TC7CUs7SEBkA-Mz6QBQFWUUEWDMgEs1dU,1058
68
+ lm_deluge-0.0.40.dist-info/METADATA,sha256=QMWHzRuDQohIf6ZWjWpajRmQhAh2aJqEqAnXgVZ613s,13443
69
+ lm_deluge-0.0.40.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
70
+ lm_deluge-0.0.40.dist-info/top_level.txt,sha256=hqU-TJX93yBwpgkDtYcXyLr3t7TLSCCZ_reytJjwBaE,10
71
+ lm_deluge-0.0.40.dist-info/RECORD,,