ccs-llmconnector 1.0.6__py3-none-any.whl → 1.1.1__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/types.py ADDED
@@ -0,0 +1,49 @@
1
+ from __future__ import annotations
2
+
3
+ from pathlib import Path
4
+ from typing import Optional, Sequence, TypedDict, Union
5
+
6
+ ImageInput = Union[str, Path]
7
+
8
+
9
+ class Message(TypedDict):
10
+ role: str
11
+ content: str
12
+
13
+
14
+ MessageSequence = Sequence[Message]
15
+
16
+
17
+ class RequestOptions(TypedDict, total=False):
18
+ request_id: str
19
+ timeout_s: float
20
+ max_retries: int
21
+ retry_backoff_s: float
22
+ reasoning_effort: str
23
+ max_tokens: int
24
+ images: Sequence[ImageInput]
25
+ messages: MessageSequence
26
+
27
+
28
+ def normalize_messages(
29
+ *,
30
+ prompt: Optional[str],
31
+ messages: Optional[MessageSequence],
32
+ ) -> list[Message]:
33
+ result: list[Message] = []
34
+ if messages:
35
+ for message in messages:
36
+ role = message.get("role")
37
+ content = message.get("content")
38
+ if not isinstance(role, str) or not role:
39
+ raise ValueError("message role must be a non-empty string")
40
+ if content is None:
41
+ content = ""
42
+ if not isinstance(content, str):
43
+ raise ValueError("message content must be a string")
44
+ result.append({"role": role, "content": content})
45
+
46
+ if prompt:
47
+ result.append({"role": "user", "content": prompt})
48
+
49
+ return result
llmconnector/utils.py ADDED
@@ -0,0 +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()
78
+ return await loop.run_in_executor(None, func)
@@ -1,14 +0,0 @@
1
- ccs_llmconnector-1.0.6.dist-info/licenses/LICENSE,sha256=rPcz2YmBB9VUWZTLJcRO_B4jKDpqmGRYi2eSI-unysg,1083
2
- llmconnector/__init__.py,sha256=RIprtUKqu2SrUmPJ8C7lPpCpvknpJqd93CUyxcaXy1I,1213
3
- llmconnector/anthropic_client.py,sha256=sBcJVmYbqTWeT_twcpDz-00XTreLjZlJ1ifVE4ik5TM,7889
4
- llmconnector/client.py,sha256=t_vWLcL0QS7w1KNwVYc8KEmtmHih5elRMelY3RhApFg,6261
5
- llmconnector/client_cli.py,sha256=cxu2NKix-9axNeY5jbfqR5rKPKJ-oqBSnJCY8PKMhYY,10660
6
- llmconnector/gemini_client.py,sha256=ZdNf4teG0RiV95y3mRMgsjhS-1vrsrPPIEjP9CsKYKE,10893
7
- llmconnector/grok_client.py,sha256=SXcufcsrYDQgx0tK7EOfIBybTZlEdhZc0MV6siUHyyQ,6453
8
- llmconnector/openai_client.py,sha256=TeXfJq1YnQ9gegjpQyOj_7h9VY4tJk6dYvEw4KQIUU8,5993
9
- llmconnector/py.typed,sha256=frcCV1k9oG9oKj3dpUqdJg1PxRT2RSN_XKdLCPjaYaY,2
10
- ccs_llmconnector-1.0.6.dist-info/METADATA,sha256=msjO02kEy78WrivW8TL6g4ANV8VkFYnVyLFxmMQ9DYk,15041
11
- ccs_llmconnector-1.0.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
12
- ccs_llmconnector-1.0.6.dist-info/entry_points.txt,sha256=eFvLY3nHAG_QhaKlemhhK7echfezW0KiMdSNMZOStLc,60
13
- ccs_llmconnector-1.0.6.dist-info/top_level.txt,sha256=Doer7TAUsN8UXQfPHPNsuBXVNCz2uV-Q0v4t4fwv_MM,13
14
- ccs_llmconnector-1.0.6.dist-info/RECORD,,