@ai-for-dev/providers 0.0.0-stage → 0.2.0

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 AI-for-dev team
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.
package/README.md CHANGED
@@ -1,3 +1,67 @@
1
- # Temporary Holding Version
1
+ # @ai-for-dev/providers
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Providers [Pi](https://pi.dev) pour la formation AI4Dev. Le paquet ajoute deux fournisseurs de modèles :
4
+
5
+ | Commande | Serveur |
6
+ |---|---|
7
+ | `/login ia4dev-ilaas` | https://devllm.ilaas.fr/v1 |
8
+ | `/login ia4dev-gricad` | https://ia4dev-owui.univ-grenoble-alpes.fr/api |
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ pi install npm:@ai-for-dev/providers
14
+ ```
15
+
16
+ ## Utilisation
17
+
18
+ 1. Lancez `pi`.
19
+ 2. Tapez `/login ia4dev-ilaas` (ou `/login ia4dev-gricad`) et collez votre clé API.
20
+ 3. Choisissez un modèle avec `/model`.
21
+
22
+ La liste des modèles est lue sur le serveur (`GET /models`) avec votre clé. Elle se met à jour au démarrage, à l'ouverture de `/model` et après `/login`.
23
+
24
+ Vous pouvez aussi fournir la clé par variable d'environnement : `ILAAS_API_KEY` ou `IA4DEV_API_KEY`.
25
+
26
+ ## Changer d'URL
27
+
28
+ `IA4DEV_ILAAS_BASE_URL` et `IA4DEV_GRICAD_BASE_URL` remplacent l'URL par défaut.
29
+
30
+ ## Réglages des modèles
31
+
32
+ `extensions/index.ts` contient, pour chaque serveur, une table des modèles connus : taille du contexte, sortie maximale, lecture d'images et gestion du raisonnement. Ces valeurs ont été mesurées sur les serveurs. Le raisonnement peut être :
33
+
34
+ - réglable par niveau : Pi propose `off`, `low`, `medium` et `high`, et envoie `enable_thinking` et `reasoning_effort` dans `chat_template_kwargs`. La table donne la valeur à envoyer pour chaque niveau, car chaque modèle a son vocabulaire (`xhigh` pour Qwen 3.8, `max` pour DeepSeek V4.1) ;
35
+ - activable (`toggle`) : le modèle ne sait que réfléchir ou non. Pi propose `off` et `high`, et passe par `chat_template_kwargs.enable_thinking` ;
36
+ - permanent (`always`) : Pi ne propose que `high` ;
37
+ - absent (`none`) : Pi n'envoie aucun paramètre de raisonnement.
38
+
39
+ Seuls `qwen-3.8-27b` et `ARES/DeepSeek-V4.1-Flash` lisent un niveau d'effort dans leur modèle de chat. Ceux de Qwen 3.6 et de Gemma 4 ne connaissent que `enable_thinking`.
40
+
41
+ Un modèle marqué `hidden: true` n'apparaît pas, même si le serveur le liste. Un modèle qui n'est pas dans la table reste utilisable. Il prend la taille de contexte donnée par le serveur (128 000 tokens à défaut), 32 768 tokens de sortie, sans images ni raisonnement.
42
+
43
+ ## Limites
44
+
45
+ - Un fournisseur déjà défini sous le même nom dans `~/.pi/agent/models.json` prend le dessus sur celui du paquet.
46
+ - La liste des modèles est mise en cache. Après un changement d'URL, elle se met à jour au prochain rafraîchissement (`/model` ou `/login`).
47
+
48
+ ## Développement
49
+
50
+ ```bash
51
+ npm ci
52
+ npm run typecheck
53
+ npm test
54
+ ```
55
+
56
+ Les tests tournent hors ligne : un faux `pi` et un `fetch` simulé remplacent Pi et les serveurs.
57
+
58
+ ## Publication
59
+
60
+ La publication reprend le fonctionnement de `@ai-for-dev/combo` :
61
+
62
+ 1. Lancer le workflow `release-please` à la main. Il ouvre une pull request avec le `CHANGELOG.md` et la nouvelle version, calculés à partir des titres de commits (conventional commits).
63
+ 2. Fusionner cette pull request, puis relancer `release-please`. Ce second passage crée le tag et la release GitHub.
64
+ 3. La release déclenche `publish`, qui vérifie le code et envoie le paquet sur npm en mode « staged ».
65
+ 4. Approuver la version depuis une machine qui peut répondre à la double authentification : `npm stage list`, puis `npm stage approve <id>`.
66
+
67
+ Le dépôt a besoin du secret `RELEASE_PLEASE` (un token GitHub qui peut écrire le contenu et les pull requests), et npm doit déclarer ce dépôt et `publish.yml` comme éditeur de confiance (trusted publisher) pour `@ai-for-dev/providers`.
@@ -0,0 +1,189 @@
1
+ // The compat entry point: Pi maps the package root to it as well, and it is the one
2
+ // that exports openAICompletionsApi when the tests run under plain Node.
3
+ import {
4
+ createProvider,
5
+ envApiKeyAuth,
6
+ type Model,
7
+ openAICompletionsApi,
8
+ type RefreshModelsContext,
9
+ } from "@earendil-works/pi-ai/compat";
10
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
11
+
12
+ type ChatModel = Model<"openai-completions">;
13
+
14
+ /**
15
+ * How a model handles reasoning, measured against the real servers:
16
+ * - "toggle": chat_template_kwargs.enable_thinking switches reasoning on and off, nothing finer.
17
+ * - "always": always reasons and ignores every switch.
18
+ * - "none": no reasoning; any reasoning parameter makes the server fail.
19
+ * - Efforts: the chat template also reads a reasoning_effort, given here as the value
20
+ * to send for each of Pi's low, medium and high levels.
21
+ */
22
+ type Thinking = "toggle" | "always" | "none" | Efforts;
23
+
24
+ interface Efforts {
25
+ low: string;
26
+ medium: string;
27
+ high: string;
28
+ }
29
+
30
+ interface ModelTuning {
31
+ contextWindow?: number;
32
+ maxTokens?: number;
33
+ vision?: boolean;
34
+ thinking?: Thinking;
35
+ // Listed by the server but unusable for the course.
36
+ hidden?: boolean;
37
+ }
38
+
39
+ interface Endpoint {
40
+ id: string;
41
+ name: string;
42
+ baseUrl: string;
43
+ envVar: string;
44
+ models: Record<string, ModelTuning>;
45
+ }
46
+
47
+ const ENDPOINTS: Endpoint[] = [
48
+ {
49
+ id: "ia4dev-ilaas",
50
+ name: "ILAAS",
51
+ baseUrl: "https://devllm.ilaas.fr/v1",
52
+ envVar: "ILAAS_API_KEY",
53
+ models: {
54
+ "scaleway/glm-5.2": { contextWindow: 256_000, maxTokens: 16_384, vision: false, thinking: "always" },
55
+ "scaleway/glm-5.3": { contextWindow: 256_000, maxTokens: 16_384, vision: false, thinking: "always" },
56
+ "scaleway/deepseek-v4.1-flash": { contextWindow: 256_000, maxTokens: 32_768, vision: true, thinking: "always" },
57
+ "scaleway/deepseek-v4-flash-0731": { contextWindow: 256_000, maxTokens: 32_768, vision: false, thinking: "always" },
58
+ "qwen-3.6-35b-instruct": { contextWindow: 262_144, vision: true, thinking: "toggle" },
59
+ "gemma-4-31b": { contextWindow: 131_072, vision: true, thinking: "toggle" },
60
+ "llama-3.1-8b": { hidden: true },
61
+ "gpt-oss-120b": { hidden: true },
62
+ "mistral-small-4-119b": { contextWindow: 128_000, vision: true, thinking: "none" },
63
+ "mistral-medium-latest": { contextWindow: 128_000, vision: true, thinking: "none" },
64
+ },
65
+ },
66
+ {
67
+ id: "ia4dev-gricad",
68
+ name: "IA4Dev",
69
+ baseUrl: "https://ia4dev-owui.univ-grenoble-alpes.fr/api",
70
+ envVar: "IA4DEV_API_KEY",
71
+ models: {
72
+ // The chat template accepts low, medium and xhigh (its default).
73
+ "qwen-3.8-27b": { vision: true, thinking: { low: "low", medium: "medium", high: "xhigh" } },
74
+ // The deployed chat template accepts low, high (its default) and max, but not medium.
75
+ "ARES/DeepSeek-V4.1-Flash": { vision: true, thinking: { low: "low", medium: "high", high: "max" } },
76
+ "gemma-4-31b": { vision: true, thinking: "toggle" },
77
+ },
78
+ },
79
+ ];
80
+
81
+ const DEFAULT_CONTEXT_WINDOW = 128_000;
82
+ const DEFAULT_MAX_TOKENS = 32_768;
83
+ const FETCH_TIMEOUT_MS = 10_000;
84
+
85
+ type Reasoning = Pick<ChatModel, "reasoning" | "thinkingLevelMap"> & { compat: ChatModel["compat"] };
86
+
87
+ // Pi's levels without a counterpart on the server are mapped to null, which hides them.
88
+ function reasoningFor(thinking: Thinking): Reasoning {
89
+ if (thinking === "none") return { reasoning: false, compat: {} };
90
+ if (thinking === "always") {
91
+ return { reasoning: true, thinkingLevelMap: { off: null, minimal: null, low: null, medium: null }, compat: {} };
92
+ }
93
+ if (thinking === "toggle") {
94
+ return {
95
+ reasoning: true,
96
+ thinkingLevelMap: { minimal: null, low: null, medium: null },
97
+ compat: { thinkingFormat: "qwen-chat-template" },
98
+ };
99
+ }
100
+ return {
101
+ reasoning: true,
102
+ thinkingLevelMap: { minimal: null, ...thinking },
103
+ compat: {
104
+ thinkingFormat: "chat-template",
105
+ chatTemplateKwargs: {
106
+ enable_thinking: { $var: "thinking.enabled" },
107
+ preserve_thinking: true,
108
+ reasoning_effort: { $var: "thinking.effort", omitWhenOff: true },
109
+ },
110
+ },
111
+ };
112
+ }
113
+
114
+ interface RemoteModel {
115
+ id: string;
116
+ // LiteLLM tags embedding and reranking models with a mode; they cannot chat.
117
+ mode?: string;
118
+ // vLLM reports max_model_len, LiteLLM max_input_tokens and max_output_tokens.
119
+ max_model_len?: number;
120
+ max_input_tokens?: number;
121
+ max_output_tokens?: number;
122
+ }
123
+
124
+ function toModel(endpoint: Endpoint, remote: RemoteModel): ChatModel {
125
+ const tuning = endpoint.models[remote.id] ?? {};
126
+ const reasoning = reasoningFor(tuning.thinking ?? "none");
127
+ const contextWindow =
128
+ tuning.contextWindow ?? remote.max_model_len ?? remote.max_input_tokens ?? DEFAULT_CONTEXT_WINDOW;
129
+ const maxTokens = tuning.maxTokens ?? remote.max_output_tokens ?? DEFAULT_MAX_TOKENS;
130
+ return {
131
+ id: remote.id,
132
+ name: remote.id,
133
+ api: "openai-completions",
134
+ provider: endpoint.id,
135
+ baseUrl: endpoint.baseUrl,
136
+ input: tuning.vision ? ["text", "image"] : ["text"],
137
+ reasoning: reasoning.reasoning,
138
+ thinkingLevelMap: reasoning.thinkingLevelMap,
139
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
140
+ contextWindow,
141
+ maxTokens: Math.min(maxTokens, contextWindow),
142
+ compat: {
143
+ // These gateways reject the newer OpenAI-only fields.
144
+ supportsDeveloperRole: false,
145
+ supportsStore: false,
146
+ // A top-level reasoning_effort is ignored by vLLM chat templates and crashes the
147
+ // Mistral models; models that read an effort get it through the chat template.
148
+ supportsReasoningEffort: false,
149
+ ...reasoning.compat,
150
+ },
151
+ };
152
+ }
153
+
154
+ async function fetchModels(endpoint: Endpoint, context: RefreshModelsContext): Promise<ChatModel[]> {
155
+ const key = context.credential?.type === "api_key" ? context.credential.key : process.env[endpoint.envVar];
156
+ if (!context.allowNetwork || !key) return [];
157
+
158
+ const response = await fetch(`${endpoint.baseUrl}/models`, {
159
+ headers: { Authorization: `Bearer ${key}` },
160
+ signal: AbortSignal.any([context.signal, AbortSignal.timeout(FETCH_TIMEOUT_MS)]),
161
+ });
162
+ if (!response.ok) {
163
+ throw new Error(`${endpoint.name}: GET /models a répondu ${response.status}`);
164
+ }
165
+ const body = (await response.json()) as { data?: RemoteModel[] };
166
+ return (body.data ?? [])
167
+ .filter((m) => typeof m.id === "string" && (m.mode === undefined || m.mode === "chat"))
168
+ .filter((m) => !endpoint.models[m.id]?.hidden)
169
+ .map((m) => toModel(endpoint, m));
170
+ }
171
+
172
+ export default function (pi: ExtensionAPI) {
173
+ for (const base of ENDPOINTS) {
174
+ // <ID>_BASE_URL (ex: IA4DEV_ILAAS_BASE_URL) remplace l'URL par défaut, pour tester ou changer de serveur.
175
+ const urlVar = `${base.id.toUpperCase().replaceAll("-", "_")}_BASE_URL`;
176
+ const endpoint = { ...base, baseUrl: process.env[urlVar] ?? base.baseUrl };
177
+ pi.registerProvider(
178
+ createProvider<"openai-completions">({
179
+ id: endpoint.id,
180
+ name: endpoint.name,
181
+ baseUrl: endpoint.baseUrl,
182
+ auth: { apiKey: envApiKeyAuth(`${endpoint.name} API key`, [endpoint.envVar]) },
183
+ models: [],
184
+ fetchModels: (context) => fetchModels(endpoint, context),
185
+ api: openAICompletionsApi(),
186
+ }),
187
+ );
188
+ }
189
+ }
package/package.json CHANGED
@@ -1,6 +1,49 @@
1
1
  {
2
2
  "name": "@ai-for-dev/providers",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "Pi providers for the AI4Dev course models (ILAAS and IA4Dev)",
5
+ "keywords": [
6
+ "pi",
7
+ "pi-package",
8
+ "provider",
9
+ "llm"
10
+ ],
11
+ "license": "MIT",
12
+ "author": "AI-for-dev team",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/AI-for-dev/providers.git"
16
+ },
17
+ "bugs": {
18
+ "url": "https://github.com/AI-for-dev/providers/issues"
19
+ },
20
+ "type": "module",
21
+ "files": [
22
+ "extensions",
23
+ "LICENSE",
24
+ "README.md"
25
+ ],
26
+ "pi": {
27
+ "extensions": [
28
+ "./extensions/index.ts"
29
+ ]
30
+ },
31
+ "scripts": {
32
+ "test": "node --test 'test/*.test.ts'",
33
+ "typecheck": "tsc --noEmit"
34
+ },
35
+ "publishConfig": {
36
+ "access": "public",
37
+ "provenance": true
38
+ },
39
+ "peerDependencies": {
40
+ "@earendil-works/pi-ai": "*",
41
+ "@earendil-works/pi-coding-agent": "*"
42
+ },
43
+ "devDependencies": {
44
+ "@earendil-works/pi-ai": "^1.3.0",
45
+ "@earendil-works/pi-coding-agent": "^1.3.0",
46
+ "@types/node": "^24.13.3",
47
+ "typescript": "^5.9.0"
48
+ }
49
+ }