GPTRouter 0.3.6__tar.gz → 0.3.7__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: GPTRouter
3
- Version: 0.3.6
3
+ Version: 0.3.7
4
4
  Summary: A Python package for working with GPTRouter APIs
5
5
  Author-email: sirjanpreet@writesonic.com
6
6
  Classifier: Development Status :: 3 - Alpha
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: GPTRouter
3
- Version: 0.3.6
3
+ Version: 0.3.7
4
4
  Summary: A Python package for working with GPTRouter APIs
5
5
  Author-email: sirjanpreet@writesonic.com
6
6
  Classifier: Development Status :: 3 - Alpha
@@ -1,4 +1,5 @@
1
1
  from __future__ import annotations
2
+ import asyncio
2
3
  from pydantic import parse_obj_as
3
4
  import logging
4
5
  import json
@@ -153,6 +154,7 @@ class GPTRouterClient:
153
154
 
154
155
  async def astream_events(self, *, path: str, method: str, payload: dict, **kwargs):
155
156
  retry_count = kwargs.get("stream_retry_count") or 1
157
+ stop_stream_signal = kwargs.get("stop_stream_signal")
156
158
  async_retrying = AsyncRetrying(
157
159
  stop=stop_after_attempt(retry_count),
158
160
  wait=wait_fixed(0.5),
@@ -191,6 +193,10 @@ class GPTRouterClient:
191
193
  raise ServerError("Server error")
192
194
  response.raise_for_status()
193
195
  async for line in response.aiter_lines():
196
+ if stop_stream_signal and stop_stream_signal.is_set():
197
+ logger.info("Stopping stream due to signal")
198
+ await response.aclose()
199
+ return
194
200
  try:
195
201
  if line.strip() == "":
196
202
  continue
@@ -223,6 +229,10 @@ class GPTRouterClient:
223
229
  ) from err
224
230
  except httpx.TimeoutException as err:
225
231
  raise TimeoutError("Request timed out") from err
232
+ finally:
233
+ if stop_stream_signal and stop_stream_signal.is_set():
234
+ logger.info("Stream stopped due to signal")
235
+ return
226
236
 
227
237
  def stream_events(
228
238
  self, *, path: str, method: str, payload: dict, **kwargs
@@ -338,6 +348,7 @@ class GPTRouterClient:
338
348
  ordered_generation_requests: List[ModelGenerationRequest],
339
349
  is_stream=False,
340
350
  model_router_metadata: Optional[GPTRouterMetadata] = None,
351
+ stop_stream_signal: Optional[asyncio.Event] = None,
341
352
  **kwargs,
342
353
  ) -> GenerationResponse:
343
354
  api_path = "/v1/generate"
@@ -355,6 +366,7 @@ class GPTRouterClient:
355
366
  path=api_path,
356
367
  method=api_method,
357
368
  payload=api_payload,
369
+ stop_stream_signal=stop_stream_signal,
358
370
  **kwargs,
359
371
  )
360
372
  result = await self._async_api_call(
@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
5
5
 
6
6
  setup(
7
7
  name="GPTRouter",
8
- version="0.3.6",
8
+ version="0.3.7",
9
9
  description="A Python package for working with GPTRouter APIs",
10
10
  long_description=long_description,
11
11
  long_description_content_type="text/markdown",
File without changes
File without changes
File without changes
File without changes
File without changes