zettcode-models 0.1.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.
@@ -0,0 +1,156 @@
1
+ """Official models for the vendor API keys found in the environment.
2
+
3
+ A reader who has ``OPENAI_API_KEY``, ``ANTHROPIC_API_KEY``, ``DEEPSEEK_API_KEY`` or ``ZAI_API_KEY`` set does not
4
+ have to type an address or a model id to try that vendor. The plugin knows the current official model of each host,
5
+ registers it as one :class:`~zettcode.plugin_api.ProvidedModel`, and leaves the token to the runtime, which reads it
6
+ from the variable named here and never writes it to the configuration.
7
+
8
+ The list is deliberately static: a start asks no vendor for anything, so a key in the environment costs no network
9
+ round trip. It is off by default — ambient keys should not change a model list unless the reader enables the plugin
10
+ with ``[plugins] enable = ["models"]``.
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ import os
16
+ from dataclasses import dataclass
17
+
18
+ from zettcode.plugin_api import Plugin, PluginContext, ProvidedModel, Provider
19
+
20
+ #: The one place the version is written; ``pyproject.toml`` reads it from here.
21
+ __version__ = "0.1.0"
22
+
23
+
24
+ @dataclass(frozen=True, slots=True)
25
+ class Vendor:
26
+ """One host an environment variable can open.
27
+
28
+ Attributes:
29
+ name: The provider name, which is unique across the application.
30
+ label: What a list shows for the host.
31
+ env: The variables that may hold the key, most specific first.
32
+ base_url: The address the client appends its route to.
33
+ api: Which protocol the host speaks.
34
+ model: The vendor's current official model id.
35
+ display: What ``/model`` shows for it.
36
+ context_window: Tokens it can carry.
37
+ multimodal: Whether it takes images.
38
+ """
39
+
40
+ name: str
41
+ label: str
42
+ env: tuple[str, ...]
43
+ base_url: str
44
+ api: str
45
+ model: str
46
+ display: str
47
+ context_window: int
48
+ multimodal: bool = False
49
+
50
+ def key(self) -> tuple[str, str] | None:
51
+ """Return the variable that holds this host's key and the key itself, or ``None`` when none is set."""
52
+ for variable in self.env:
53
+ value = os.getenv(variable)
54
+ if value:
55
+ return variable, value
56
+ return None
57
+
58
+
59
+ #: The official model offered for each host, checked against the vendors' model pages on 2026-11-10. The ids and
60
+ #: windows are the whole of this plugin's knowledge: when a vendor moves on, this table is the one place to edit.
61
+ VENDORS: tuple[Vendor, ...] = (
62
+ Vendor(
63
+ "openai",
64
+ "OpenAI",
65
+ ("OPENAI_API_KEY",),
66
+ "https://api.openai.com/v1",
67
+ "chat",
68
+ "gpt-6.1-sol",
69
+ "GPT-6.1 Sol",
70
+ 1_050_000,
71
+ multimodal=True,
72
+ ),
73
+ Vendor(
74
+ "anthropic",
75
+ "Anthropic",
76
+ ("ANTHROPIC_API_KEY",),
77
+ "https://api.anthropic.com",
78
+ "anthropic",
79
+ "claude-opus-5-5",
80
+ "Claude Opus 5.5",
81
+ 1_000_000,
82
+ multimodal=True,
83
+ ),
84
+ Vendor(
85
+ "deepseek",
86
+ "DeepSeek",
87
+ ("DEEPSEEK_API_KEY",),
88
+ "https://api.deepseek.com",
89
+ "chat",
90
+ "deepseek-v4.1-flash",
91
+ "DeepSeek V4.1 Flash",
92
+ 1_000_000,
93
+ ),
94
+ Vendor(
95
+ "zai",
96
+ "Z.AI",
97
+ ("ZAI_API_KEY", "ZHIPUAI_API_KEY", "ZHIPU_API_KEY"),
98
+ "https://api.z.ai/api/paas/v4",
99
+ "chat",
100
+ "glm-5.3",
101
+ "GLM-5.3",
102
+ 1_000_000,
103
+ ),
104
+ )
105
+
106
+
107
+ def _provider(vendor: Vendor, variable: str) -> Provider:
108
+ """Return the host description for one vendor, with the one model it offers."""
109
+ return Provider(
110
+ vendor.name,
111
+ vendor.label,
112
+ # The vendor names the protocol as the word Provider parses.
113
+ api=vendor.api, # type: ignore[arg-type]
114
+ base_url=vendor.base_url,
115
+ token_env=variable,
116
+ models=(
117
+ ProvidedModel(
118
+ vendor.model,
119
+ display_model=vendor.display,
120
+ context_window=vendor.context_window,
121
+ multimodal=vendor.multimodal,
122
+ ),
123
+ ),
124
+ note="official model",
125
+ )
126
+
127
+
128
+ class ModelsPlugin(Plugin[PluginContext]):
129
+ """Offer one official model for each vendor whose API key is in the environment."""
130
+
131
+ name = "models"
132
+ description = "An official model for each vendor API key in the environment"
133
+
134
+ @classmethod
135
+ def default_enabled(cls) -> bool:
136
+ """Stay off until the reader asks for it: ambient keys should not change a model list by themselves."""
137
+ return False
138
+
139
+ def activate(self, ctx: PluginContext) -> None:
140
+ """Register the host of every key that is set, with its current official model."""
141
+ clashes: list[str] = []
142
+ for vendor in VENDORS:
143
+ key = vendor.key()
144
+ if key is None:
145
+ continue
146
+ try:
147
+ ctx.agent.register_provider(_provider(vendor, key[0]))
148
+ except ValueError as error:
149
+ # A clash is not swallowed: the loader reports this plugin failed, so the reader sees why the host
150
+ # is absent instead of finding it missing with no word. Every clash is named, not only the first.
151
+ clashes.append(f"{vendor.label}: {error}")
152
+ if clashes:
153
+ raise ValueError("; ".join(clashes))
154
+
155
+
156
+ __all__ = ["ModelsPlugin", "Vendor", "VENDORS", "__version__"]
@@ -0,0 +1,47 @@
1
+ Metadata-Version: 2.5
2
+ Name: zettcode-models
3
+ Version: 0.1.0
4
+ Summary: A ZettCode plugin: an official model for each vendor API key found in the environment
5
+ Project-URL: Repository, https://github.com/Chang-LeHung/zettcode/tree/main/packages/zettcode-models
6
+ Project-URL: Issues, https://github.com/Chang-LeHung/zettcode/issues
7
+ Author: Chang-LeHung
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Keywords: environment,models,plugin,providers,zettcode
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Environment :: Console
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Classifier: Programming Language :: Python :: 3.15
19
+ Classifier: Topic :: Software Development :: User Interfaces
20
+ Classifier: Typing :: Typed
21
+ Requires-Python: >=3.10
22
+ Requires-Dist: zettcode-plugin-api<0.5,>=0.4
23
+ Description-Content-Type: text/markdown
24
+
25
+ # zettcode-models
26
+
27
+ A ZettCode plugin that offers an **official model** for each vendor whose API key is in the environment:
28
+ OpenAI, Anthropic, DeepSeek and Z.AI.
29
+
30
+ Install it as an extra and enable it once:
31
+
32
+ ```bash
33
+ pip install "zettcode[models]"
34
+ ```
35
+
36
+ ```toml
37
+ [plugins]
38
+ enable = ["models"]
39
+ ```
40
+
41
+ With `OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, `DEEPSEEK_API_KEY` or `ZAI_API_KEY` set (`ZHIPUAI_API_KEY` and
42
+ `ZHIPU_API_KEY` are accepted aliases), the plugin registers that host with its current official model — `GPT-6.1 Sol`,
43
+ `Claude Opus 5.5`, `DeepSeek V4.1 Flash` or `GLM-5.3`. The model appears in `/model` with `from the openai plugin`
44
+ (or `anthropic`, `deepseek`, `zai`); its token is read from the environment and never written to `config.toml`.
45
+
46
+ The list is static and no endpoint is called at start. The plugin is off by default: a set of ambient keys should not
47
+ change a model list unless the reader asks it to.
@@ -0,0 +1,6 @@
1
+ zettcode/models/__init__.py,sha256=jO7dLq4hH8Kqy5afgCJmQ0X_NbTz4Jkskk-vib-twHY,5253
2
+ zettcode_models-0.1.0.dist-info/METADATA,sha256=1nO4ydAjoGcLflMRfhncjKYbrzGyxG81yqfGqiNFjFM,1947
3
+ zettcode_models-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
4
+ zettcode_models-0.1.0.dist-info/entry_points.txt,sha256=U_LqiM9dSvmrn4ICnj6bVbnuYjPsW8kb-YX96JMemY4,56
5
+ zettcode_models-0.1.0.dist-info/licenses/LICENSE,sha256=O9b87-u8V1aSp6xkr9qnbHZIJAWNV6m04GEQjycLLiw,1069
6
+ zettcode_models-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [zettcode.plugin]
2
+ models = zettcode.models:ModelsPlugin
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Chang-LeHung
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.