ai-lib-python 0.8.3__py3-none-any.whl → 0.8.6__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.
- ai_lib_python/__init__.py +62 -62
- ai_lib_python/_features.py +52 -51
- ai_lib_python/_version.py +13 -0
- ai_lib_python/batch/__init__.py +15 -15
- ai_lib_python/batch/collector.py +241 -247
- ai_lib_python/batch/executor.py +228 -224
- ai_lib_python/cache/__init__.py +26 -26
- ai_lib_python/cache/backends.py +372 -380
- ai_lib_python/cache/key.py +239 -237
- ai_lib_python/cache/manager.py +333 -333
- ai_lib_python/client/__init__.py +37 -37
- ai_lib_python/client/builder.py +598 -561
- ai_lib_python/client/cancel.py +372 -372
- ai_lib_python/client/core.py +568 -517
- ai_lib_python/client/response.py +170 -134
- ai_lib_python/computer_use/__init__.py +234 -227
- ai_lib_python/drivers/__init__.py +140 -140
- ai_lib_python/drivers/anthropic.py +191 -183
- ai_lib_python/drivers/gemini.py +199 -187
- ai_lib_python/drivers/openai.py +137 -137
- ai_lib_python/embeddings/__init__.py +36 -36
- ai_lib_python/embeddings/client.py +341 -343
- ai_lib_python/embeddings/types.py +232 -234
- ai_lib_python/embeddings/vectors.py +245 -246
- ai_lib_python/errors/__init__.py +54 -54
- ai_lib_python/errors/base.py +325 -325
- ai_lib_python/errors/classification.py +242 -240
- ai_lib_python/errors/standard_codes.py +280 -280
- ai_lib_python/guardrails/__init__.py +35 -35
- ai_lib_python/guardrails/filters.py +6 -2
- ai_lib_python/guardrails/validators.py +39 -27
- ai_lib_python/mcp/__init__.py +183 -181
- ai_lib_python/multimodal/__init__.py +143 -143
- ai_lib_python/pipeline/__init__.py +55 -55
- ai_lib_python/pipeline/accumulate.py +248 -248
- ai_lib_python/pipeline/base.py +230 -240
- ai_lib_python/pipeline/compliance.py +224 -0
- ai_lib_python/pipeline/decode.py +275 -281
- ai_lib_python/pipeline/event_map.py +601 -507
- ai_lib_python/pipeline/fan_out.py +278 -284
- ai_lib_python/pipeline/select.py +308 -297
- ai_lib_python/plugins/__init__.py +32 -32
- ai_lib_python/plugins/base.py +294 -294
- ai_lib_python/plugins/hooks.py +294 -296
- ai_lib_python/plugins/middleware.py +281 -285
- ai_lib_python/plugins/registry.py +294 -294
- ai_lib_python/protocol/__init__.py +71 -71
- ai_lib_python/protocol/loader.py +341 -329
- ai_lib_python/protocol/manifest.py +397 -387
- ai_lib_python/protocol/v2/__init__.py +22 -22
- ai_lib_python/protocol/v2/manifest.py +292 -292
- ai_lib_python/protocol/validator.py +445 -460
- ai_lib_python/py.typed +1 -1
- ai_lib_python/registry/__init__.py +175 -173
- ai_lib_python/rerank/__init__.py +20 -20
- ai_lib_python/rerank/client.py +146 -144
- ai_lib_python/resilience/__init__.py +102 -102
- ai_lib_python/resilience/backpressure.py +222 -225
- ai_lib_python/resilience/circuit_breaker.py +308 -318
- ai_lib_python/resilience/executor.py +336 -348
- ai_lib_python/resilience/fallback.py +341 -341
- ai_lib_python/resilience/preflight.py +397 -401
- ai_lib_python/resilience/rate_limiter.py +289 -291
- ai_lib_python/resilience/retry.py +302 -300
- ai_lib_python/resilience/signals.py +281 -283
- ai_lib_python/routing/__init__.py +118 -118
- ai_lib_python/routing/manager.py +592 -593
- ai_lib_python/routing/strategy.py +345 -345
- ai_lib_python/routing/types.py +395 -397
- ai_lib_python/structured/__init__.py +33 -33
- ai_lib_python/structured/json_mode.py +285 -285
- ai_lib_python/structured/schema.py +320 -322
- ai_lib_python/structured/validator.py +338 -344
- ai_lib_python/stt/__init__.py +22 -22
- ai_lib_python/stt/client.py +173 -171
- ai_lib_python/telemetry/__init__.py +127 -127
- ai_lib_python/telemetry/exporters/__init__.py +9 -9
- ai_lib_python/telemetry/exporters/prometheus.py +111 -111
- ai_lib_python/telemetry/feedback.py +446 -446
- ai_lib_python/telemetry/health.py +409 -409
- ai_lib_python/telemetry/logger.py +388 -392
- ai_lib_python/telemetry/metrics.py +486 -496
- ai_lib_python/telemetry/tracer.py +471 -473
- ai_lib_python/tokens/__init__.py +25 -25
- ai_lib_python/tokens/counter.py +282 -282
- ai_lib_python/tokens/estimator.py +286 -286
- ai_lib_python/transport/__init__.py +44 -34
- ai_lib_python/transport/auth.py +274 -141
- ai_lib_python/transport/http.py +410 -400
- ai_lib_python/transport/pool.py +422 -426
- ai_lib_python/tts/__init__.py +22 -22
- ai_lib_python/tts/client.py +171 -164
- ai_lib_python/types/__init__.py +61 -41
- ai_lib_python/types/events.py +333 -343
- ai_lib_python/types/execution_result.py +49 -0
- ai_lib_python/types/message.py +352 -352
- ai_lib_python/types/text_tool.py +249 -0
- ai_lib_python/types/tool.py +210 -209
- ai_lib_python/utils/__init__.py +21 -21
- ai_lib_python/utils/tool_call_assembler.py +314 -317
- ai_lib_python-0.8.6.dist-info/METADATA +447 -0
- ai_lib_python-0.8.6.dist-info/RECORD +107 -0
- {ai_lib_python-0.8.3.dist-info → ai_lib_python-0.8.6.dist-info}/WHEEL +1 -1
- {ai_lib_python-0.8.3.dist-info → ai_lib_python-0.8.6.dist-info}/licenses/LICENSE-APACHE +201 -201
- {ai_lib_python-0.8.3.dist-info → ai_lib_python-0.8.6.dist-info}/licenses/LICENSE-MIT +21 -21
- ai_lib_python-0.8.3.dist-info/METADATA +0 -1023
- ai_lib_python-0.8.3.dist-info/RECORD +0 -103
ai_lib_python/__init__.py
CHANGED
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
"""AI-Protocol 官方 Python 运行时:提供统一的多厂商 AI 模型交互接口。
|
|
2
|
-
|
|
3
|
-
ai-lib-python: Official Python Runtime for AI-Protocol.
|
|
4
|
-
|
|
5
|
-
The canonical Pythonic implementation for unified AI model interaction.
|
|
6
|
-
Core principle: All logic is operators, all configuration is protocol.
|
|
7
|
-
"""
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
from ai_lib_python.
|
|
21
|
-
from ai_lib_python.
|
|
22
|
-
from ai_lib_python.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
__all__ = [
|
|
33
|
-
# Client
|
|
34
|
-
"AiClient",
|
|
35
|
-
"AiClientBuilder",
|
|
36
|
-
# Feature flags
|
|
37
|
-
"HAS_AUDIO",
|
|
38
|
-
"HAS_KEYRING",
|
|
39
|
-
"HAS_TELEMETRY",
|
|
40
|
-
"HAS_TOKENIZER",
|
|
41
|
-
"HAS_VISION",
|
|
42
|
-
"HAS_WATCHDOG",
|
|
43
|
-
"require_extra",
|
|
44
|
-
# Errors
|
|
45
|
-
"AiLibError",
|
|
46
|
-
"CallStats",
|
|
47
|
-
"ChatResponse",
|
|
48
|
-
"ContentBlock",
|
|
49
|
-
# Types - Message
|
|
50
|
-
"Message",
|
|
51
|
-
"MessageContent",
|
|
52
|
-
"MessageRole",
|
|
53
|
-
"ProtocolError",
|
|
54
|
-
# Types - Events
|
|
55
|
-
"StreamingEvent",
|
|
56
|
-
"ToolCall",
|
|
57
|
-
# Types - Tool
|
|
58
|
-
"ToolDefinition",
|
|
59
|
-
"TransportError",
|
|
60
|
-
# Version
|
|
61
|
-
"__version__",
|
|
62
|
-
]
|
|
1
|
+
"""AI-Protocol 官方 Python 运行时:提供统一的多厂商 AI 模型交互接口。
|
|
2
|
+
|
|
3
|
+
ai-lib-python: Official Python Runtime for AI-Protocol.
|
|
4
|
+
|
|
5
|
+
The canonical Pythonic implementation for unified AI model interaction.
|
|
6
|
+
Core principle: All logic is operators, all configuration is protocol.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
from ai_lib_python._features import (
|
|
12
|
+
HAS_AUDIO,
|
|
13
|
+
HAS_KEYRING,
|
|
14
|
+
HAS_TELEMETRY,
|
|
15
|
+
HAS_TOKENIZER,
|
|
16
|
+
HAS_VISION,
|
|
17
|
+
HAS_WATCHDOG,
|
|
18
|
+
require_extra,
|
|
19
|
+
)
|
|
20
|
+
from ai_lib_python._version import __version__
|
|
21
|
+
from ai_lib_python.client import AiClient, AiClientBuilder, CallStats, ChatResponse
|
|
22
|
+
from ai_lib_python.errors import AiLibError, ProtocolError, TransportError
|
|
23
|
+
from ai_lib_python.types.events import StreamingEvent
|
|
24
|
+
from ai_lib_python.types.message import (
|
|
25
|
+
ContentBlock,
|
|
26
|
+
Message,
|
|
27
|
+
MessageContent,
|
|
28
|
+
MessageRole,
|
|
29
|
+
)
|
|
30
|
+
from ai_lib_python.types.tool import ToolCall, ToolDefinition
|
|
31
|
+
|
|
32
|
+
__all__ = [
|
|
33
|
+
# Client
|
|
34
|
+
"AiClient",
|
|
35
|
+
"AiClientBuilder",
|
|
36
|
+
# Feature flags
|
|
37
|
+
"HAS_AUDIO",
|
|
38
|
+
"HAS_KEYRING",
|
|
39
|
+
"HAS_TELEMETRY",
|
|
40
|
+
"HAS_TOKENIZER",
|
|
41
|
+
"HAS_VISION",
|
|
42
|
+
"HAS_WATCHDOG",
|
|
43
|
+
"require_extra",
|
|
44
|
+
# Errors
|
|
45
|
+
"AiLibError",
|
|
46
|
+
"CallStats",
|
|
47
|
+
"ChatResponse",
|
|
48
|
+
"ContentBlock",
|
|
49
|
+
# Types - Message
|
|
50
|
+
"Message",
|
|
51
|
+
"MessageContent",
|
|
52
|
+
"MessageRole",
|
|
53
|
+
"ProtocolError",
|
|
54
|
+
# Types - Events
|
|
55
|
+
"StreamingEvent",
|
|
56
|
+
"ToolCall",
|
|
57
|
+
# Types - Tool
|
|
58
|
+
"ToolDefinition",
|
|
59
|
+
"TransportError",
|
|
60
|
+
# Version
|
|
61
|
+
"__version__",
|
|
62
|
+
]
|
ai_lib_python/_features.py
CHANGED
|
@@ -1,51 +1,52 @@
|
|
|
1
|
-
"""运行时特性检测:检查可选依赖以确定可用的能力模块。
|
|
2
|
-
|
|
3
|
-
Runtime feature detection for optional extras.
|
|
4
|
-
|
|
5
|
-
Checks availability of optional dependencies to determine which
|
|
6
|
-
capability modules can be used.
|
|
7
|
-
"""
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
f"
|
|
51
|
-
|
|
1
|
+
"""运行时特性检测:检查可选依赖以确定可用的能力模块。
|
|
2
|
+
|
|
3
|
+
Runtime feature detection for optional extras.
|
|
4
|
+
|
|
5
|
+
Checks availability of optional dependencies to determine which
|
|
6
|
+
capability modules can be used.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _check_import(module_name: str) -> bool:
|
|
13
|
+
"""Check if a module is importable."""
|
|
14
|
+
try:
|
|
15
|
+
__import__(module_name)
|
|
16
|
+
return True
|
|
17
|
+
except ImportError:
|
|
18
|
+
return False
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
# Capability feature flags
|
|
22
|
+
HAS_VISION: bool = _check_import("PIL")
|
|
23
|
+
HAS_AUDIO: bool = _check_import("soundfile")
|
|
24
|
+
HAS_TELEMETRY: bool = _check_import("opentelemetry")
|
|
25
|
+
HAS_TOKENIZER: bool = _check_import("tiktoken")
|
|
26
|
+
HAS_KEYRING: bool = _check_import("keyring")
|
|
27
|
+
HAS_WATCHDOG: bool = _check_import("watchdog")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
# Map pip package names to import module names (when they differ)
|
|
31
|
+
_PACKAGE_TO_MODULE: dict[str, str] = {
|
|
32
|
+
"pillow": "PIL",
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def require_extra(extra_name: str, package_name: str) -> None:
|
|
37
|
+
"""Raise ImportError with installation hint if extra is not available.
|
|
38
|
+
|
|
39
|
+
Args:
|
|
40
|
+
extra_name: Name of the pip extra (e.g., 'vision')
|
|
41
|
+
package_name: Name of the required package (e.g., 'pillow')
|
|
42
|
+
|
|
43
|
+
Raises:
|
|
44
|
+
ImportError: With installation instructions when package is not available.
|
|
45
|
+
"""
|
|
46
|
+
module_name = _PACKAGE_TO_MODULE.get(package_name, package_name)
|
|
47
|
+
if _check_import(module_name):
|
|
48
|
+
return
|
|
49
|
+
raise ImportError(
|
|
50
|
+
f"The '{extra_name}' extra is required for this feature. "
|
|
51
|
+
f"Install it with: pip install ai-lib-python[{extra_name}]"
|
|
52
|
+
)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""Package version — single source via installed distribution metadata."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
try:
|
|
6
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
7
|
+
|
|
8
|
+
try:
|
|
9
|
+
__version__ = version("ai-lib-python")
|
|
10
|
+
except PackageNotFoundError:
|
|
11
|
+
__version__ = "0.8.6"
|
|
12
|
+
except ImportError: # pragma: no cover - Python < 3.8 guard
|
|
13
|
+
__version__ = "0.8.6"
|
ai_lib_python/batch/__init__.py
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Batch processing module for ai-lib-python.
|
|
3
|
-
|
|
4
|
-
Provides request batching and batch execution utilities.
|
|
5
|
-
"""
|
|
6
|
-
|
|
7
|
-
from ai_lib_python.batch.collector import BatchCollector, BatchConfig
|
|
8
|
-
from ai_lib_python.batch.executor import BatchExecutor, BatchResult
|
|
9
|
-
|
|
10
|
-
__all__ = [
|
|
11
|
-
"BatchCollector",
|
|
12
|
-
"BatchConfig",
|
|
13
|
-
"BatchExecutor",
|
|
14
|
-
"BatchResult",
|
|
15
|
-
]
|
|
1
|
+
"""
|
|
2
|
+
Batch processing module for ai-lib-python.
|
|
3
|
+
|
|
4
|
+
Provides request batching and batch execution utilities.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from ai_lib_python.batch.collector import BatchCollector, BatchConfig
|
|
8
|
+
from ai_lib_python.batch.executor import BatchExecutor, BatchResult
|
|
9
|
+
|
|
10
|
+
__all__ = [
|
|
11
|
+
"BatchCollector",
|
|
12
|
+
"BatchConfig",
|
|
13
|
+
"BatchExecutor",
|
|
14
|
+
"BatchResult",
|
|
15
|
+
]
|