lm-deluge 0.0.71__py3-none-any.whl → 0.0.72__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.
@@ -90,9 +90,32 @@ class APIRequestBase(ABC):
90
90
  start -> poll -> result style of request.
91
91
  """
92
92
  assert self.context.status_tracker, "no status tracker"
93
- start_time = time.time()
93
+ poll_interval = 5.0
94
+ attempt_start = time.monotonic()
95
+ deadline = attempt_start + self.context.request_timeout
96
+ response_id: str | None = None
97
+ last_status: str | None = None
98
+
94
99
  async with aiohttp.ClientSession() as session:
95
- last_status: str | None = None
100
+
101
+ async def cancel_response(reason: str) -> None:
102
+ nonlocal response_id
103
+ if not response_id:
104
+ return
105
+ cancel_url = f"{self.url}/{response_id}/cancel"
106
+ try:
107
+ async with session.post(
108
+ url=cancel_url,
109
+ headers=self.request_header,
110
+ ) as cancel_response:
111
+ cancel_response.raise_for_status()
112
+ print(f"Background req {response_id} cancelled: {reason}")
113
+ except (
114
+ Exception
115
+ ) as cancel_err: # pragma: no cover - best effort logging
116
+ print(
117
+ f"Failed to cancel background req {response_id}: {cancel_err}"
118
+ )
96
119
 
97
120
  try:
98
121
  self.context.status_tracker.total_requests += 1
@@ -109,14 +132,11 @@ class APIRequestBase(ABC):
109
132
  last_status = data["status"]
110
133
 
111
134
  while True:
112
- if time.time() - start_time > self.context.request_timeout:
113
- # cancel the response
114
- async with session.post(
115
- url=f"{self.url}/{response_id}/cancel",
116
- headers=self.request_header,
117
- ) as http_response:
118
- http_response.raise_for_status()
119
-
135
+ now = time.monotonic()
136
+ remaining = deadline - now
137
+ if remaining <= 0:
138
+ elapsed = now - attempt_start
139
+ await cancel_response(f"timed out after {elapsed:.1f}s")
120
140
  return APIResponse(
121
141
  id=self.context.task_id,
122
142
  model_internal=self.context.model_name,
@@ -128,8 +148,9 @@ class APIRequestBase(ABC):
128
148
  content=None,
129
149
  usage=None,
130
150
  )
151
+
131
152
  # poll for the response
132
- await asyncio.sleep(5.0)
153
+ await asyncio.sleep(min(poll_interval, max(remaining, 0)))
133
154
  async with session.get(
134
155
  url=f"{self.url}/{response_id}",
135
156
  headers=self.request_header,
@@ -146,6 +167,8 @@ class APIRequestBase(ABC):
146
167
  return await self.handle_response(http_response)
147
168
 
148
169
  except Exception as e:
170
+ if response_id:
171
+ await cancel_response(f"errored: {type(e).__name__}")
149
172
  raise_if_modal_exception(e)
150
173
  tb = traceback.format_exc()
151
174
  print(tb)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lm_deluge
3
- Version: 0.0.71
3
+ Version: 0.0.72
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
@@ -18,7 +18,7 @@ lm_deluge/usage.py,sha256=xz9tAw2hqaJvv9aAVhnQ6N1Arn7fS8Shb28VwCW26wI,5136
18
18
  lm_deluge/warnings.py,sha256=nlDJMCw30VhDEFxqLO2-bfXH_Tv5qmlglzUSbokCSw8,1498
19
19
  lm_deluge/api_requests/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
20
20
  lm_deluge/api_requests/anthropic.py,sha256=QGq3G5jJIGcoM2HdRt73GgkvZs4GOViyjYexWex05Vk,8927
21
- lm_deluge/api_requests/base.py,sha256=GCcydwBRx4_xAuYLvasXlyj-TgqvKAVhVvxRfJkvPbY,9471
21
+ lm_deluge/api_requests/base.py,sha256=mXEM85mcU_5LD-ugELpCl28tv-tpHKcaxerTIVLQZVo,10436
22
22
  lm_deluge/api_requests/bedrock.py,sha256=Uppne03GcIEk1tVYzoGu7GXK2Sg94a_xvFTLDRN_phY,15412
23
23
  lm_deluge/api_requests/chat_reasoning.py,sha256=sJvstvKFqsSBUjYcwxzGt2_FH4cEp3Z6gKcBPyPjGwk,236
24
24
  lm_deluge/api_requests/common.py,sha256=BZ3vRO5TB669_UsNKugkkuFSzoLHOYJIKt4nV4sf4vc,422
@@ -69,8 +69,8 @@ lm_deluge/util/logprobs.py,sha256=UkBZakOxWluaLqHrjARu7xnJ0uCHVfLGHJdnYlEcutk,11
69
69
  lm_deluge/util/spatial.py,sha256=BsF_UKhE-x0xBirc-bV1xSKZRTUhsOBdGqsMKme20C8,4099
70
70
  lm_deluge/util/validation.py,sha256=hz5dDb3ebvZrZhnaWxOxbNSVMI6nmaOODBkk0htAUhs,1575
71
71
  lm_deluge/util/xml.py,sha256=Ft4zajoYBJR3HHCt2oHwGfymGLdvp_gegVmJ-Wqk4Ck,10547
72
- lm_deluge-0.0.71.dist-info/licenses/LICENSE,sha256=uNNXGXPCw2TC7CUs7SEBkA-Mz6QBQFWUUEWDMgEs1dU,1058
73
- lm_deluge-0.0.71.dist-info/METADATA,sha256=kgq3xiS7tMIbXpx5UkhCEA_yJAJvgGOPaie_ZlScTxQ,13514
74
- lm_deluge-0.0.71.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
75
- lm_deluge-0.0.71.dist-info/top_level.txt,sha256=hqU-TJX93yBwpgkDtYcXyLr3t7TLSCCZ_reytJjwBaE,10
76
- lm_deluge-0.0.71.dist-info/RECORD,,
72
+ lm_deluge-0.0.72.dist-info/licenses/LICENSE,sha256=uNNXGXPCw2TC7CUs7SEBkA-Mz6QBQFWUUEWDMgEs1dU,1058
73
+ lm_deluge-0.0.72.dist-info/METADATA,sha256=Ffg1w5rphPj_MScOCYhA1cQmSKsc2XjBqJefXiZOtDk,13514
74
+ lm_deluge-0.0.72.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
75
+ lm_deluge-0.0.72.dist-info/top_level.txt,sha256=hqU-TJX93yBwpgkDtYcXyLr3t7TLSCCZ_reytJjwBaE,10
76
+ lm_deluge-0.0.72.dist-info/RECORD,,