promptimizer-cli 0.1.2 → 0.1.4
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/README.md +2 -4
- package/bin/promptimizer.mjs +109 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
# promptimizer-cli
|
|
2
2
|
|
|
3
|
-
Login with a `pmz_live_` key, connect a provider, route prompts, and read savings.
|
|
4
|
-
|
|
5
3
|
```bash
|
|
6
4
|
npm install -g promptimizer-cli
|
|
7
|
-
|
|
8
|
-
npx promptimizer-cli
|
|
5
|
+
npx promptimizer-cli --help
|
|
6
|
+
npx promptimizer-cli login --help
|
|
9
7
|
```
|
|
10
8
|
|
|
11
9
|
```bash
|
package/bin/promptimizer.mjs
CHANGED
|
@@ -9,15 +9,82 @@ const DEFAULT_URL = process.env.PROMPTIMIZER_URL || "https://hackathon-omega-lia
|
|
|
9
9
|
const CONFIG_PATH = join(homedir(), ".promptimizer", "config.json");
|
|
10
10
|
|
|
11
11
|
const COMMANDS = [
|
|
12
|
-
["login", "
|
|
13
|
-
["logout", "
|
|
12
|
+
["login", "Save a Promptimizer API key"],
|
|
13
|
+
["logout", "Remove the saved key"],
|
|
14
14
|
["connect", "Attach a model provider"],
|
|
15
15
|
["chat", "Route a completion"],
|
|
16
|
-
["models", "
|
|
17
|
-
["savings", "
|
|
18
|
-
["providers", "
|
|
16
|
+
["models", "List the connected fleet"],
|
|
17
|
+
["savings", "Show account savings"],
|
|
18
|
+
["providers", "List known provider URLs"],
|
|
19
19
|
];
|
|
20
20
|
|
|
21
|
+
const COMMAND_HELP = {
|
|
22
|
+
login: [
|
|
23
|
+
"Usage",
|
|
24
|
+
" promptimizer login --key <pmz_live_...>",
|
|
25
|
+
"",
|
|
26
|
+
"Save a key from /account. Stored in ~/.promptimizer/config.json.",
|
|
27
|
+
"",
|
|
28
|
+
"Options",
|
|
29
|
+
" --key, -k Promptimizer API key",
|
|
30
|
+
" --url, -u Gateway URL",
|
|
31
|
+
],
|
|
32
|
+
logout: ["Usage", " promptimizer logout", "", "Deletes ~/.promptimizer/config.json."],
|
|
33
|
+
connect: [
|
|
34
|
+
"Usage",
|
|
35
|
+
" promptimizer connect <provider> --key <vendor-key>",
|
|
36
|
+
" promptimizer connect custom --base-url <url> --key <vendor-key>",
|
|
37
|
+
" promptimizer connect simulator",
|
|
38
|
+
"",
|
|
39
|
+
"Attach a provider to the signed-in account. Known hosts do not need --base-url.",
|
|
40
|
+
"",
|
|
41
|
+
"Options",
|
|
42
|
+
" --key, -k Provider API key (or $BASETEN_API_KEY, $GROQ_API_KEY, …)",
|
|
43
|
+
" --base-url Required for custom",
|
|
44
|
+
" --pmz Promptimizer key (else the saved login)",
|
|
45
|
+
" --url, -u Gateway URL",
|
|
46
|
+
],
|
|
47
|
+
chat: [
|
|
48
|
+
"Usage",
|
|
49
|
+
' promptimizer chat "<prompt>"',
|
|
50
|
+
"",
|
|
51
|
+
"Route one completion through the connected provider.",
|
|
52
|
+
"",
|
|
53
|
+
"Options",
|
|
54
|
+
" --prompt Prompt text",
|
|
55
|
+
" --pmz Promptimizer key (else the saved login)",
|
|
56
|
+
" --url, -u Gateway URL",
|
|
57
|
+
],
|
|
58
|
+
models: [
|
|
59
|
+
"Usage",
|
|
60
|
+
" promptimizer models",
|
|
61
|
+
"",
|
|
62
|
+
"List chat models on the current session.",
|
|
63
|
+
"",
|
|
64
|
+
"Options",
|
|
65
|
+
" --url, -u Gateway URL",
|
|
66
|
+
],
|
|
67
|
+
savings: [
|
|
68
|
+
"Usage",
|
|
69
|
+
" promptimizer savings",
|
|
70
|
+
"",
|
|
71
|
+
"Print routed spend versus the frontier baseline.",
|
|
72
|
+
"",
|
|
73
|
+
"Options",
|
|
74
|
+
" --key, -k Promptimizer API key",
|
|
75
|
+
" --url, -u Gateway URL",
|
|
76
|
+
],
|
|
77
|
+
providers: [
|
|
78
|
+
"Usage",
|
|
79
|
+
" promptimizer providers",
|
|
80
|
+
"",
|
|
81
|
+
"Print known provider ids and base URLs.",
|
|
82
|
+
"",
|
|
83
|
+
"Options",
|
|
84
|
+
" --url, -u Gateway URL",
|
|
85
|
+
],
|
|
86
|
+
};
|
|
87
|
+
|
|
21
88
|
function die(message, code = 1) {
|
|
22
89
|
process.stderr.write(`${message}\n`);
|
|
23
90
|
process.exit(code);
|
|
@@ -84,13 +151,20 @@ function usd(value) {
|
|
|
84
151
|
|
|
85
152
|
function help() {
|
|
86
153
|
const width = Math.max(...COMMANDS.map(([name]) => name.length));
|
|
154
|
+
out("Usage: promptimizer [--url <gateway>] <command> [options]");
|
|
87
155
|
out();
|
|
88
|
-
out("
|
|
89
|
-
out(" promptimizer <command>");
|
|
156
|
+
out("Route prompts through Promptimizer. Create a key at /account.");
|
|
90
157
|
out();
|
|
91
158
|
out("Commands");
|
|
92
159
|
for (const [name, desc] of COMMANDS) out(` ${name.padEnd(width + 2)}${desc}`);
|
|
93
160
|
out();
|
|
161
|
+
out("Global options");
|
|
162
|
+
out(" --url, -u Gateway URL (default: hosted app, or $PROMPTIMIZER_URL)");
|
|
163
|
+
out(" --help, -h Show help");
|
|
164
|
+
out(" --version, -v Print version");
|
|
165
|
+
out();
|
|
166
|
+
out("Run `promptimizer <command> --help` for command flags.");
|
|
167
|
+
out();
|
|
94
168
|
out("Examples");
|
|
95
169
|
out(" promptimizer login --key pmz_live_…");
|
|
96
170
|
out(" promptimizer connect baseten --key $BASETEN_API_KEY");
|
|
@@ -99,6 +173,14 @@ function help() {
|
|
|
99
173
|
out();
|
|
100
174
|
}
|
|
101
175
|
|
|
176
|
+
function commandHelp(name) {
|
|
177
|
+
const lines = COMMAND_HELP[name];
|
|
178
|
+
if (!lines) die(`Unknown command "${name}". Run promptimizer --help.`);
|
|
179
|
+
out();
|
|
180
|
+
for (const line of lines) out(line);
|
|
181
|
+
out();
|
|
182
|
+
}
|
|
183
|
+
|
|
102
184
|
async function request(path, { method = "GET", body, apiKey, sessionId, gatewayURL } = {}) {
|
|
103
185
|
const headers = { "content-type": "application/json" };
|
|
104
186
|
if (apiKey) headers.authorization = `Bearer ${apiKey}`;
|
|
@@ -263,20 +345,33 @@ async function cmdSavings(flags) {
|
|
|
263
345
|
out();
|
|
264
346
|
}
|
|
265
347
|
|
|
348
|
+
function printVersion() {
|
|
349
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
350
|
+
const pkg = JSON.parse(readFileSync(join(here, "../package.json"), "utf8"));
|
|
351
|
+
out(pkg.version);
|
|
352
|
+
}
|
|
353
|
+
|
|
266
354
|
async function main() {
|
|
267
355
|
const { flags, positional } = parse(process.argv.slice(2));
|
|
268
|
-
if (flags.
|
|
269
|
-
|
|
356
|
+
if (flags.version || flags.v || positional[0] === "version") {
|
|
357
|
+
printVersion();
|
|
270
358
|
return;
|
|
271
359
|
}
|
|
272
|
-
if (
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
360
|
+
if (positional[0] === "help") {
|
|
361
|
+
if (positional[1]) commandHelp(positional[1]);
|
|
362
|
+
else help();
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
if (positional.length === 0) {
|
|
366
|
+
help();
|
|
276
367
|
return;
|
|
277
368
|
}
|
|
278
369
|
|
|
279
370
|
const [command, ...rest] = positional;
|
|
371
|
+
if (flags.help || flags.h) {
|
|
372
|
+
commandHelp(command);
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
280
375
|
if (command === "login") return cmdLogin(flags);
|
|
281
376
|
if (command === "logout") return cmdLogout();
|
|
282
377
|
if (command === "providers") return cmdProviders(flags);
|
|
@@ -284,7 +379,7 @@ async function main() {
|
|
|
284
379
|
if (command === "chat") return cmdChat(flags, rest);
|
|
285
380
|
if (command === "models") return cmdModels(flags);
|
|
286
381
|
if (command === "savings") return cmdSavings(flags);
|
|
287
|
-
die(`Unknown command "${command}".`);
|
|
382
|
+
die(`Unknown command "${command}". Run promptimizer --help.`);
|
|
288
383
|
}
|
|
289
384
|
|
|
290
385
|
main().catch((error) => die(error instanceof Error ? error.message : String(error)));
|