ai-lib-python 0.8.2__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.
Files changed (109) hide show
  1. ai_lib_python/__init__.py +62 -62
  2. ai_lib_python/_features.py +52 -51
  3. ai_lib_python/_version.py +13 -0
  4. ai_lib_python/batch/__init__.py +15 -15
  5. ai_lib_python/batch/collector.py +241 -247
  6. ai_lib_python/batch/executor.py +228 -224
  7. ai_lib_python/cache/__init__.py +26 -26
  8. ai_lib_python/cache/backends.py +372 -380
  9. ai_lib_python/cache/key.py +239 -237
  10. ai_lib_python/cache/manager.py +333 -333
  11. ai_lib_python/client/__init__.py +37 -37
  12. ai_lib_python/client/builder.py +598 -561
  13. ai_lib_python/client/cancel.py +372 -372
  14. ai_lib_python/client/core.py +568 -517
  15. ai_lib_python/client/response.py +170 -134
  16. ai_lib_python/computer_use/__init__.py +234 -227
  17. ai_lib_python/drivers/__init__.py +140 -140
  18. ai_lib_python/drivers/anthropic.py +191 -183
  19. ai_lib_python/drivers/gemini.py +199 -187
  20. ai_lib_python/drivers/openai.py +137 -137
  21. ai_lib_python/embeddings/__init__.py +36 -36
  22. ai_lib_python/embeddings/client.py +341 -343
  23. ai_lib_python/embeddings/types.py +232 -234
  24. ai_lib_python/embeddings/vectors.py +245 -246
  25. ai_lib_python/errors/__init__.py +54 -54
  26. ai_lib_python/errors/base.py +325 -325
  27. ai_lib_python/errors/classification.py +242 -240
  28. ai_lib_python/errors/standard_codes.py +280 -280
  29. ai_lib_python/guardrails/__init__.py +35 -35
  30. ai_lib_python/guardrails/base.py +336 -336
  31. ai_lib_python/guardrails/filters.py +565 -561
  32. ai_lib_python/guardrails/validators.py +487 -475
  33. ai_lib_python/mcp/__init__.py +183 -181
  34. ai_lib_python/multimodal/__init__.py +143 -143
  35. ai_lib_python/pipeline/__init__.py +55 -55
  36. ai_lib_python/pipeline/accumulate.py +248 -248
  37. ai_lib_python/pipeline/base.py +230 -240
  38. ai_lib_python/pipeline/compliance.py +224 -0
  39. ai_lib_python/pipeline/decode.py +275 -281
  40. ai_lib_python/pipeline/event_map.py +601 -507
  41. ai_lib_python/pipeline/fan_out.py +278 -284
  42. ai_lib_python/pipeline/select.py +308 -297
  43. ai_lib_python/plugins/__init__.py +32 -32
  44. ai_lib_python/plugins/base.py +294 -294
  45. ai_lib_python/plugins/hooks.py +294 -296
  46. ai_lib_python/plugins/middleware.py +281 -285
  47. ai_lib_python/plugins/registry.py +294 -294
  48. ai_lib_python/protocol/__init__.py +71 -71
  49. ai_lib_python/protocol/loader.py +341 -329
  50. ai_lib_python/protocol/manifest.py +397 -387
  51. ai_lib_python/protocol/v2/__init__.py +22 -22
  52. ai_lib_python/protocol/v2/capabilities.py +224 -224
  53. ai_lib_python/protocol/v2/manifest.py +292 -292
  54. ai_lib_python/protocol/validator.py +445 -460
  55. ai_lib_python/py.typed +1 -1
  56. ai_lib_python/registry/__init__.py +175 -173
  57. ai_lib_python/rerank/__init__.py +20 -20
  58. ai_lib_python/rerank/client.py +146 -144
  59. ai_lib_python/resilience/__init__.py +102 -102
  60. ai_lib_python/resilience/backpressure.py +222 -225
  61. ai_lib_python/resilience/circuit_breaker.py +308 -318
  62. ai_lib_python/resilience/executor.py +336 -348
  63. ai_lib_python/resilience/fallback.py +341 -341
  64. ai_lib_python/resilience/preflight.py +397 -401
  65. ai_lib_python/resilience/rate_limiter.py +289 -291
  66. ai_lib_python/resilience/retry.py +302 -300
  67. ai_lib_python/resilience/signals.py +281 -283
  68. ai_lib_python/routing/__init__.py +118 -118
  69. ai_lib_python/routing/manager.py +592 -593
  70. ai_lib_python/routing/strategy.py +345 -345
  71. ai_lib_python/routing/types.py +395 -397
  72. ai_lib_python/structured/__init__.py +33 -33
  73. ai_lib_python/structured/json_mode.py +285 -285
  74. ai_lib_python/structured/schema.py +320 -322
  75. ai_lib_python/structured/validator.py +338 -344
  76. ai_lib_python/stt/__init__.py +22 -22
  77. ai_lib_python/stt/client.py +173 -171
  78. ai_lib_python/telemetry/__init__.py +127 -127
  79. ai_lib_python/telemetry/exporters/__init__.py +9 -9
  80. ai_lib_python/telemetry/exporters/prometheus.py +111 -111
  81. ai_lib_python/telemetry/feedback.py +446 -446
  82. ai_lib_python/telemetry/health.py +409 -409
  83. ai_lib_python/telemetry/logger.py +388 -392
  84. ai_lib_python/telemetry/metrics.py +486 -496
  85. ai_lib_python/telemetry/tracer.py +471 -473
  86. ai_lib_python/tokens/__init__.py +25 -25
  87. ai_lib_python/tokens/counter.py +282 -282
  88. ai_lib_python/tokens/estimator.py +286 -286
  89. ai_lib_python/transport/__init__.py +44 -34
  90. ai_lib_python/transport/auth.py +274 -141
  91. ai_lib_python/transport/http.py +410 -400
  92. ai_lib_python/transport/pool.py +422 -426
  93. ai_lib_python/tts/__init__.py +22 -22
  94. ai_lib_python/tts/client.py +171 -164
  95. ai_lib_python/types/__init__.py +61 -41
  96. ai_lib_python/types/events.py +333 -343
  97. ai_lib_python/types/execution_result.py +49 -0
  98. ai_lib_python/types/message.py +352 -352
  99. ai_lib_python/types/text_tool.py +249 -0
  100. ai_lib_python/types/tool.py +210 -209
  101. ai_lib_python/utils/__init__.py +21 -21
  102. ai_lib_python/utils/tool_call_assembler.py +314 -317
  103. ai_lib_python-0.8.6.dist-info/METADATA +447 -0
  104. ai_lib_python-0.8.6.dist-info/RECORD +107 -0
  105. {ai_lib_python-0.8.2.dist-info → ai_lib_python-0.8.6.dist-info}/WHEEL +1 -1
  106. {ai_lib_python-0.8.2.dist-info → ai_lib_python-0.8.6.dist-info}/licenses/LICENSE-APACHE +201 -201
  107. {ai_lib_python-0.8.2.dist-info → ai_lib_python-0.8.6.dist-info}/licenses/LICENSE-MIT +21 -21
  108. ai_lib_python-0.8.2.dist-info/METADATA +0 -1023
  109. ai_lib_python-0.8.2.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
- from __future__ import annotations
9
-
10
- from ai_lib_python._features import (
11
- HAS_AUDIO,
12
- HAS_KEYRING,
13
- HAS_TELEMETRY,
14
- HAS_TOKENIZER,
15
- HAS_VISION,
16
- HAS_WATCHDOG,
17
- require_extra,
18
- )
19
- from ai_lib_python.client import AiClient, AiClientBuilder, CallStats, ChatResponse
20
- from ai_lib_python.errors import AiLibError, ProtocolError, TransportError
21
- from ai_lib_python.types.events import StreamingEvent
22
- from ai_lib_python.types.message import (
23
- ContentBlock,
24
- Message,
25
- MessageContent,
26
- MessageRole,
27
- )
28
- from ai_lib_python.types.tool import ToolCall, ToolDefinition
29
-
30
- __version__ = "0.7.5"
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
+ ]
@@ -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
- from __future__ import annotations
9
-
10
-
11
- def _check_import(module_name: str) -> bool:
12
- """Check if a module is importable."""
13
- try:
14
- __import__(module_name)
15
- return True
16
- except ImportError:
17
- return False
18
-
19
-
20
- # Capability feature flags
21
- HAS_VISION: bool = _check_import("PIL")
22
- HAS_AUDIO: bool = _check_import("soundfile")
23
- HAS_TELEMETRY: bool = _check_import("opentelemetry")
24
- HAS_TOKENIZER: bool = _check_import("tiktoken")
25
- HAS_KEYRING: bool = _check_import("keyring")
26
- HAS_WATCHDOG: bool = _check_import("watchdog")
27
-
28
-
29
- # Map pip package names to import module names (when they differ)
30
- _PACKAGE_TO_MODULE: dict[str, str] = {
31
- "pillow": "PIL",
32
- }
33
-
34
-
35
- def require_extra(extra_name: str, package_name: str) -> None:
36
- """Raise ImportError with installation hint if extra is not available.
37
-
38
- Args:
39
- extra_name: Name of the pip extra (e.g., 'vision')
40
- package_name: Name of the required package (e.g., 'pillow')
41
-
42
- Raises:
43
- ImportError: With installation instructions when package is not available.
44
- """
45
- module_name = _PACKAGE_TO_MODULE.get(package_name, package_name)
46
- if _check_import(module_name):
47
- return
48
- raise ImportError(
49
- f"The '{extra_name}' extra is required for this feature. "
50
- f"Install it with: pip install ai-lib-python[{extra_name}]"
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"
@@ -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
+ ]