pyllym 1.16.0a1__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 (114) hide show
  1. pyllym/__init__.py +280 -0
  2. pyllym/agent.py +74 -0
  3. pyllym/aliases.json +553 -0
  4. pyllym/aliases.py +35 -0
  5. pyllym/attachment.py +221 -0
  6. pyllym/bdd/__init__.py +59 -0
  7. pyllym/bdd/__main__.py +69 -0
  8. pyllym/bdd/brief.py +120 -0
  9. pyllym/bdd/builder.py +173 -0
  10. pyllym/bdd/checks.py +61 -0
  11. pyllym/bdd/planner.py +140 -0
  12. pyllym/bdd/renderer.py +106 -0
  13. pyllym/bdd/safety.py +141 -0
  14. pyllym/bdd/schema.py +87 -0
  15. pyllym/bdd/sequence.py +147 -0
  16. pyllym/bdd/toml_spec.py +367 -0
  17. pyllym/celery/__init__.py +36 -0
  18. pyllym/celery/tasks.py +218 -0
  19. pyllym/chat.py +497 -0
  20. pyllym/chunk.py +9 -0
  21. pyllym/citation.py +44 -0
  22. pyllym/configuration.py +116 -0
  23. pyllym/connection.py +277 -0
  24. pyllym/content.py +77 -0
  25. pyllym/context.py +60 -0
  26. pyllym/cost.py +269 -0
  27. pyllym/embedding.py +37 -0
  28. pyllym/errors.py +140 -0
  29. pyllym/image.py +85 -0
  30. pyllym/message.py +184 -0
  31. pyllym/mime_type.py +136 -0
  32. pyllym/model/__init__.py +11 -0
  33. pyllym/model/info.py +181 -0
  34. pyllym/model/modalities.py +17 -0
  35. pyllym/model/pricing.py +54 -0
  36. pyllym/model/pricing_category.py +52 -0
  37. pyllym/model/pricing_tier.py +44 -0
  38. pyllym/models.json +64119 -0
  39. pyllym/models.py +284 -0
  40. pyllym/models_schema.json +169 -0
  41. pyllym/moderation.py +55 -0
  42. pyllym/persistence/__init__.py +27 -0
  43. pyllym/persistence/models.py +173 -0
  44. pyllym/protocol.py +265 -0
  45. pyllym/protocols/__init__.py +1 -0
  46. pyllym/protocols/anthropic.py +537 -0
  47. pyllym/protocols/chat_completions.py +682 -0
  48. pyllym/protocols/converse.py +619 -0
  49. pyllym/protocols/fal.py +123 -0
  50. pyllym/protocols/gemini.py +922 -0
  51. pyllym/provider.py +338 -0
  52. pyllym/providers/__init__.py +1 -0
  53. pyllym/providers/anthropic.py +39 -0
  54. pyllym/providers/azure.py +33 -0
  55. pyllym/providers/bedrock.py +227 -0
  56. pyllym/providers/capabilities.py +37 -0
  57. pyllym/providers/cerebras.py +10 -0
  58. pyllym/providers/databricks.py +14 -0
  59. pyllym/providers/deepseek.py +10 -0
  60. pyllym/providers/doubao.py +14 -0
  61. pyllym/providers/ernie.py +13 -0
  62. pyllym/providers/fal.py +40 -0
  63. pyllym/providers/gemini.py +154 -0
  64. pyllym/providers/gpustack.py +33 -0
  65. pyllym/providers/huggingface.py +10 -0
  66. pyllym/providers/minimax.py +15 -0
  67. pyllym/providers/mistral.py +9 -0
  68. pyllym/providers/moonshot.py +15 -0
  69. pyllym/providers/nvidia.py +10 -0
  70. pyllym/providers/ollama.py +33 -0
  71. pyllym/providers/openai.py +51 -0
  72. pyllym/providers/openai_compatible.py +61 -0
  73. pyllym/providers/openrouter.py +9 -0
  74. pyllym/providers/perplexity.py +25 -0
  75. pyllym/providers/qwen.py +15 -0
  76. pyllym/providers/vertexai.py +106 -0
  77. pyllym/providers/vllm.py +44 -0
  78. pyllym/providers/xai.py +10 -0
  79. pyllym/providers/zhipu.py +15 -0
  80. pyllym/py.typed +0 -0
  81. pyllym/reactllm_bridge.py +165 -0
  82. pyllym/reactullm_bridge.py +228 -0
  83. pyllym/reactullm_handoff.py +352 -0
  84. pyllym/reactullm_runtime.py +405 -0
  85. pyllym/search_results.py +45 -0
  86. pyllym/speech.py +73 -0
  87. pyllym/stream_accumulator.py +249 -0
  88. pyllym/streaming.py +167 -0
  89. pyllym/tdg/__init__.py +66 -0
  90. pyllym/tdg/__main__.py +86 -0
  91. pyllym/tdg/brief.py +120 -0
  92. pyllym/tdg/builder.py +288 -0
  93. pyllym/tdg/checks.py +61 -0
  94. pyllym/tdg/deps.py +251 -0
  95. pyllym/tdg/planner.py +140 -0
  96. pyllym/tdg/renderer.py +106 -0
  97. pyllym/tdg/runs.py +142 -0
  98. pyllym/tdg/safety.py +141 -0
  99. pyllym/tdg/schema.py +87 -0
  100. pyllym/tdg/sequence.py +147 -0
  101. pyllym/tdg/toml_spec.py +367 -0
  102. pyllym/thinking.py +42 -0
  103. pyllym/tokens.py +53 -0
  104. pyllym/tool.py +197 -0
  105. pyllym/tool_call.py +23 -0
  106. pyllym/toolset.py +343 -0
  107. pyllym/transcription.py +44 -0
  108. pyllym/uploaded_file.py +59 -0
  109. pyllym/utils.py +124 -0
  110. pyllym/video.py +87 -0
  111. pyllym-1.16.0a1.dist-info/METADATA +696 -0
  112. pyllym-1.16.0a1.dist-info/RECORD +114 -0
  113. pyllym-1.16.0a1.dist-info/WHEEL +4 -0
  114. pyllym-1.16.0a1.dist-info/licenses/LICENSE +22 -0
pyllym/__init__.py ADDED
@@ -0,0 +1,280 @@
1
+ """pyllym — one delightful, async-first Python framework for every major AI
2
+ provider.
3
+
4
+ Public façade::
5
+
6
+ import pyllym
7
+
8
+ pyllym.configure(lambda c: setattr(c, "openai_api_key", "sk-..."))
9
+
10
+ chat = pyllym.create_chat(model="gpt-5.4")
11
+ message = await chat.ask("What's the best way to learn Python?")
12
+ print(message.content)
13
+ """
14
+
15
+ from __future__ import annotations
16
+
17
+ from collections.abc import Callable
18
+ from typing import Any
19
+
20
+ from .agent import Agent
21
+ from .chat import Chat
22
+ from .citation import Citation
23
+ from .configuration import Configuration
24
+ from .connection import aclose
25
+ from .content import Content, RawContent
26
+ from .context import Context
27
+ from .embedding import Embedding
28
+ from .errors import (
29
+ BadRequestError,
30
+ ConfigurationError,
31
+ ContextLengthExceededError,
32
+ Error,
33
+ ForbiddenError,
34
+ InvalidRoleError,
35
+ InvalidToolChoiceError,
36
+ ModelNotFoundError,
37
+ OverloadedError,
38
+ PaymentRequiredError,
39
+ RateLimitError,
40
+ ServerError,
41
+ ServiceUnavailableError,
42
+ UnauthorizedError,
43
+ UnsupportedAttachmentError,
44
+ )
45
+ from .image import Image
46
+ from .message import Message, Role
47
+ from .moderation import Moderation
48
+ from .provider import Provider
49
+ from .reactullm_runtime import (
50
+ LLMError,
51
+ LLMRequest,
52
+ LLMResponse,
53
+ TaskConfig,
54
+ TaskRegistry,
55
+ )
56
+ from .search_results import SearchResults
57
+ from .speech import Speech
58
+ from .thinking import Thinking
59
+ from .tokens import Tokens
60
+ from .tool import Parameter, Tool
61
+ from .tool_call import ToolCall
62
+ from .toolset import MissingToolPackageError, load_toolset, tool_from_path
63
+ from .transcription import Transcription
64
+ from .uploaded_file import UploadedFile
65
+ from .video import Video
66
+
67
+ __version__ = "1.16.0a1"
68
+
69
+ _config: Configuration | None = None
70
+
71
+
72
+ def config() -> Configuration:
73
+ """The global configuration singleton."""
74
+ global _config
75
+ if _config is None:
76
+ _config = Configuration()
77
+ return _config
78
+
79
+
80
+ def configure(block: Callable[[Configuration], Any]) -> Configuration:
81
+ """Configure pyllym: ``pyllym.configure(lambda c: setattr(c, 'openai_api_key', ...))``."""
82
+ cfg = config()
83
+ block(cfg)
84
+ return cfg
85
+
86
+
87
+ def context(block: Callable[[Configuration], Any] | None = None) -> Context:
88
+ """Create a per-call :class:`Context` with an isolated config copy."""
89
+ cfg = config().copy()
90
+ if block is not None:
91
+ block(cfg)
92
+ return Context(cfg)
93
+
94
+
95
+ def create_chat(**kwargs: Any) -> Chat:
96
+ """Create a new conversation with an AI model."""
97
+ return Chat(**kwargs)
98
+
99
+
100
+ async def embed(text: Any, **kwargs: Any) -> Embedding:
101
+ from .embedding import embed as _embed
102
+
103
+ return await _embed(text, **kwargs)
104
+
105
+
106
+ async def moderate(input: Any, **kwargs: Any) -> Moderation:
107
+ from .moderation import moderate as _moderate
108
+
109
+ return await _moderate(input, **kwargs)
110
+
111
+
112
+ async def paint(prompt: str, **kwargs: Any) -> Image:
113
+ from .image import paint as _paint
114
+
115
+ return await _paint(prompt, **kwargs)
116
+
117
+
118
+ async def animate(prompt: str, **kwargs: Any) -> Video:
119
+ from .video import animate as _animate
120
+
121
+ return await _animate(prompt, **kwargs)
122
+
123
+
124
+ async def speak(input: str, **kwargs: Any) -> Speech:
125
+ from .speech import speak as _speak
126
+
127
+ return await _speak(input, **kwargs)
128
+
129
+
130
+ async def transcribe(audio_file: str, **kwargs: Any) -> Transcription:
131
+ from .transcription import transcribe as _transcribe
132
+
133
+ return await _transcribe(audio_file, **kwargs)
134
+
135
+
136
+ async def upload(file: Any, **kwargs: Any) -> UploadedFile:
137
+ from .uploaded_file import upload as _upload
138
+
139
+ return await _upload(file, **kwargs)
140
+
141
+
142
+ async def download(id: str, **kwargs: Any) -> bytes:
143
+ from .uploaded_file import download as _download
144
+
145
+ return await _download(id, **kwargs)
146
+
147
+
148
+ def list_providers() -> list[type[Provider]]:
149
+ """All registered provider classes.
150
+
151
+ Note: ``pyllym.providers`` is the provider *subpackage*; use this function
152
+ or :meth:`Provider.providers` to enumerate registered providers.
153
+ """
154
+ return list(Provider.providers().values())
155
+
156
+
157
+ class _ModelsProxy:
158
+ """Attribute proxy so ``pyllym.models.find(...)`` reaches the registry module
159
+ even though the ``models`` attribute on the package shadows the submodule."""
160
+
161
+ def __getattr__(self, name: str) -> Any:
162
+ import importlib
163
+
164
+ module = importlib.import_module("pyllym.models")
165
+ return getattr(module, name)
166
+
167
+
168
+ models = _ModelsProxy()
169
+
170
+
171
+ def _register_builtin_providers() -> None:
172
+ """Register provider classes if their modules import cleanly.
173
+
174
+ Providers depend on protocol modules that may be filled in incrementally;
175
+ importing defensively keeps the core usable as coverage grows.
176
+ """
177
+ registrations = [
178
+ ("anthropic", "Anthropic"),
179
+ ("openai", "OpenAI"),
180
+ ("gemini", "Gemini"),
181
+ ("deepseek", "DeepSeek"),
182
+ ("mistral", "Mistral"),
183
+ ("ollama", "Ollama"),
184
+ ("openrouter", "OpenRouter"),
185
+ ("perplexity", "Perplexity"),
186
+ ("xai", "XAI"),
187
+ ("gpustack", "GPUStack"),
188
+ ("vllm", "VLLM"),
189
+ ("azure", "Azure"),
190
+ ("bedrock", "Bedrock"),
191
+ ("vertexai", "VertexAI"),
192
+ ("nvidia", "NVIDIA"),
193
+ ("cerebras", "Cerebras"),
194
+ ("huggingface", "HuggingFace"),
195
+ ("databricks", "Databricks"),
196
+ ("qwen", "Qwen"),
197
+ ("zhipu", "Zhipu"),
198
+ ("moonshot", "Moonshot"),
199
+ ("doubao", "Doubao"),
200
+ ("ernie", "ERNIE"),
201
+ ("minimax", "MiniMax"),
202
+ ("fal", "Fal"),
203
+ ]
204
+ import importlib
205
+
206
+ for slug, class_name in registrations:
207
+ try:
208
+ module = importlib.import_module(f".providers.{slug}", __name__)
209
+ provider_class = getattr(module, class_name)
210
+ except Exception:
211
+ continue
212
+ Provider.register(slug, provider_class)
213
+
214
+
215
+ _register_builtin_providers()
216
+
217
+ __all__ = [
218
+ "Agent",
219
+ "BadRequestError",
220
+ "Chat",
221
+ "Citation",
222
+ "Configuration",
223
+ "ConfigurationError",
224
+ "Content",
225
+ "Context",
226
+ "ContextLengthExceededError",
227
+ "Embedding",
228
+ "Error",
229
+ "ForbiddenError",
230
+ "Image",
231
+ "InvalidRoleError",
232
+ "InvalidToolChoiceError",
233
+ "LLMError",
234
+ "LLMRequest",
235
+ "LLMResponse",
236
+ "Message",
237
+ "MissingToolPackageError",
238
+ "ModelNotFoundError",
239
+ "Moderation",
240
+ "OverloadedError",
241
+ "Parameter",
242
+ "PaymentRequiredError",
243
+ "Provider",
244
+ "RateLimitError",
245
+ "RawContent",
246
+ "Role",
247
+ "SearchResults",
248
+ "ServerError",
249
+ "ServiceUnavailableError",
250
+ "Speech",
251
+ "TaskConfig",
252
+ "TaskRegistry",
253
+ "Thinking",
254
+ "Tokens",
255
+ "Tool",
256
+ "ToolCall",
257
+ "Transcription",
258
+ "UnauthorizedError",
259
+ "UnsupportedAttachmentError",
260
+ "UploadedFile",
261
+ "Video",
262
+ "__version__",
263
+ "aclose",
264
+ "animate",
265
+ "config",
266
+ "configure",
267
+ "context",
268
+ "create_chat",
269
+ "download",
270
+ "embed",
271
+ "list_providers",
272
+ "load_toolset",
273
+ "models",
274
+ "moderate",
275
+ "paint",
276
+ "speak",
277
+ "tool_from_path",
278
+ "transcribe",
279
+ "upload",
280
+ ]
pyllym/agent.py ADDED
@@ -0,0 +1,74 @@
1
+ """Class-configured agents.
2
+
3
+ Subclasses declare their configuration (model, instructions, tools,
4
+ temperature, …) as class attributes and produce a ready-to-use
5
+ :class:`~pyllym.chat.Chat`. Persistence is handled separately by
6
+ :mod:`pyllym.persistence`.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ from typing import Any, ClassVar
12
+
13
+ from .chat import Chat
14
+ from .tool import Tool
15
+
16
+
17
+ class Agent:
18
+ """Subclass and set class attributes to configure a reusable chat.
19
+
20
+ Example::
21
+
22
+ class Researcher(Agent):
23
+ chat_model = "claude-sonnet-4-6"
24
+ instructions = "You are a meticulous research assistant."
25
+ tools = [WebSearch]
26
+ temperature = 0.2
27
+
28
+ chat = Researcher.create_chat()
29
+ await chat.ask("Summarize the latest on ...")
30
+ """
31
+
32
+ chat_model: ClassVar[str | None] = None
33
+ chat_kwargs: ClassVar[dict[str, Any]] = {}
34
+ instructions: ClassVar[str | None] = None
35
+ tools: ClassVar[list[type[Tool] | Tool]] = []
36
+ temperature: ClassVar[float | None] = None
37
+ thinking: ClassVar[dict[str, Any] | None] = None
38
+ citations: ClassVar[bool | None] = None
39
+ params: ClassVar[dict[str, Any]] = {}
40
+ headers: ClassVar[dict[str, str]] = {}
41
+ schema: ClassVar[Any] = None
42
+ context: ClassVar[Any] = None
43
+
44
+ @classmethod
45
+ def create_chat(cls, **chat_options: Any) -> Chat:
46
+ """Create a conversation pre-configured by this agent's class attributes."""
47
+ kwargs = dict(cls.chat_kwargs)
48
+ if cls.chat_model and "model" not in kwargs:
49
+ kwargs["model"] = cls.chat_model
50
+ kwargs.update(chat_options)
51
+ if cls.context is not None and "context" not in kwargs:
52
+ kwargs["context"] = cls.context
53
+ chat = Chat(**kwargs)
54
+ cls._configure(chat)
55
+ return chat
56
+
57
+ @classmethod
58
+ def _configure(cls, chat: Chat) -> None:
59
+ if cls.instructions:
60
+ chat.with_instructions(cls.instructions)
61
+ if cls.tools:
62
+ chat.with_tools(*cls.tools)
63
+ if cls.temperature is not None:
64
+ chat.with_temperature(cls.temperature)
65
+ if cls.thinking:
66
+ chat.with_thinking(effort=cls.thinking.get("effort"), budget=cls.thinking.get("budget"))
67
+ if cls.citations is not None:
68
+ chat.with_citations(cls.citations)
69
+ if cls.params:
70
+ chat.with_params(**cls.params)
71
+ if cls.headers:
72
+ chat.with_headers(**cls.headers)
73
+ if cls.schema is not None:
74
+ chat.with_schema(cls.schema)