@aivax/cli 0.0.0-stage → 1.1.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 +21 -0
- package/README.md +213 -2
- package/package.json +41 -5
- package/src/args.js +84 -0
- package/src/cli.js +124 -0
- package/src/commands/account.js +132 -0
- package/src/commands/analytics.js +30 -0
- package/src/commands/api.js +37 -0
- package/src/commands/auth.js +142 -0
- package/src/commands/batch.js +191 -0
- package/src/commands/chat-clients.js +157 -0
- package/src/commands/conversations.js +92 -0
- package/src/commands/crud.js +68 -0
- package/src/commands/docs.js +91 -0
- package/src/commands/gateways.js +85 -0
- package/src/commands/generate.js +197 -0
- package/src/commands/logs.js +41 -0
- package/src/commands/models.js +38 -0
- package/src/commands/ocr.js +370 -0
- package/src/commands/rag.js +452 -0
- package/src/commands/shell.js +46 -0
- package/src/commands/skills.js +48 -0
- package/src/commands/tests.js +429 -0
- package/src/commands/web.js +68 -0
- package/src/errors.js +19 -0
- package/src/http.js +175 -0
- package/src/input.js +120 -0
- package/src/pdf.js +209 -0
- package/src/profiles.js +67 -0
- package/src/prompt.js +67 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { UsageError } from "../errors.js";
|
|
2
|
+
import { call, seg } from "../http.js";
|
|
3
|
+
import { dataOption, payload, readJson, readSource } from "../input.js";
|
|
4
|
+
|
|
5
|
+
import { confirm } from "../prompt.js";
|
|
6
|
+
export const idOption = noun => ({ value: "<id>", required: true, description: `${noun} identifier.` });
|
|
7
|
+
|
|
8
|
+
export const filterOption = { alias: "q", value: "<text>", description: "Optional search text." };
|
|
9
|
+
|
|
10
|
+
async function body(ctx, fields) {
|
|
11
|
+
const entries = await Promise.all(Object.entries(fields).map(async ([key, spec]) => {
|
|
12
|
+
const value = ctx.options[key];
|
|
13
|
+
|
|
14
|
+
if (value === undefined) {
|
|
15
|
+
return [spec.key ?? key, undefined];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return [spec.key ?? key, spec.json ? await readJson(value, `--${key}`) : spec.source ? await readSource(value) : value];
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
const result = await payload(ctx, Object.fromEntries(entries));
|
|
22
|
+
|
|
23
|
+
if (!Object.keys(result).length) {
|
|
24
|
+
throw new UsageError(`Provide the request body with -d or with the field options.`);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function crud({ base, noun, plural = `${noun}s`, updateMethod = "PATCH", fields = {} }) {
|
|
31
|
+
const item = ctx => `${base}/${seg(ctx.options.id)}`;
|
|
32
|
+
const id = { id: idOption(noun) };
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
list: {
|
|
36
|
+
aliases: ["ls"],
|
|
37
|
+
description: `List ${plural}.`,
|
|
38
|
+
options: { filter: filterOption },
|
|
39
|
+
run: ctx => call(ctx, "GET", base, { query: { filter: ctx.options.filter } })
|
|
40
|
+
},
|
|
41
|
+
get: {
|
|
42
|
+
aliases: ["view"],
|
|
43
|
+
description: `Show one ${noun}.`,
|
|
44
|
+
options: id,
|
|
45
|
+
run: ctx => call(ctx, "GET", item(ctx))
|
|
46
|
+
},
|
|
47
|
+
create: {
|
|
48
|
+
description: `Create a ${noun}.`,
|
|
49
|
+
options: { data: dataOption(), ...fields },
|
|
50
|
+
run: async ctx => call(ctx, "POST", base, { body: await body(ctx, fields) })
|
|
51
|
+
},
|
|
52
|
+
patch: {
|
|
53
|
+
aliases: ["update", "edit"],
|
|
54
|
+
description: `Update a ${noun}. Send only the fields to change.`,
|
|
55
|
+
options: { ...id, data: dataOption(), ...fields },
|
|
56
|
+
run: async ctx => call(ctx, updateMethod, item(ctx), { body: await body(ctx, fields) })
|
|
57
|
+
},
|
|
58
|
+
delete: {
|
|
59
|
+
aliases: ["rm"],
|
|
60
|
+
description: `Delete a ${noun}.`,
|
|
61
|
+
options: id,
|
|
62
|
+
run: async ctx => {
|
|
63
|
+
await confirm(ctx, `Delete ${noun} ${ctx.options.id}?`);
|
|
64
|
+
await call(ctx, "DELETE", item(ctx));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { UsageError } from "../errors.js";
|
|
2
|
+
import { fetchData, print, request } from "../http.js";
|
|
3
|
+
|
|
4
|
+
const REFERENCE_URL = "https://inference.aivax.net/apidocs/llms.txt";
|
|
5
|
+
|
|
6
|
+
const GUIDE = `AIVAX CLI guidance
|
|
7
|
+
|
|
8
|
+
Authentication
|
|
9
|
+
aivax auth login Prompts for the login key and, when enabled, the 2FA code.
|
|
10
|
+
aivax auth login --login-key <key> --2fa <code> --profile-name work
|
|
11
|
+
AIVAX_API_KEY=<key> aivax ... Uses an API key instead of a saved profile.
|
|
12
|
+
AIVAX_ENDPOINT=<url> aivax ... Overrides the API endpoint.
|
|
13
|
+
|
|
14
|
+
Request bodies
|
|
15
|
+
-d '{"json": true}' Inline JSON body.
|
|
16
|
+
-d @body.json Reads the body from a file.
|
|
17
|
+
-d - Reads the body from stdin.
|
|
18
|
+
Field flags (such as --name) are merged over the -d body.
|
|
19
|
+
|
|
20
|
+
Output
|
|
21
|
+
Responses are agent-optimized by default (X-Response-Truncating: agent-optimized).
|
|
22
|
+
Use --verbose for the complete JSON response.
|
|
23
|
+
Use -o <file> on export and download commands to save the result.
|
|
24
|
+
|
|
25
|
+
Destructive commands
|
|
26
|
+
Delete, reset, clear and similar commands ask for confirmation. Pass --yes to skip it.
|
|
27
|
+
|
|
28
|
+
Raw access
|
|
29
|
+
aivax api <METHOD> <path> [-d body] Calls any endpoint not covered by a dedicated command.
|
|
30
|
+
|
|
31
|
+
API reference
|
|
32
|
+
aivax docs reference Lists every endpoint.
|
|
33
|
+
aivax docs reference <Endpoint> Shows one endpoint, e.g. "aivax docs reference EditAIGateway".
|
|
34
|
+
aivax docs search <terms...> Semantic search over the manual and API reference.
|
|
35
|
+
`;
|
|
36
|
+
|
|
37
|
+
const reference = {
|
|
38
|
+
description: "Show the API reference index, or one endpoint by name.",
|
|
39
|
+
args: "[endpoint]",
|
|
40
|
+
async run(ctx) {
|
|
41
|
+
const url = new URL(REFERENCE_URL);
|
|
42
|
+
if (ctx.args[0]) url.searchParams.set("endpoint", ctx.args[0]);
|
|
43
|
+
|
|
44
|
+
const response = await fetch(url, { headers: { "X-Response-Truncating": "agent-optimized" } });
|
|
45
|
+
print(await response.text());
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const search = {
|
|
50
|
+
description: "Search the AIVAX manual and API reference.",
|
|
51
|
+
options: {
|
|
52
|
+
type: { alias: "t", value: "<library>", description: "api-function-reference, documentation-manual or all (default)." }
|
|
53
|
+
},
|
|
54
|
+
args: "<terms...>",
|
|
55
|
+
minArgs: 1,
|
|
56
|
+
async run(ctx) {
|
|
57
|
+
const response = await request(ctx, "POST", "/v1/mcp/documentation", {
|
|
58
|
+
agentOutput: false,
|
|
59
|
+
headers: { Accept: "application/json, text/event-stream" },
|
|
60
|
+
body: {
|
|
61
|
+
jsonrpc: "2.0",
|
|
62
|
+
id: 1,
|
|
63
|
+
method: "tools/call",
|
|
64
|
+
params: {
|
|
65
|
+
name: "aivax_search_documentation",
|
|
66
|
+
arguments: { search_terms: ctx.args, search_type: ctx.options.type ?? "all" }
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const message = await response.json();
|
|
72
|
+
if (message.error) {
|
|
73
|
+
throw new UsageError(message.error.message);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
print(message.result.content.map(part => part.text).join("\n"));
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export default {
|
|
81
|
+
description: "Documentation-specific commands and CLI guidance.",
|
|
82
|
+
commands: {
|
|
83
|
+
guide: { description: "Show CLI usage guidance.", run: () => print(GUIDE) },
|
|
84
|
+
reference,
|
|
85
|
+
search,
|
|
86
|
+
setup: {
|
|
87
|
+
description: "Generate a setup prompt URL to configure an agent with this account.",
|
|
88
|
+
run: async ctx => print(await fetchData(ctx, "GET", "/api/v1/accounts/agent-setup-prompt"))
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { UsageError } from "../errors.js";
|
|
2
|
+
import { events, print, request } from "../http.js";
|
|
3
|
+
import { contentPart, readJson, readSource } from "../input.js";
|
|
4
|
+
import { crud } from "./crud.js";
|
|
5
|
+
|
|
6
|
+
const chat = {
|
|
7
|
+
aliases: ["complete"],
|
|
8
|
+
description: "Send a chat completion to a gateway or integrated model.",
|
|
9
|
+
options: {
|
|
10
|
+
model: { alias: "m", value: "<model>", required: true, description: "AI gateway ID, slug or integrated model name." },
|
|
11
|
+
prompt: { alias: "p", value: "<text>", description: "User message. Use @file or - to read it. Also accepted as positional text." },
|
|
12
|
+
system: { alias: "s", value: "<text>", description: "Optional system message." },
|
|
13
|
+
messages: { value: "<json>", description: "OpenAI-compatible messages array (JSON, @file or -). Replaces --prompt." },
|
|
14
|
+
file: { alias: "f", value: "<file>", list: true, description: "Image, audio, video or document attached to the user message. Repeatable." },
|
|
15
|
+
stream: { description: "Stream the answer as it is generated." },
|
|
16
|
+
json: { description: "Print the full OpenAI-compatible response instead of only the answer text." },
|
|
17
|
+
reasoningEffort: { value: "<level>", description: "Optional reasoning effort." },
|
|
18
|
+
temperature: { value: "<n>", number: true, description: "Optional sampling temperature." },
|
|
19
|
+
maxTokens: { value: "<n>", number: true, description: "Optional maximum completion tokens." },
|
|
20
|
+
user: { value: "<id>", description: "Optional external user identifier." }
|
|
21
|
+
},
|
|
22
|
+
args: "[prompt]",
|
|
23
|
+
async run(ctx) {
|
|
24
|
+
const { options } = ctx;
|
|
25
|
+
let messages = options.messages && await readJson(options.messages, "--messages");
|
|
26
|
+
|
|
27
|
+
if (!messages) {
|
|
28
|
+
const text = options.prompt ? await readSource(options.prompt) : ctx.args.join(" ");
|
|
29
|
+
const parts = await Promise.all((options.file ?? []).map(contentPart));
|
|
30
|
+
|
|
31
|
+
if (!text && !parts.length) {
|
|
32
|
+
throw new UsageError("Provide a prompt with -p, --messages or positional text.");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
messages = [
|
|
36
|
+
...(options.system ? [{ role: "system", content: options.system }] : []),
|
|
37
|
+
{ role: "user", content: parts.length ? [...(text ? [{ type: "text", text }] : []), ...parts] : text }
|
|
38
|
+
];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const body = {
|
|
42
|
+
model: options.model,
|
|
43
|
+
messages,
|
|
44
|
+
stream: Boolean(options.stream),
|
|
45
|
+
reasoning_effort: options.reasoningEffort,
|
|
46
|
+
temperature: options.temperature,
|
|
47
|
+
max_completion_tokens: options.maxTokens,
|
|
48
|
+
user: options.user
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const response = await request(ctx, "POST", "/v1/chat/completions", { body, agentOutput: false });
|
|
52
|
+
|
|
53
|
+
if (!options.stream) {
|
|
54
|
+
const result = await response.json();
|
|
55
|
+
print(options.json ? result : result.choices?.[0]?.message?.content ?? "");
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
for await (const data of events(response)) {
|
|
60
|
+
if (data === "[DONE]") break;
|
|
61
|
+
|
|
62
|
+
const chunk = JSON.parse(data);
|
|
63
|
+
if (chunk.error) {
|
|
64
|
+
throw new UsageError(chunk.error.message ?? JSON.stringify(chunk.error));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (options.json) {
|
|
68
|
+
print(chunk);
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
process.stdout.write(chunk.choices?.[0]?.delta?.content ?? "");
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (!options.json) process.stdout.write("\n");
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export default {
|
|
80
|
+
description: "AI-Gateways-specific commands.",
|
|
81
|
+
commands: {
|
|
82
|
+
...crud({ base: "/api/v1/ai-gateways", noun: "AI gateway" }),
|
|
83
|
+
chat
|
|
84
|
+
}
|
|
85
|
+
};
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { writeFile } from "node:fs/promises";
|
|
2
|
+
import { extname } from "node:path";
|
|
3
|
+
import { UsageError } from "../errors.js";
|
|
4
|
+
import { call, fetchData, print } from "../http.js";
|
|
5
|
+
import { base64, dataOption, documentParts, fileOption, payload, readJson, readSource, textDocuments, textOption } from "../input.js";
|
|
6
|
+
|
|
7
|
+
const documentsOptions = {
|
|
8
|
+
file: fileOption("Document file or URL (text, image, PDF...). Repeatable."),
|
|
9
|
+
text: textOption
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const image = {
|
|
13
|
+
description: "Generate images. Prints the image URLs.",
|
|
14
|
+
options: {
|
|
15
|
+
model: { alias: "m", value: "<model>", required: true, description: "Image model. See \"aivax models catalog image\"." },
|
|
16
|
+
prompt: { alias: "p", value: "<text>", list: true, description: "Prompt. Repeatable. Also accepted as positional text." },
|
|
17
|
+
count: { alias: "n", value: "<n>", number: true, description: "Images per prompt, from 1 to 4." },
|
|
18
|
+
reference: { value: "<url>", list: true, description: "HTTP(S) reference image URL. Repeatable." }
|
|
19
|
+
},
|
|
20
|
+
args: "[prompt]",
|
|
21
|
+
async run(ctx) {
|
|
22
|
+
const input = ctx.options.prompt ?? (ctx.args.length ? [ctx.args.join(" ")] : []);
|
|
23
|
+
|
|
24
|
+
if (!input.length) {
|
|
25
|
+
throw new UsageError("Provide a prompt with -p or positional text.");
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const body = { model: ctx.options.model, input, count: ctx.options.count, referenceImages: ctx.options.reference };
|
|
29
|
+
await call(ctx, "POST", "/api/v1/generations/images", { body });
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const speech = {
|
|
34
|
+
aliases: ["tts"],
|
|
35
|
+
description: "Synthesize speech into an audio file.",
|
|
36
|
+
options: {
|
|
37
|
+
model: { alias: "m", value: "<model>", required: true, description: "Speech model. See \"aivax models catalog speech\"." },
|
|
38
|
+
text: { alias: "t", value: "<text>", description: "Text to speak. Use @file or - to read it. Also accepted as positional text." },
|
|
39
|
+
voice: { value: "<voice>", description: "Voice name." },
|
|
40
|
+
format: { value: "<format>", description: "mp3, wav or ogg. Defaults to the output file extension or mp3." },
|
|
41
|
+
output: { alias: "o", value: "<file>", required: true, description: "Audio output file." }
|
|
42
|
+
},
|
|
43
|
+
args: "[text]",
|
|
44
|
+
async run(ctx) {
|
|
45
|
+
const input = ctx.options.text ? await readSource(ctx.options.text) : ctx.args.join(" ");
|
|
46
|
+
|
|
47
|
+
if (!input) {
|
|
48
|
+
throw new UsageError("Provide the text with -t or positional text.");
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const format = ctx.options.format ?? (extname(ctx.options.output).slice(1).toLowerCase() || "mp3");
|
|
52
|
+
const result = await fetchData(ctx, "POST", "/api/v1/generations/speech", {
|
|
53
|
+
body: { model: ctx.options.model, input, voice: ctx.options.voice, format, raw: false }
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const audio = Buffer.from(result.data, "base64");
|
|
57
|
+
await writeFile(ctx.options.output, audio);
|
|
58
|
+
process.stderr.write(`Saved ${audio.length.toLocaleString("en-US")} bytes to ${ctx.options.output}\n`);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const transcribe = {
|
|
63
|
+
aliases: ["stt"],
|
|
64
|
+
description: "Transcribe an audio file. Prints the text.",
|
|
65
|
+
options: {
|
|
66
|
+
file: { alias: "f", value: "<file>", required: true, description: "Audio file: wav, mp3, m4a, flac, ogg, webm or aac." },
|
|
67
|
+
model: { alias: "m", value: "<model>", description: "Speech-to-text model." },
|
|
68
|
+
language: { alias: "l", value: "<code>", description: "Language hint." },
|
|
69
|
+
json: { description: "Print the full API result." }
|
|
70
|
+
},
|
|
71
|
+
async run(ctx) {
|
|
72
|
+
const result = await fetchData(ctx, "POST", "/api/v1/generations/audio/transcriptions", {
|
|
73
|
+
body: {
|
|
74
|
+
model: ctx.options.model,
|
|
75
|
+
language: ctx.options.language,
|
|
76
|
+
input_audio: { data: await base64(ctx.options.file), format: extname(ctx.options.file).slice(1).toLowerCase() }
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
print(ctx.options.json ? result : result.text);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const describe = {
|
|
85
|
+
description: "Describe media (images, audio, video, documents) as text.",
|
|
86
|
+
options: {
|
|
87
|
+
...documentsOptions,
|
|
88
|
+
preset: { value: "<preset>", description: "auto (default) or high." },
|
|
89
|
+
guidance: { alias: "g", value: "<text>", description: "Extraction guidance." }
|
|
90
|
+
},
|
|
91
|
+
async run(ctx) {
|
|
92
|
+
const body = { input: await documentParts(ctx), preset: ctx.options.preset, extractionGuidance: ctx.options.guidance };
|
|
93
|
+
await call(ctx, "POST", "/api/v1/generations/descriptions", { body });
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const summarize = {
|
|
98
|
+
description: "Summarize documents.",
|
|
99
|
+
options: { ...documentsOptions, instructions: { alias: "i", value: "<text>", description: "Format, language, focus or length guidance." } },
|
|
100
|
+
async run(ctx) {
|
|
101
|
+
await call(ctx, "POST", "/api/v1/generations/summarize", { body: { documents: await documentParts(ctx), instructions: ctx.options.instructions } });
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const translate = {
|
|
106
|
+
description: "Translate documents.",
|
|
107
|
+
options: {
|
|
108
|
+
...documentsOptions,
|
|
109
|
+
to: { value: "<language>", required: true, description: "Target language, e.g. pt-BR." },
|
|
110
|
+
from: { value: "<language>", description: "Source language. Detected when omitted." }
|
|
111
|
+
},
|
|
112
|
+
async run(ctx) {
|
|
113
|
+
const body = { documents: await documentParts(ctx), toLanguage: ctx.options.to, fromLanguage: ctx.options.from };
|
|
114
|
+
await call(ctx, "POST", "/api/v1/generations/translate", { body });
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const extract = {
|
|
119
|
+
description: "Extract structured data from documents with a JSON schema.",
|
|
120
|
+
options: {
|
|
121
|
+
...documentsOptions,
|
|
122
|
+
schema: { alias: "s", value: "<json>", required: true, description: "Object JSON schema (JSON, @file or -)." },
|
|
123
|
+
instructions: { alias: "i", value: "<text>", description: "Extraction guidance." }
|
|
124
|
+
},
|
|
125
|
+
async run(ctx) {
|
|
126
|
+
const body = {
|
|
127
|
+
documents: await documentParts(ctx),
|
|
128
|
+
responseSchema: await readJson(ctx.options.schema, "--schema"),
|
|
129
|
+
instructions: ctx.options.instructions
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
await call(ctx, "POST", "/api/v1/generations/extract", { body });
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const textDocumentOptions = {
|
|
137
|
+
file: fileOption("Text file. Each file is one document. Repeatable."),
|
|
138
|
+
document: { alias: "t", value: "<text>", list: true, description: "Inline document. Repeatable." }
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
const classify = {
|
|
142
|
+
description: "Score documents against labels.",
|
|
143
|
+
options: { ...textDocumentOptions, label: { alias: "l", value: "<label>", list: true, required: true, description: "Label. Repeatable." } },
|
|
144
|
+
run: async ctx => call(ctx, "POST", "/api/v1/generations/classify", { body: { documents: await textDocuments(ctx), labels: ctx.options.label } })
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const segment = {
|
|
148
|
+
description: "Split documents into RAG-ready segments.",
|
|
149
|
+
options: { ...textDocumentOptions, sanitize: { description: "Skip segments that are better left out of the RAG (slower)." } },
|
|
150
|
+
run: async ctx => call(ctx, "POST", "/api/v1/generations/segment", { body: { documents: await textDocuments(ctx), sanitize: ctx.options.sanitize } })
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
const rerank = {
|
|
154
|
+
description: "Rank documents by relevance to a query.",
|
|
155
|
+
options: {
|
|
156
|
+
...textDocumentOptions,
|
|
157
|
+
query: { alias: "q", value: "<text>", required: true, description: "Query." },
|
|
158
|
+
model: { alias: "m", value: "<model>", description: "Reranker. See \"aivax models catalog reranker\"." },
|
|
159
|
+
top: { alias: "k", value: "<n>", number: true, description: "Maximum ranked documents." },
|
|
160
|
+
minScore: { value: "<n>", number: true, description: "Minimum relevance score." }
|
|
161
|
+
},
|
|
162
|
+
async run(ctx) {
|
|
163
|
+
const body = {
|
|
164
|
+
documents: await textDocuments(ctx),
|
|
165
|
+
query: ctx.options.query,
|
|
166
|
+
model: ctx.options.model,
|
|
167
|
+
top_n: ctx.options.top,
|
|
168
|
+
min_score: ctx.options.minScore
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
await call(ctx, "POST", "/api/v1/generations/rerank", { body });
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
const decide = {
|
|
176
|
+
description: "Evaluate semantic decisions (noul, choice, score) over a state.",
|
|
177
|
+
options: {
|
|
178
|
+
model: { alias: "m", value: "<model>", description: "Semantic decision model." },
|
|
179
|
+
state: { value: "<json>", description: "JSON state (JSON, @file or -)." },
|
|
180
|
+
questions: { value: "<json>", description: "Questions object (JSON, @file or -)." },
|
|
181
|
+
data: dataOption()
|
|
182
|
+
},
|
|
183
|
+
async run(ctx) {
|
|
184
|
+
const body = await payload(ctx, {
|
|
185
|
+
model: ctx.options.model,
|
|
186
|
+
state: ctx.options.state && await readJson(ctx.options.state, "--state"),
|
|
187
|
+
questions: ctx.options.questions && await readJson(ctx.options.questions, "--questions")
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
await call(ctx, "POST", "/api/v1/generations/decisions", { body });
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
export default {
|
|
195
|
+
description: "Media and text generation commands.",
|
|
196
|
+
commands: { image, speech, transcribe, describe, summarize, translate, extract, classify, segment, rerank, decide }
|
|
197
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { call, fetchData, print } from "../http.js";
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
description: "Account and gateway log commands.",
|
|
5
|
+
commands: {
|
|
6
|
+
account: {
|
|
7
|
+
description: "Show the latest account log entries (errors, warnings and notices).",
|
|
8
|
+
options: { level: { alias: "l", value: "<level>", description: "Only show Information, Warning or Error entries." } },
|
|
9
|
+
async run(ctx) {
|
|
10
|
+
const level = ctx.options.level?.toLowerCase();
|
|
11
|
+
const entries = (await fetchData(ctx, "GET", "/api/v1/information/logs.json"))
|
|
12
|
+
.filter(entry => !level || String(entry.level).toLowerCase().startsWith(level));
|
|
13
|
+
|
|
14
|
+
print(ctx.options.verbose
|
|
15
|
+
? entries
|
|
16
|
+
: entries.map(entry => `${entry.createdAt}\t${entry.level}\t${entry.message}`).join("\n") || "No log entries.");
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
gateway: {
|
|
20
|
+
description: "Show the conversation logs of an AI gateway.",
|
|
21
|
+
options: {
|
|
22
|
+
gateway: { alias: "g", value: "<id>", required: true, description: "AI gateway identifier." },
|
|
23
|
+
minutes: { value: "<n>", number: true, description: "Lookback window in minutes (default 120)." },
|
|
24
|
+
from: { value: "<date>", description: "ISO 8601 start date." },
|
|
25
|
+
to: { value: "<date>", description: "ISO 8601 end date." }
|
|
26
|
+
},
|
|
27
|
+
run: ctx => call(ctx, "GET", "/api/v1/conversations", {
|
|
28
|
+
query: {
|
|
29
|
+
offsetminutes: ctx.options.minutes,
|
|
30
|
+
timeStart: ctx.options.from,
|
|
31
|
+
timeEnd: ctx.options.to,
|
|
32
|
+
filter: `--gateway ${ctx.options.gateway}`
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
},
|
|
36
|
+
batch: {
|
|
37
|
+
description: "Show batch and media-processing job logs.",
|
|
38
|
+
run: ctx => call(ctx, "GET", "/api/v1/compound/logs.json")
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { UsageError } from "../errors.js";
|
|
2
|
+
import { call } from "../http.js";
|
|
3
|
+
|
|
4
|
+
const catalogs = {
|
|
5
|
+
chat: "/api/v1/information/models.json",
|
|
6
|
+
image: "/api/v1/information/image-models.json",
|
|
7
|
+
speech: "/api/v1/information/speech-models.json",
|
|
8
|
+
transcription: "/api/v1/information/audio-transcription-models.json",
|
|
9
|
+
reranker: "/api/v1/information/rerankers-models.json",
|
|
10
|
+
decisions: "/api/v1/information/decisions-models.json",
|
|
11
|
+
embedding: "/api/v1/information/collection-embedding-model.json"
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export default {
|
|
15
|
+
description: "Model catalog commands.",
|
|
16
|
+
commands: {
|
|
17
|
+
list: {
|
|
18
|
+
aliases: ["ls"],
|
|
19
|
+
description: "List the OpenAI-compatible models and AI gateways available to the account.",
|
|
20
|
+
options: { filter: { alias: "q", value: "<name>", description: "Exact model name or dated snapshot." } },
|
|
21
|
+
run: ctx => call(ctx, "GET", "/v1/models", { query: { filter: ctx.options.filter } })
|
|
22
|
+
},
|
|
23
|
+
catalog: {
|
|
24
|
+
description: `Show a detailed catalog with pricing: ${Object.keys(catalogs).join(", ")}.`,
|
|
25
|
+
args: "<type>",
|
|
26
|
+
minArgs: 1,
|
|
27
|
+
run(ctx) {
|
|
28
|
+
const path = catalogs[ctx.args[0]];
|
|
29
|
+
|
|
30
|
+
if (!path) {
|
|
31
|
+
throw new UsageError(`Unknown catalog "${ctx.args[0]}". Use one of: ${Object.keys(catalogs).join(", ")}.`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return call(ctx, "GET", path);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
};
|