pyllym 1.16.0__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 (121) hide show
  1. pyllym/__init__.py +310 -0
  2. pyllym/agent.py +74 -0
  3. pyllym/aliases.json +642 -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 +126 -0
  23. pyllym/connection.py +490 -0
  24. pyllym/content.py +77 -0
  25. pyllym/context.py +60 -0
  26. pyllym/cost.py +269 -0
  27. pyllym/decision.py +244 -0
  28. pyllym/embedding.py +37 -0
  29. pyllym/errors.py +183 -0
  30. pyllym/image.py +92 -0
  31. pyllym/layout_parsing.py +84 -0
  32. pyllym/mcp.py +351 -0
  33. pyllym/message.py +184 -0
  34. pyllym/mime_type.py +136 -0
  35. pyllym/model/__init__.py +11 -0
  36. pyllym/model/info.py +183 -0
  37. pyllym/model/modalities.py +17 -0
  38. pyllym/model/pricing.py +54 -0
  39. pyllym/model/pricing_category.py +52 -0
  40. pyllym/model/pricing_tier.py +44 -0
  41. pyllym/models.json +65836 -0
  42. pyllym/models.py +291 -0
  43. pyllym/models_schema.json +169 -0
  44. pyllym/moderation.py +55 -0
  45. pyllym/persistence/__init__.py +27 -0
  46. pyllym/persistence/models.py +173 -0
  47. pyllym/protocol.py +289 -0
  48. pyllym/protocols/__init__.py +1 -0
  49. pyllym/protocols/anthropic.py +537 -0
  50. pyllym/protocols/chat_completions.py +687 -0
  51. pyllym/protocols/converse.py +619 -0
  52. pyllym/protocols/fal.py +123 -0
  53. pyllym/protocols/gemini.py +939 -0
  54. pyllym/protocols/nli_classify.py +138 -0
  55. pyllym/protocols/systemone.py +82 -0
  56. pyllym/protocols/zhipu_layout.py +79 -0
  57. pyllym/provider.py +355 -0
  58. pyllym/providers/__init__.py +1 -0
  59. pyllym/providers/anthropic.py +39 -0
  60. pyllym/providers/azure.py +33 -0
  61. pyllym/providers/bedrock.py +227 -0
  62. pyllym/providers/capabilities.py +37 -0
  63. pyllym/providers/cerebras.py +10 -0
  64. pyllym/providers/databricks.py +14 -0
  65. pyllym/providers/deepseek.py +10 -0
  66. pyllym/providers/doubao.py +14 -0
  67. pyllym/providers/ernie.py +13 -0
  68. pyllym/providers/fal.py +40 -0
  69. pyllym/providers/gemini.py +154 -0
  70. pyllym/providers/gpustack.py +33 -0
  71. pyllym/providers/huggingface.py +10 -0
  72. pyllym/providers/minimax.py +15 -0
  73. pyllym/providers/mistral.py +9 -0
  74. pyllym/providers/moonshot.py +15 -0
  75. pyllym/providers/nvidia.py +10 -0
  76. pyllym/providers/ollama.py +33 -0
  77. pyllym/providers/openai.py +57 -0
  78. pyllym/providers/openai_compatible.py +61 -0
  79. pyllym/providers/openrouter.py +9 -0
  80. pyllym/providers/perplexity.py +25 -0
  81. pyllym/providers/qwen.py +15 -0
  82. pyllym/providers/typesafe.py +24 -0
  83. pyllym/providers/vertexai.py +106 -0
  84. pyllym/providers/vllm.py +45 -0
  85. pyllym/providers/xai.py +10 -0
  86. pyllym/providers/zhipu.py +19 -0
  87. pyllym/py.typed +0 -0
  88. pyllym/reactllm_bridge.py +165 -0
  89. pyllym/reactullm_bridge.py +228 -0
  90. pyllym/reactullm_handoff.py +352 -0
  91. pyllym/reactullm_runtime.py +405 -0
  92. pyllym/search_results.py +45 -0
  93. pyllym/speech.py +73 -0
  94. pyllym/stream_accumulator.py +249 -0
  95. pyllym/streaming.py +169 -0
  96. pyllym/tdg/__init__.py +66 -0
  97. pyllym/tdg/__main__.py +86 -0
  98. pyllym/tdg/brief.py +120 -0
  99. pyllym/tdg/builder.py +288 -0
  100. pyllym/tdg/checks.py +61 -0
  101. pyllym/tdg/deps.py +251 -0
  102. pyllym/tdg/planner.py +140 -0
  103. pyllym/tdg/renderer.py +106 -0
  104. pyllym/tdg/runs.py +142 -0
  105. pyllym/tdg/safety.py +141 -0
  106. pyllym/tdg/schema.py +87 -0
  107. pyllym/tdg/sequence.py +147 -0
  108. pyllym/tdg/toml_spec.py +367 -0
  109. pyllym/thinking.py +42 -0
  110. pyllym/tokens.py +53 -0
  111. pyllym/tool.py +197 -0
  112. pyllym/tool_call.py +23 -0
  113. pyllym/toolset.py +343 -0
  114. pyllym/transcription.py +44 -0
  115. pyllym/uploaded_file.py +59 -0
  116. pyllym/utils.py +124 -0
  117. pyllym/video.py +94 -0
  118. pyllym-1.16.0.dist-info/METADATA +776 -0
  119. pyllym-1.16.0.dist-info/RECORD +121 -0
  120. pyllym-1.16.0.dist-info/WHEEL +4 -0
  121. pyllym-1.16.0.dist-info/licenses/LICENSE +22 -0
pyllym/__init__.py ADDED
@@ -0,0 +1,310 @@
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 .decision import Answer, Decision, Question
28
+ from .embedding import Embedding
29
+ from .errors import (
30
+ BadRequestError,
31
+ ConfigurationError,
32
+ ConnectionFailedError,
33
+ ContextLengthExceededError,
34
+ Error,
35
+ ForbiddenError,
36
+ InvalidRoleError,
37
+ InvalidToolChoiceError,
38
+ ModelNotFoundError,
39
+ OverloadedError,
40
+ PaymentRequiredError,
41
+ RateLimitError,
42
+ ServerError,
43
+ ServiceUnavailableError,
44
+ UnauthorizedError,
45
+ UnsupportedAttachmentError,
46
+ )
47
+ from .image import Image
48
+ from .layout_parsing import LayoutElement, LayoutParsing
49
+ from .mcp import MCPNotInstalledError, MCPServer, MCPTool, tools_from_session
50
+ from .message import Message, Role
51
+ from .moderation import Moderation
52
+ from .provider import Provider
53
+ from .reactullm_runtime import (
54
+ LLMError,
55
+ LLMRequest,
56
+ LLMResponse,
57
+ TaskConfig,
58
+ TaskRegistry,
59
+ )
60
+ from .search_results import SearchResults
61
+ from .speech import Speech
62
+ from .thinking import Thinking
63
+ from .tokens import Tokens
64
+ from .tool import Parameter, Tool
65
+ from .tool_call import ToolCall
66
+ from .toolset import MissingToolPackageError, load_toolset, tool_from_path
67
+ from .transcription import Transcription
68
+ from .uploaded_file import UploadedFile
69
+ from .video import Video
70
+
71
+ __version__ = "1.16.0"
72
+
73
+ _config: Configuration | None = None
74
+
75
+
76
+ def config() -> Configuration:
77
+ """The global configuration singleton."""
78
+ global _config
79
+ if _config is None:
80
+ _config = Configuration()
81
+ return _config
82
+
83
+
84
+ def configure(block: Callable[[Configuration], Any]) -> Configuration:
85
+ """Configure pyllym: ``pyllym.configure(lambda c: setattr(c, 'openai_api_key', ...))``."""
86
+ cfg = config()
87
+ block(cfg)
88
+ return cfg
89
+
90
+
91
+ def context(block: Callable[[Configuration], Any] | None = None) -> Context:
92
+ """Create a per-call :class:`Context` with an isolated config copy."""
93
+ cfg = config().copy()
94
+ if block is not None:
95
+ block(cfg)
96
+ return Context(cfg)
97
+
98
+
99
+ def create_chat(**kwargs: Any) -> Chat:
100
+ """Create a new conversation with an AI model."""
101
+ return Chat(**kwargs)
102
+
103
+
104
+ async def embed(text: Any, **kwargs: Any) -> Embedding:
105
+ from .embedding import embed as _embed
106
+
107
+ return await _embed(text, **kwargs)
108
+
109
+
110
+ async def moderate(input: Any, **kwargs: Any) -> Moderation:
111
+ from .moderation import moderate as _moderate
112
+
113
+ return await _moderate(input, **kwargs)
114
+
115
+
116
+ async def decide(state: Any, questions: Any, **kwargs: Any) -> Decision:
117
+ """Answer typed questions about ``state`` with a decision model (Jev, ...)."""
118
+ from .decision import decide as _decide
119
+
120
+ return await _decide(state, questions, **kwargs)
121
+
122
+
123
+ async def paint(prompt: str, **kwargs: Any) -> Image:
124
+ from .image import paint as _paint
125
+
126
+ return await _paint(prompt, **kwargs)
127
+
128
+
129
+ async def animate(prompt: str, **kwargs: Any) -> Video:
130
+ from .video import animate as _animate
131
+
132
+ return await _animate(prompt, **kwargs)
133
+
134
+
135
+ async def speak(input: str, **kwargs: Any) -> Speech:
136
+ from .speech import speak as _speak
137
+
138
+ return await _speak(input, **kwargs)
139
+
140
+
141
+ async def transcribe(audio_file: str, **kwargs: Any) -> Transcription:
142
+ from .transcription import transcribe as _transcribe
143
+
144
+ return await _transcribe(audio_file, **kwargs)
145
+
146
+
147
+ async def parse_layout(file: str, **kwargs: Any) -> LayoutParsing:
148
+ from .layout_parsing import parse_layout as _parse_layout
149
+
150
+ return await _parse_layout(file, **kwargs)
151
+
152
+
153
+ async def upload(file: Any, **kwargs: Any) -> UploadedFile:
154
+ from .uploaded_file import upload as _upload
155
+
156
+ return await _upload(file, **kwargs)
157
+
158
+
159
+ async def download(id: str, **kwargs: Any) -> bytes:
160
+ from .uploaded_file import download as _download
161
+
162
+ return await _download(id, **kwargs)
163
+
164
+
165
+ def list_providers() -> list[type[Provider]]:
166
+ """All registered provider classes.
167
+
168
+ Note: ``pyllym.providers`` is the provider *subpackage*; use this function
169
+ or :meth:`Provider.providers` to enumerate registered providers.
170
+ """
171
+ return list(Provider.providers().values())
172
+
173
+
174
+ class _ModelsProxy:
175
+ """Attribute proxy so ``pyllym.models.find(...)`` reaches the registry module
176
+ even though the ``models`` attribute on the package shadows the submodule."""
177
+
178
+ def __getattr__(self, name: str) -> Any:
179
+ import importlib
180
+
181
+ module = importlib.import_module("pyllym.models")
182
+ return getattr(module, name)
183
+
184
+
185
+ models = _ModelsProxy()
186
+
187
+
188
+ def _register_builtin_providers() -> None:
189
+ """Register provider classes if their modules import cleanly.
190
+
191
+ Providers depend on protocol modules that may be filled in incrementally;
192
+ importing defensively keeps the core usable as coverage grows.
193
+ """
194
+ registrations = [
195
+ ("anthropic", "Anthropic"),
196
+ ("openai", "OpenAI"),
197
+ ("gemini", "Gemini"),
198
+ ("deepseek", "DeepSeek"),
199
+ ("mistral", "Mistral"),
200
+ ("ollama", "Ollama"),
201
+ ("openrouter", "OpenRouter"),
202
+ ("perplexity", "Perplexity"),
203
+ ("xai", "XAI"),
204
+ ("gpustack", "GPUStack"),
205
+ ("vllm", "VLLM"),
206
+ ("azure", "Azure"),
207
+ ("bedrock", "Bedrock"),
208
+ ("vertexai", "VertexAI"),
209
+ ("nvidia", "NVIDIA"),
210
+ ("cerebras", "Cerebras"),
211
+ ("huggingface", "HuggingFace"),
212
+ ("databricks", "Databricks"),
213
+ ("qwen", "Qwen"),
214
+ ("zhipu", "Zhipu"),
215
+ ("moonshot", "Moonshot"),
216
+ ("doubao", "Doubao"),
217
+ ("ernie", "ERNIE"),
218
+ ("minimax", "MiniMax"),
219
+ ("fal", "Fal"),
220
+ ("typesafe", "TypeSafe"),
221
+ ]
222
+ import importlib
223
+
224
+ for slug, class_name in registrations:
225
+ try:
226
+ module = importlib.import_module(f".providers.{slug}", __name__)
227
+ provider_class = getattr(module, class_name)
228
+ except Exception:
229
+ continue
230
+ Provider.register(slug, provider_class)
231
+
232
+
233
+ _register_builtin_providers()
234
+
235
+ __all__ = [
236
+ "Agent",
237
+ "Answer",
238
+ "BadRequestError",
239
+ "Chat",
240
+ "Citation",
241
+ "Configuration",
242
+ "ConfigurationError",
243
+ "ConnectionFailedError",
244
+ "Content",
245
+ "Context",
246
+ "ContextLengthExceededError",
247
+ "Decision",
248
+ "Embedding",
249
+ "Error",
250
+ "ForbiddenError",
251
+ "Image",
252
+ "InvalidRoleError",
253
+ "InvalidToolChoiceError",
254
+ "LLMError",
255
+ "LLMRequest",
256
+ "LLMResponse",
257
+ "LayoutElement",
258
+ "LayoutParsing",
259
+ "MCPNotInstalledError",
260
+ "MCPServer",
261
+ "MCPTool",
262
+ "Message",
263
+ "MissingToolPackageError",
264
+ "ModelNotFoundError",
265
+ "Moderation",
266
+ "OverloadedError",
267
+ "Parameter",
268
+ "PaymentRequiredError",
269
+ "Provider",
270
+ "Question",
271
+ "RateLimitError",
272
+ "RawContent",
273
+ "Role",
274
+ "SearchResults",
275
+ "ServerError",
276
+ "ServiceUnavailableError",
277
+ "Speech",
278
+ "TaskConfig",
279
+ "TaskRegistry",
280
+ "Thinking",
281
+ "Tokens",
282
+ "Tool",
283
+ "ToolCall",
284
+ "Transcription",
285
+ "UnauthorizedError",
286
+ "UnsupportedAttachmentError",
287
+ "UploadedFile",
288
+ "Video",
289
+ "__version__",
290
+ "aclose",
291
+ "animate",
292
+ "config",
293
+ "configure",
294
+ "context",
295
+ "create_chat",
296
+ "decide",
297
+ "download",
298
+ "embed",
299
+ "list_providers",
300
+ "load_toolset",
301
+ "models",
302
+ "moderate",
303
+ "paint",
304
+ "parse_layout",
305
+ "speak",
306
+ "tool_from_path",
307
+ "tools_from_session",
308
+ "transcribe",
309
+ "upload",
310
+ ]
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)