pi-free 2.0.8 → 2.0.10
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/CHANGELOG.md +29 -1
- package/README.md +588 -572
- package/banner.jpg +0 -0
- package/banner.png +0 -0
- package/banner.svg +12 -10
- package/config.ts +349 -337
- package/constants.ts +106 -103
- package/index.ts +242 -239
- package/lib/built-in-toggle.ts +2 -2
- package/lib/model-detection.ts +1 -1
- package/lib/model-enhancer.ts +20 -20
- package/lib/provider-compat.ts +1 -1
- package/lib/registry.ts +1 -1
- package/lib/util.ts +524 -460
- package/package.json +70 -68
- package/provider-helper.ts +1 -1
- package/providers/cline/cline-auth.ts +1 -1
- package/providers/cline/cline.ts +2 -2
- package/providers/codestral/codestral.ts +1 -1
- package/providers/crofai/crofai.ts +190 -99
- package/providers/deepinfra/deepinfra.ts +206 -109
- package/providers/dynamic-built-in/index.ts +1 -1
- package/providers/kilo/kilo-auth.ts +1 -1
- package/providers/kilo/kilo.ts +2 -2
- package/providers/llm7/llm7.ts +1 -1
- package/providers/nvidia/nvidia.ts +1 -1
- package/providers/ollama/ollama.ts +610 -295
- package/providers/ollama/thinking-levels.ts +96 -0
- package/providers/qwen/qwen-auth.ts +1 -1
- package/providers/qwen/qwen-models.ts +101 -101
- package/providers/qwen/qwen.ts +2 -2
- package/providers/sambanova/sambanova.ts +1 -1
- package/providers/together/together.ts +197 -0
- package/providers/zenmux/zenmux.ts +194 -179
|
@@ -1,109 +1,206 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DeepInfra Provider Extension
|
|
3
|
-
*
|
|
4
|
-
* DeepInfra is an AI inference cloud with an OpenAI-compatible API for
|
|
5
|
-
* 100+ open-source models (Llama, DeepSeek, Mistral, Qwen, Mixtral, etc.).
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
import {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
import {
|
|
37
|
-
import {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
1
|
+
/**
|
|
2
|
+
* DeepInfra Provider Extension
|
|
3
|
+
*
|
|
4
|
+
* DeepInfra is an AI inference cloud with an OpenAI-compatible API for
|
|
5
|
+
* 100+ open-source models (Llama, DeepSeek, Mistral, Qwen, Mixtral, etc.).
|
|
6
|
+
*
|
|
7
|
+
* NOTE: DeepInfra's /v1/openai/models buries real model data in a "metadata"
|
|
8
|
+
* field (context_length, max_tokens, pricing, tags). We extract it here.
|
|
9
|
+
* Pricing is per-MILLION tokens.
|
|
10
|
+
*
|
|
11
|
+
* Free tier:
|
|
12
|
+
* - $5 one-time credit on signup (no credit card)
|
|
13
|
+
* - ~5M tokens, expires after 90 days
|
|
14
|
+
* - 60 RPM (varies by model)
|
|
15
|
+
*
|
|
16
|
+
* Paid: pay-per-token after credits exhaust
|
|
17
|
+
*
|
|
18
|
+
* Endpoint:
|
|
19
|
+
* Chat: https://api.deepinfra.com/v1/openai/chat/completions
|
|
20
|
+
*
|
|
21
|
+
* Setup:
|
|
22
|
+
* 1. Sign up at https://deepinfra.com/ (GitHub or email)
|
|
23
|
+
* 2. Get API key from https://deepinfra.com/dash/api_keys
|
|
24
|
+
* 3. Set DEEPINFRA_TOKEN env var (or add to ~/.pi/free.json)
|
|
25
|
+
*
|
|
26
|
+
* Usage:
|
|
27
|
+
* pi install git:github.com/apmantza/pi-free
|
|
28
|
+
* # Set DEEPINFRA_TOKEN env var
|
|
29
|
+
* # Models appear in /model selector as "deepinfra/meta-llama/..."
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
import type {
|
|
33
|
+
ExtensionAPI,
|
|
34
|
+
ProviderModelConfig,
|
|
35
|
+
} from "@earendil-works/pi-coding-agent";
|
|
36
|
+
import { getDeepinfraApiKey } from "../../config.ts";
|
|
37
|
+
import {
|
|
38
|
+
BASE_URL_DEEPINFRA,
|
|
39
|
+
DEFAULT_FETCH_TIMEOUT_MS,
|
|
40
|
+
PROVIDER_DEEPINFRA,
|
|
41
|
+
} from "../../constants.ts";
|
|
42
|
+
import { createLogger } from "../../lib/logger.ts";
|
|
43
|
+
import {
|
|
44
|
+
getProxyModelCompat,
|
|
45
|
+
isLikelyReasoningModel,
|
|
46
|
+
} from "../../lib/provider-compat.ts";
|
|
47
|
+
import { registerWithGlobalToggle } from "../../lib/registry.ts";
|
|
48
|
+
import { fetchWithRetry } from "../../lib/util.ts";
|
|
49
|
+
import { createReRegister, setupProvider } from "../../provider-helper.ts";
|
|
50
|
+
|
|
51
|
+
const _logger = createLogger("deepinfra");
|
|
52
|
+
|
|
53
|
+
// =============================================================================
|
|
54
|
+
// Types
|
|
55
|
+
// =============================================================================
|
|
56
|
+
|
|
57
|
+
interface DeepInfraModel {
|
|
58
|
+
id: string;
|
|
59
|
+
metadata?: {
|
|
60
|
+
context_length?: number;
|
|
61
|
+
max_tokens?: number;
|
|
62
|
+
description?: string;
|
|
63
|
+
pricing?: {
|
|
64
|
+
input_tokens?: number;
|
|
65
|
+
output_tokens?: number;
|
|
66
|
+
};
|
|
67
|
+
tags?: string[];
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// =============================================================================
|
|
72
|
+
// Fetch
|
|
73
|
+
// =============================================================================
|
|
74
|
+
|
|
75
|
+
async function fetchDeepinfraModels(
|
|
76
|
+
apiKey: string,
|
|
77
|
+
): Promise<ProviderModelConfig[]> {
|
|
78
|
+
const response = await fetchWithRetry(
|
|
79
|
+
`${BASE_URL_DEEPINFRA}/models`,
|
|
80
|
+
{
|
|
81
|
+
headers: {
|
|
82
|
+
Authorization: `Bearer ${apiKey}`,
|
|
83
|
+
"Content-Type": "application/json",
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
3,
|
|
87
|
+
1000,
|
|
88
|
+
DEFAULT_FETCH_TIMEOUT_MS,
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
if (!response.ok) {
|
|
92
|
+
throw new Error(
|
|
93
|
+
`DeepInfra API error: ${response.status} ${response.statusText}`,
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const json = (await response.json()) as { data?: DeepInfraModel[] };
|
|
98
|
+
const models = json.data ?? [];
|
|
99
|
+
|
|
100
|
+
_logger.info(`[deepinfra] Fetched ${models.length} models`);
|
|
101
|
+
|
|
102
|
+
return models
|
|
103
|
+
.filter((m) => {
|
|
104
|
+
const id = m.id.toLowerCase();
|
|
105
|
+
// Filter out non-chat models
|
|
106
|
+
if (id.includes("embed")) return false;
|
|
107
|
+
if (id.includes("rerank")) return false;
|
|
108
|
+
if (id.includes("whisper")) return false;
|
|
109
|
+
if (id.includes("speech")) return false;
|
|
110
|
+
return true;
|
|
111
|
+
})
|
|
112
|
+
.map((m): ProviderModelConfig => {
|
|
113
|
+
const meta = m.metadata;
|
|
114
|
+
const name = m.id.split("/").pop() || m.id;
|
|
115
|
+
|
|
116
|
+
// Reasoning: check tags first, fall back to name heuristic
|
|
117
|
+
const reasoning =
|
|
118
|
+
meta?.tags?.includes("reasoning") ??
|
|
119
|
+
isLikelyReasoningModel({ id: m.id, name });
|
|
120
|
+
|
|
121
|
+
// Pricing is per-MILLION tokens. Divide to get per-token (Pi convention).
|
|
122
|
+
const inputCost = (meta?.pricing?.input_tokens ?? 0.3) / 1_000_000;
|
|
123
|
+
const outputCost = (meta?.pricing?.output_tokens ?? 0.9) / 1_000_000;
|
|
124
|
+
|
|
125
|
+
return {
|
|
126
|
+
id: m.id,
|
|
127
|
+
name,
|
|
128
|
+
reasoning,
|
|
129
|
+
input: ["text"],
|
|
130
|
+
cost: {
|
|
131
|
+
input: inputCost,
|
|
132
|
+
output: outputCost,
|
|
133
|
+
cacheRead: 0,
|
|
134
|
+
cacheWrite: 0,
|
|
135
|
+
},
|
|
136
|
+
contextWindow: meta?.context_length ?? 128_000,
|
|
137
|
+
maxTokens: meta?.max_tokens ?? 16_384,
|
|
138
|
+
compat: getProxyModelCompat({ id: m.id, name }),
|
|
139
|
+
};
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// =============================================================================
|
|
144
|
+
// Extension Entry Point
|
|
145
|
+
// =============================================================================
|
|
146
|
+
|
|
147
|
+
export default async function deepinfraProvider(pi: ExtensionAPI) {
|
|
148
|
+
const apiKey = getDeepinfraApiKey();
|
|
149
|
+
|
|
150
|
+
if (!apiKey) {
|
|
151
|
+
_logger.info(
|
|
152
|
+
"[deepinfra] Skipping — DEEPINFRA_TOKEN not set. Sign up at https://deepinfra.com/",
|
|
153
|
+
);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Fetch models
|
|
158
|
+
const allModels = await fetchDeepinfraModels(apiKey);
|
|
159
|
+
|
|
160
|
+
if (allModels.length === 0) {
|
|
161
|
+
_logger.warn("[deepinfra] No chat models available");
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// DeepInfra is a trial credit provider — $5 one-time credit, no truly free models.
|
|
166
|
+
// All models are marked as paid. When free-only mode is ON, no models are shown.
|
|
167
|
+
// Toggle free-only OFF to see all models.
|
|
168
|
+
const freeModels: ProviderModelConfig[] = [];
|
|
169
|
+
const stored = { free: freeModels, all: allModels };
|
|
170
|
+
|
|
171
|
+
_logger.info(
|
|
172
|
+
`[deepinfra] Registered ${allModels.length} chat models (trial credit, 0 free)`,
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
// Create re-register function
|
|
176
|
+
const reRegister = createReRegister(pi, {
|
|
177
|
+
providerId: PROVIDER_DEEPINFRA,
|
|
178
|
+
baseUrl: BASE_URL_DEEPINFRA,
|
|
179
|
+
apiKey,
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
// Register with global toggle
|
|
183
|
+
registerWithGlobalToggle(PROVIDER_DEEPINFRA, stored, reRegister, true);
|
|
184
|
+
|
|
185
|
+
// Setup provider with toggle command
|
|
186
|
+
setupProvider(
|
|
187
|
+
pi,
|
|
188
|
+
{
|
|
189
|
+
providerId: PROVIDER_DEEPINFRA,
|
|
190
|
+
initialShowPaid: true, // trial credit: default to showing all models
|
|
191
|
+
tosUrl: "https://deepinfra.com/pricing",
|
|
192
|
+
reRegister: (models, _stored) => {
|
|
193
|
+
if (_stored) {
|
|
194
|
+
stored.free = _stored.free;
|
|
195
|
+
stored.all = _stored.all;
|
|
196
|
+
}
|
|
197
|
+
reRegister(models);
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
stored,
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
// Initial registration — DeepInfra is a trial-credit provider,
|
|
204
|
+
// so always show all models. Users see them immediately on setup.
|
|
205
|
+
reRegister(allModels);
|
|
206
|
+
}
|
package/providers/kilo/kilo.ts
CHANGED
|
@@ -12,11 +12,11 @@
|
|
|
12
12
|
* # Free models visible immediately; /login kilo for paid access
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
import type { Api, Model, OAuthCredentials } from "@
|
|
15
|
+
import type { Api, Model, OAuthCredentials } from "@earendil-works/pi-ai";
|
|
16
16
|
import type {
|
|
17
17
|
ExtensionAPI,
|
|
18
18
|
ProviderModelConfig,
|
|
19
|
-
} from "@
|
|
19
|
+
} from "@earendil-works/pi-coding-agent";
|
|
20
20
|
import {
|
|
21
21
|
getKiloFreeOnly,
|
|
22
22
|
getKiloShowPaid,
|
package/providers/llm7/llm7.ts
CHANGED
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
import type {
|
|
36
36
|
ExtensionAPI,
|
|
37
37
|
ProviderModelConfig,
|
|
38
|
-
} from "@
|
|
38
|
+
} from "@earendil-works/pi-coding-agent";
|
|
39
39
|
import { getLlm7ApiKey, getLlm7ShowPaid } from "../../config.ts";
|
|
40
40
|
import { BASE_URL_LLM7, PROVIDER_LLM7 } from "../../constants.ts";
|
|
41
41
|
import { createLogger } from "../../lib/logger.ts";
|