ccs-llmconnector 1.1.0__py3-none-any.whl → 1.1.2__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.
llmconnector/utils.py CHANGED
@@ -1,78 +1,78 @@
1
- from __future__ import annotations
2
-
3
- import asyncio
4
- import logging
5
- import time
6
- from typing import Awaitable, Callable, TypeVar
7
-
8
- T = TypeVar("T")
9
- logger = logging.getLogger(__name__)
10
-
11
-
12
- def clamp_retries(max_retries: int | None) -> int:
13
- if max_retries is None:
14
- return 0
15
- if max_retries < 0:
16
- return 0
17
- return max_retries
18
-
19
-
20
- def compute_delay(attempt: int, retry_backoff_s: float) -> float:
21
- return retry_backoff_s * (2**attempt)
22
-
23
-
24
- def run_with_retries(
25
- *,
26
- func: Callable[[], T],
27
- max_retries: int,
28
- retry_backoff_s: float,
29
- request_id: str | None = None,
30
- ) -> T:
31
- attempt = 0
32
- while True:
33
- try:
34
- return func()
35
- except Exception as exc:
36
- if attempt >= max_retries:
37
- raise
38
- delay = compute_delay(attempt, retry_backoff_s)
39
- logger.warning(
40
- "Retrying LLM request: attempt=%d delay=%.2fs request_id=%s error=%s",
41
- attempt + 1,
42
- delay,
43
- request_id,
44
- exc,
45
- )
46
- time.sleep(delay)
47
- attempt += 1
48
-
49
-
50
- async def run_with_retries_async(
51
- *,
52
- func: Callable[[], Awaitable[T]],
53
- max_retries: int,
54
- retry_backoff_s: float,
55
- request_id: str | None = None,
56
- ) -> T:
57
- attempt = 0
58
- while True:
59
- try:
60
- return await func()
61
- except Exception as exc:
62
- if attempt >= max_retries:
63
- raise
64
- delay = compute_delay(attempt, retry_backoff_s)
65
- logger.warning(
66
- "Retrying LLM request (async): attempt=%d delay=%.2fs request_id=%s error=%s",
67
- attempt + 1,
68
- delay,
69
- request_id,
70
- exc,
71
- )
72
- await asyncio.sleep(delay)
73
- attempt += 1
74
-
75
-
76
- async def run_sync_in_thread(func: Callable[[], T]) -> T:
77
- loop = asyncio.get_running_loop()
1
+ from __future__ import annotations
2
+
3
+ import asyncio
4
+ import logging
5
+ import time
6
+ from typing import Awaitable, Callable, TypeVar
7
+
8
+ T = TypeVar("T")
9
+ logger = logging.getLogger(__name__)
10
+
11
+
12
+ def clamp_retries(max_retries: int | None) -> int:
13
+ if max_retries is None:
14
+ return 0
15
+ if max_retries < 0:
16
+ return 0
17
+ return max_retries
18
+
19
+
20
+ def compute_delay(attempt: int, retry_backoff_s: float) -> float:
21
+ return retry_backoff_s * (2**attempt)
22
+
23
+
24
+ def run_with_retries(
25
+ *,
26
+ func: Callable[[], T],
27
+ max_retries: int,
28
+ retry_backoff_s: float,
29
+ request_id: str | None = None,
30
+ ) -> T:
31
+ attempt = 0
32
+ while True:
33
+ try:
34
+ return func()
35
+ except Exception as exc:
36
+ if attempt >= max_retries:
37
+ raise
38
+ delay = compute_delay(attempt, retry_backoff_s)
39
+ logger.warning(
40
+ "Retrying LLM request: attempt=%d delay=%.2fs request_id=%s error=%s",
41
+ attempt + 1,
42
+ delay,
43
+ request_id,
44
+ exc,
45
+ )
46
+ time.sleep(delay)
47
+ attempt += 1
48
+
49
+
50
+ async def run_with_retries_async(
51
+ *,
52
+ func: Callable[[], Awaitable[T]],
53
+ max_retries: int,
54
+ retry_backoff_s: float,
55
+ request_id: str | None = None,
56
+ ) -> T:
57
+ attempt = 0
58
+ while True:
59
+ try:
60
+ return await func()
61
+ except Exception as exc:
62
+ if attempt >= max_retries:
63
+ raise
64
+ delay = compute_delay(attempt, retry_backoff_s)
65
+ logger.warning(
66
+ "Retrying LLM request (async): attempt=%d delay=%.2fs request_id=%s error=%s",
67
+ attempt + 1,
68
+ delay,
69
+ request_id,
70
+ exc,
71
+ )
72
+ await asyncio.sleep(delay)
73
+ attempt += 1
74
+
75
+
76
+ async def run_sync_in_thread(func: Callable[[], T]) -> T:
77
+ loop = asyncio.get_running_loop()
78
78
  return await loop.run_in_executor(None, func)
@@ -1,16 +0,0 @@
1
- ccs_llmconnector-1.1.0.dist-info/licenses/LICENSE,sha256=rPcz2YmBB9VUWZTLJcRO_B4jKDpqmGRYi2eSI-unysg,1083
2
- llmconnector/__init__.py,sha256=eSsSwcrSbQAMxz6DkmN4XaLNZn1_ClQVFj7USRp3geU,1337
3
- llmconnector/anthropic_client.py,sha256=nR7gZJ5fa_cJ334SkeNsBuwTkEAF0pF4C0ew-VuhSRY,12995
4
- llmconnector/client.py,sha256=2emUbeuOZEGRB7_bpzwCzdhY2zoHlRFKR0gcv1rfU_8,13560
5
- llmconnector/client_cli.py,sha256=8-C275ah4VrYW1noiPr78p8BB-rf7utiMFYMbFLuUVc,11421
6
- llmconnector/gemini_client.py,sha256=BbtVoUi6D-HcMs80OF18GLiJsrrjbXAY0LDw2Kw8QA8,18697
7
- llmconnector/grok_client.py,sha256=oHqY6ooeuCSAGhkPpUprAzbXxmdLlnI-Gk8XDCvWW_0,10986
8
- llmconnector/openai_client.py,sha256=WibOK2ErJyaX31SMM-siHtenhd-e1Du0uV9B2R_CN6s,10795
9
- llmconnector/py.typed,sha256=frcCV1k9oG9oKj3dpUqdJg1PxRT2RSN_XKdLCPjaYaY,2
10
- llmconnector/types.py,sha256=Rs9K78L5BBjQn_JuK2APCu123ANPSNeSaO6jHsgYEJA,1239
11
- llmconnector/utils.py,sha256=iUzjnSINn5cX2Jq3E0CIjMUR_yBLblHCvCcB8NuXUiM,1970
12
- ccs_llmconnector-1.1.0.dist-info/METADATA,sha256=4XLz7J-BscL7FIMmReoys5FsGxPRjq5bnW4GCADWyNk,17001
13
- ccs_llmconnector-1.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
14
- ccs_llmconnector-1.1.0.dist-info/entry_points.txt,sha256=eFvLY3nHAG_QhaKlemhhK7echfezW0KiMdSNMZOStLc,60
15
- ccs_llmconnector-1.1.0.dist-info/top_level.txt,sha256=Doer7TAUsN8UXQfPHPNsuBXVNCz2uV-Q0v4t4fwv_MM,13
16
- ccs_llmconnector-1.1.0.dist-info/RECORD,,