@aivax/cli 1.1.0 → 1.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/README.md +6 -3
- package/package.json +1 -1
- package/src/commands/account.js +4 -0
- package/src/commands/analytics.js +5 -2
- package/src/commands/chat-clients.js +133 -8
- package/src/commands/conversations.js +21 -6
- package/src/commands/gateways.js +12 -2
- package/src/commands/generate.js +107 -10
- package/src/commands/models.js +6 -1
- package/src/http.js +1 -1
- package/src/input.js +15 -0
package/README.md
CHANGED
|
@@ -86,6 +86,9 @@ aivax batch jobs start -w <workflow> -j <job>
|
|
|
86
86
|
aivax batch jobs export -w <workflow> -j <job> -o resultados.jsonl
|
|
87
87
|
aivax generate speech -m <model> -t @roteiro.txt -o narracao.mp3
|
|
88
88
|
aivax conversations list -g <gateway> --minutes 60
|
|
89
|
+
aivax chat-clients talk -k <access-key> "Qual o status do meu pedido?" --stream --reasoning-effort low
|
|
90
|
+
aivax chat-clients talk -k <access-key> "Posso trocar o tamanho?" --context @pedido.txt
|
|
91
|
+
aivax chat-clients sessions insert -c <client> -t <tag> -m '[{"role":"assistant","content":"Seu pedido foi enviado."}]'
|
|
89
92
|
aivax tests evaluate -m checkout-gateway -g @objetivo.txt -c "Valide se o assistente confirma o total" --max-turns 6 -q high
|
|
90
93
|
aivax tests runs get --id <test> --run <run> --stream
|
|
91
94
|
aivax analytics balance
|
|
@@ -129,7 +132,7 @@ PDFs are processed locally: large embedded images are recompressed as JPEG (max
|
|
|
129
132
|
| `docs` | guide, reference, search, setup |
|
|
130
133
|
| `gateways` | list, get, create, patch, delete, chat |
|
|
131
134
|
| `rag` | search, similar, answer, collections (list, get, create, patch, delete, export, reset, reindex, transactions, dedup), documents (list, get, upsert, delete), import |
|
|
132
|
-
| `chat-clients` | list, get, create, patch, delete, sessions, integrations, schedules, talk, session |
|
|
135
|
+
| `chat-clients` | list, get, create, patch, delete, sessions (list, create, insert, delete), integrations (set, delete, rotate-key), schedules, talk, session |
|
|
133
136
|
| `models` | list, catalog |
|
|
134
137
|
| `batch` | workflows (CRUD), jobs (list, get, create, patch, start, pause, finish, delete, export), items (import, list, get, patch, delete, retry) |
|
|
135
138
|
| `tests` | list, get, create, patch, delete, run, runs (list, get, cancel), evaluate |
|
|
@@ -139,8 +142,8 @@ PDFs are processed locally: large embedded images are recompressed as JPEG (max
|
|
|
139
142
|
| `conversations` | list, get, export, delete |
|
|
140
143
|
| `skills` | list, get, create, patch, delete, import, export, clear, teach |
|
|
141
144
|
| `logs` | account, gateway, batch |
|
|
142
|
-
| `account` | update, keys, security, subscription, roll-salt, reset-login-key, notifications |
|
|
143
|
-
| `generate` | image, speech, transcribe, describe, summarize, translate, extract, classify, segment, rerank, decide |
|
|
145
|
+
| `account` | update, keys (list, applications, create, delete), security, subscription, roll-salt, reset-login-key, notifications |
|
|
146
|
+
| `generate` | image, speech, transcribe, describe, summarize, translate, extract, classify, segment, rerank, decide, refine |
|
|
144
147
|
| `shell` | ls, stat, download, upload, publish, mkdir, rm, rmdir |
|
|
145
148
|
| `api` | raw call to any endpoint |
|
|
146
149
|
|
package/package.json
CHANGED
package/src/commands/account.js
CHANGED
|
@@ -13,6 +13,10 @@ const keys = {
|
|
|
13
13
|
description: "List masked API keys and the account salt.",
|
|
14
14
|
run: ctx => call(ctx, "GET", "/api/v1/accounts/api-key")
|
|
15
15
|
},
|
|
16
|
+
applications: {
|
|
17
|
+
description: "List third-party applications authorized through OAuth. Revoke one with \"keys delete --id <id>\".",
|
|
18
|
+
run: ctx => call(ctx, "GET", "/api/v1/accounts/applications")
|
|
19
|
+
},
|
|
16
20
|
create: {
|
|
17
21
|
description: "Create an API key. The key is shown only once.",
|
|
18
22
|
options: {
|
|
@@ -17,9 +17,12 @@ export default {
|
|
|
17
17
|
},
|
|
18
18
|
report: {
|
|
19
19
|
description: "Show the monthly report with top-cost models, resources and SKUs.",
|
|
20
|
-
options: {
|
|
20
|
+
options: {
|
|
21
|
+
month: { alias: "m", value: "<YYYY-MM>", description: "Reporting month. Defaults to the current month." },
|
|
22
|
+
brl: { description: "Include usdBrlRate, the current USD to BRL exchange rate." }
|
|
23
|
+
},
|
|
21
24
|
run: ctx => call(ctx, "GET", "/api/v1/information/usage/monthly-report", {
|
|
22
|
-
query: { month: ctx.options.month ?? new Date().toISOString().slice(0, 7) }
|
|
25
|
+
query: { month: ctx.options.month ?? new Date().toISOString().slice(0, 7), includeBrl: ctx.options.brl }
|
|
23
26
|
})
|
|
24
27
|
},
|
|
25
28
|
resources: {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { UsageError } from "../errors.js";
|
|
2
|
+
import { call, events, print, request, seg } from "../http.js";
|
|
3
|
+
import { dataOption, payload, readContent, readJson, readSource } from "../input.js";
|
|
3
4
|
import { confirm } from "../prompt.js";
|
|
4
5
|
import { crud, filterOption } from "./crud.js";
|
|
5
6
|
|
|
@@ -41,6 +42,37 @@ const sessions = {
|
|
|
41
42
|
await call(ctx, "POST", `${clientPath(ctx)}/sessions`, { body });
|
|
42
43
|
}
|
|
43
44
|
},
|
|
45
|
+
insert: {
|
|
46
|
+
description: "Append messages to a session history without running inference. Fails with 409 while an inference is in progress.",
|
|
47
|
+
options: {
|
|
48
|
+
client,
|
|
49
|
+
session: { alias: "s", value: "<id>", description: "Session identifier. Use this or --tag." },
|
|
50
|
+
tag: { alias: "t", value: "<tag>", description: "Session tag (external user id). Use this or --session." },
|
|
51
|
+
messages: {
|
|
52
|
+
alias: "m",
|
|
53
|
+
value: "<json|text>",
|
|
54
|
+
description: "Plain text (inserted as a user message), an OpenAI-compatible message or an ordered array of user, assistant or tool messages. Use @file or - to read it."
|
|
55
|
+
},
|
|
56
|
+
data: dataOption()
|
|
57
|
+
},
|
|
58
|
+
async run(ctx) {
|
|
59
|
+
const body = await payload(ctx, {
|
|
60
|
+
sessionId: ctx.options.session,
|
|
61
|
+
tag: ctx.options.tag,
|
|
62
|
+
messages: ctx.options.messages && await readContent(ctx.options.messages, "--messages")
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
if ((body.sessionId === undefined) === (body.tag === undefined)) {
|
|
66
|
+
throw new UsageError("Provide exactly one of --session or --tag.");
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (body.messages === undefined) {
|
|
70
|
+
throw new UsageError("Provide the messages to insert with --messages.");
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
await call(ctx, "POST", `${clientPath(ctx)}/sessions/insert-message`, { body });
|
|
74
|
+
}
|
|
75
|
+
},
|
|
44
76
|
delete: {
|
|
45
77
|
aliases: ["rm"],
|
|
46
78
|
description: "Delete a session.",
|
|
@@ -53,6 +85,8 @@ const sessions = {
|
|
|
53
85
|
}
|
|
54
86
|
};
|
|
55
87
|
|
|
88
|
+
const integrationName = { alias: "n", value: "<name>", required: true, description: "Zapi, Telegram, EvolutionApi or Kapso." };
|
|
89
|
+
|
|
56
90
|
const integrations = {
|
|
57
91
|
description: "Messaging integration commands (Zapi, Telegram, EvolutionApi, Kapso).",
|
|
58
92
|
commands: {
|
|
@@ -64,11 +98,19 @@ const integrations = {
|
|
|
64
98
|
delete: {
|
|
65
99
|
aliases: ["rm"],
|
|
66
100
|
description: "Remove an integration.",
|
|
67
|
-
options: { client, name:
|
|
101
|
+
options: { client, name: integrationName },
|
|
68
102
|
async run(ctx) {
|
|
69
103
|
await confirm(ctx, `Remove the ${ctx.options.name} integration?`);
|
|
70
104
|
await call(ctx, "DELETE", `${clientPath(ctx)}/integrations/${seg(ctx.options.name)}`);
|
|
71
105
|
}
|
|
106
|
+
},
|
|
107
|
+
"rotate-key": {
|
|
108
|
+
description: "Generate a new webhook hook key. The current webhook URL stops working immediately: update the URL in the provider and, for Telegram, update the bot hooks.",
|
|
109
|
+
options: { client, name: integrationName },
|
|
110
|
+
async run(ctx) {
|
|
111
|
+
await confirm(ctx, `Rotate the ${ctx.options.name} hook key? The current webhook URL stops working immediately.`);
|
|
112
|
+
await call(ctx, "POST", `${clientPath(ctx)}/integrations/${seg(ctx.options.name)}/hook-key`);
|
|
113
|
+
}
|
|
72
114
|
}
|
|
73
115
|
}
|
|
74
116
|
};
|
|
@@ -104,25 +146,108 @@ const schedules = {
|
|
|
104
146
|
}
|
|
105
147
|
};
|
|
106
148
|
|
|
149
|
+
const renderingModes = ["default", "textual_blocks"];
|
|
150
|
+
|
|
107
151
|
const talk = {
|
|
108
152
|
aliases: ["send"],
|
|
109
153
|
description: "Send a prompt to a public chat session.",
|
|
110
154
|
options: {
|
|
111
155
|
accessKey,
|
|
112
156
|
prompt: { alias: "p", value: "<text>", description: "Message text. Use @file or - to read it. Also accepted as positional text." },
|
|
113
|
-
instructions: { value: "<text>", description: "Extra
|
|
157
|
+
instructions: { value: "<text>", description: "Extra system instructions for this inference only." },
|
|
158
|
+
context: {
|
|
159
|
+
value: "<json|text>",
|
|
160
|
+
description: "Disposable information for this inference only, prepended to the last user message and never saved in the history, not even with commit. Plain text, an OpenAI-compatible content part or an array of them (@file or -). Unlike --instructions, it does not change the system instructions and is meant for information, not instructions."
|
|
161
|
+
},
|
|
114
162
|
noCommit: { description: "Do not save this turn in the session history." },
|
|
163
|
+
stream: { description: "Stream the reply: text is printed as it is generated and tool activity goes to stderr. --verbose prints every event." },
|
|
164
|
+
tools: { value: "<json>", description: "OpenAI-compatible function tools for this inference only (JSON array, @file or -). Their calls are returned for your application to execute." },
|
|
165
|
+
reasoningEffort: { value: "<level>", description: "Reasoning effort for this inference, such as none, low, medium or high." },
|
|
166
|
+
renderingMode: { value: "<mode>", description: `${renderingModes.join(" or ")}. textual_blocks places reasoning and tool activity as text blocks in the reply.` },
|
|
167
|
+
toolExplanations: { description: "Ask the model to explain why it calls each server-side tool." },
|
|
115
168
|
data: dataOption()
|
|
116
169
|
},
|
|
117
170
|
args: "[prompt]",
|
|
118
171
|
async run(ctx) {
|
|
172
|
+
const { options } = ctx;
|
|
173
|
+
|
|
174
|
+
if (options.renderingMode !== undefined && !renderingModes.includes(options.renderingMode)) {
|
|
175
|
+
throw new UsageError(`--rendering-mode must be one of: ${renderingModes.join(", ")}.`);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const tools = options.tools && await readJson(options.tools, "--tools");
|
|
179
|
+
|
|
180
|
+
if (tools !== undefined && !(Array.isArray(tools) && tools.every(tool => typeof tool?.function?.name === "string"))) {
|
|
181
|
+
throw new UsageError("--tools must be a JSON array of OpenAI-compatible function tools, each with function.name.");
|
|
182
|
+
}
|
|
183
|
+
|
|
119
184
|
const body = await payload(ctx, {
|
|
120
|
-
prompt:
|
|
121
|
-
instructions:
|
|
122
|
-
|
|
185
|
+
prompt: options.prompt ? await readSource(options.prompt) : ctx.args.join(" ") || undefined,
|
|
186
|
+
instructions: options.instructions,
|
|
187
|
+
context: options.context && await readContent(options.context, "--context"),
|
|
188
|
+
commit: options.noCommit ? false : undefined,
|
|
189
|
+
stream: options.stream || undefined,
|
|
190
|
+
tools
|
|
123
191
|
});
|
|
124
192
|
|
|
125
|
-
|
|
193
|
+
const inferenceOptions = Object.entries({
|
|
194
|
+
reasoningEffort: options.reasoningEffort,
|
|
195
|
+
renderingMode: options.renderingMode,
|
|
196
|
+
toolInvocationExplanations: options.toolExplanations
|
|
197
|
+
}).filter(([, value]) => value !== undefined);
|
|
198
|
+
|
|
199
|
+
if (inferenceOptions.length) {
|
|
200
|
+
body.inferenceOptions = { ...body.inferenceOptions, ...Object.fromEntries(inferenceOptions) };
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (body.stream !== true) {
|
|
204
|
+
await call(ctx, "POST", `${publicPath(ctx)}/prompt`, { body });
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const response = await request(ctx, "POST", `${publicPath(ctx)}/prompt`, { body, agentOutput: false });
|
|
209
|
+
let result;
|
|
210
|
+
let written = false;
|
|
211
|
+
|
|
212
|
+
for await (const data of events(response)) {
|
|
213
|
+
const { type, data: event = {} } = JSON.parse(data);
|
|
214
|
+
|
|
215
|
+
if (options.verbose) {
|
|
216
|
+
print(data);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (type === "error") {
|
|
220
|
+
if (written) process.stdout.write("\n");
|
|
221
|
+
throw new Error(event.message ?? "The prompt stream failed.");
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if (type === "result") {
|
|
225
|
+
result = event;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (options.verbose) continue;
|
|
229
|
+
|
|
230
|
+
if (type === "text" && event.content) {
|
|
231
|
+
process.stdout.write(`${event.replace && written ? "\n" : ""}${event.content}`);
|
|
232
|
+
written = true;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
if (type === "tool") {
|
|
236
|
+
process.stderr.write(`› ${event.toolName} (${event.update})\n`);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (!result) {
|
|
241
|
+
throw new Error("The prompt stream ended without a result.");
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (options.verbose) return;
|
|
245
|
+
|
|
246
|
+
if (written) process.stdout.write("\n");
|
|
247
|
+
|
|
248
|
+
if (result.toolCalls?.length) {
|
|
249
|
+
print({ toolCalls: result.toolCalls });
|
|
250
|
+
}
|
|
126
251
|
}
|
|
127
252
|
};
|
|
128
253
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { call, seg } from "../http.js";
|
|
1
|
+
import { call, output, request, seg } from "../http.js";
|
|
2
2
|
import { confirm } from "../prompt.js";
|
|
3
3
|
|
|
4
4
|
const id = { value: "<id>", required: true, description: "Conversation identifier." };
|
|
@@ -18,6 +18,9 @@ const exportQuery = ctx => ({
|
|
|
18
18
|
});
|
|
19
19
|
|
|
20
20
|
const filters = {
|
|
21
|
+
id: "--id",
|
|
22
|
+
token: "--token",
|
|
23
|
+
requestId: "--rid",
|
|
21
24
|
model: "--model",
|
|
22
25
|
user: "--user",
|
|
23
26
|
apiKey: "--api-key",
|
|
@@ -31,28 +34,33 @@ export default {
|
|
|
31
34
|
commands: {
|
|
32
35
|
list: {
|
|
33
36
|
aliases: ["ls"],
|
|
34
|
-
description: "List recent conversations.",
|
|
37
|
+
description: "List the most recent conversations of a period, up to 300 without filters or 1,000 with them. Filters apply to the whole period before the limit.",
|
|
35
38
|
options: {
|
|
36
39
|
minutes: { value: "<n>", number: true, description: "Lookback window in minutes (default 120)." },
|
|
37
40
|
from: { value: "<date>", description: "ISO 8601 start date." },
|
|
38
41
|
to: { value: "<date>", description: "ISO 8601 end date." },
|
|
42
|
+
search: { alias: "s", value: "<text>", description: "Free text matched against messages, model, provider, user, conversation ID, token and request ID." },
|
|
43
|
+
id: { alias: "i", value: "<id>", description: "Filter by conversation ID (partial match)." },
|
|
44
|
+
token: { alias: "t", value: "<token>", description: "Filter by conversation token (partial match)." },
|
|
45
|
+
requestId: { alias: "r", value: "<id>", description: "Filter by request ID (partial match)." },
|
|
39
46
|
model: { alias: "m", value: "<model>", description: "Filter by model." },
|
|
40
47
|
user: { alias: "u", value: "<id>", description: "Filter by external user." },
|
|
41
48
|
apiKey: { value: "<id>", description: "Filter by API key." },
|
|
42
49
|
gateway: { alias: "g", value: "<id>", description: "Filter by AI gateway." },
|
|
43
50
|
chatClient: { value: "<id>", description: "Filter by chat client." },
|
|
44
51
|
chatSession: { value: "<id>", description: "Filter by chat session." },
|
|
45
|
-
filter: { value: "<expr>", description: "Raw filter expression, e.g. \"--gateway <id> -u joe\"." }
|
|
52
|
+
filter: { value: "<expr>", description: "Raw filter expression, e.g. \"--gateway <id> -u joe refund\"." }
|
|
46
53
|
},
|
|
47
|
-
run(ctx) {
|
|
54
|
+
async run(ctx) {
|
|
48
55
|
const expression = [
|
|
49
56
|
...Object.entries(filters)
|
|
50
57
|
.filter(([key]) => ctx.options[key])
|
|
51
58
|
.map(([key, flag]) => `${flag} ${JSON.stringify(ctx.options[key])}`),
|
|
52
|
-
ctx.options.filter
|
|
59
|
+
ctx.options.filter,
|
|
60
|
+
ctx.options.search && JSON.stringify(ctx.options.search)
|
|
53
61
|
].filter(Boolean).join(" ");
|
|
54
62
|
|
|
55
|
-
|
|
63
|
+
const response = await request(ctx, "GET", "/api/v1/conversations", {
|
|
56
64
|
query: {
|
|
57
65
|
offsetminutes: ctx.options.minutes,
|
|
58
66
|
timeStart: ctx.options.from,
|
|
@@ -60,6 +68,13 @@ export default {
|
|
|
60
68
|
filter: expression
|
|
61
69
|
}
|
|
62
70
|
});
|
|
71
|
+
const limit = response.headers.get("x-results-truncated");
|
|
72
|
+
|
|
73
|
+
await output(ctx, response);
|
|
74
|
+
|
|
75
|
+
if (limit) {
|
|
76
|
+
process.stderr.write(`Showing the ${limit} most recent conversations. Narrow --from/--to or add filters to see older ones.\n`);
|
|
77
|
+
}
|
|
63
78
|
}
|
|
64
79
|
},
|
|
65
80
|
get: {
|
package/src/commands/gateways.js
CHANGED
|
@@ -17,11 +17,20 @@ const chat = {
|
|
|
17
17
|
reasoningEffort: { value: "<level>", description: "Optional reasoning effort." },
|
|
18
18
|
temperature: { value: "<n>", number: true, description: "Optional sampling temperature." },
|
|
19
19
|
maxTokens: { value: "<n>", number: true, description: "Optional maximum completion tokens." },
|
|
20
|
-
user: { value: "<id>", description: "Optional external user identifier." }
|
|
20
|
+
user: { value: "<id>", description: "Optional external user identifier." },
|
|
21
|
+
conversationToken: {
|
|
22
|
+
value: "<id>",
|
|
23
|
+
description: "Conversation token, up to 128 characters. Send the same value in every request of a conversation to restore server-side tool calls and results and update the same stored conversation."
|
|
24
|
+
}
|
|
21
25
|
},
|
|
22
26
|
args: "[prompt]",
|
|
23
27
|
async run(ctx) {
|
|
24
28
|
const { options } = ctx;
|
|
29
|
+
|
|
30
|
+
if (options.conversationToken?.length > 128) {
|
|
31
|
+
throw new UsageError("--conversation-token must be 128 characters or less.");
|
|
32
|
+
}
|
|
33
|
+
|
|
25
34
|
let messages = options.messages && await readJson(options.messages, "--messages");
|
|
26
35
|
|
|
27
36
|
if (!messages) {
|
|
@@ -45,7 +54,8 @@ const chat = {
|
|
|
45
54
|
reasoning_effort: options.reasoningEffort,
|
|
46
55
|
temperature: options.temperature,
|
|
47
56
|
max_completion_tokens: options.maxTokens,
|
|
48
|
-
user: options.user
|
|
57
|
+
user: options.user,
|
|
58
|
+
conversation_token: options.conversationToken
|
|
49
59
|
};
|
|
50
60
|
|
|
51
61
|
const response = await request(ctx, "POST", "/v1/chat/completions", { body, agentOutput: false });
|
package/src/commands/generate.js
CHANGED
|
@@ -2,7 +2,7 @@ import { writeFile } from "node:fs/promises";
|
|
|
2
2
|
import { extname } from "node:path";
|
|
3
3
|
import { UsageError } from "../errors.js";
|
|
4
4
|
import { call, fetchData, print } from "../http.js";
|
|
5
|
-
import { base64, dataOption, documentParts, fileOption, payload, readJson, readSource, textDocuments, textOption } from "../input.js";
|
|
5
|
+
import { base64, dataOption, dataUrl, documentParts, fileOption, isUrl, openFile, payload, readJson, readSource, textDocuments, textOption } from "../input.js";
|
|
6
6
|
|
|
7
7
|
const documentsOptions = {
|
|
8
8
|
file: fileOption("Document file or URL (text, image, PDF...). Repeatable."),
|
|
@@ -10,12 +10,15 @@ const documentsOptions = {
|
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
const image = {
|
|
13
|
-
description: "Generate images. Prints the image URLs.",
|
|
13
|
+
description: "Generate images. Prints the image URLs and the cost or error of each image.",
|
|
14
14
|
options: {
|
|
15
15
|
model: { alias: "m", value: "<model>", required: true, description: "Image model. See \"aivax models catalog image\"." },
|
|
16
16
|
prompt: { alias: "p", value: "<text>", list: true, description: "Prompt. Repeatable. Also accepted as positional text." },
|
|
17
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)
|
|
18
|
+
reference: { value: "<file|url>", list: true, description: "Reference image: local png, jpg, webp or gif file (up to 8 MB), HTTP(S) URL or data URI. Repeatable." },
|
|
19
|
+
size: { value: "<WxH>", description: "Output size, such as 1024x1024. Each side from 64 to 4096 pixels." },
|
|
20
|
+
format: { value: "<format>", description: "Output format: png, jpeg or webp. Defaults to the model output." },
|
|
21
|
+
quality: { value: "<n>", number: true, description: "Encoding quality from 1 to 100 for jpeg and webp." }
|
|
19
22
|
},
|
|
20
23
|
args: "[prompt]",
|
|
21
24
|
async run(ctx) {
|
|
@@ -25,7 +28,31 @@ const image = {
|
|
|
25
28
|
throw new UsageError("Provide a prompt with -p or positional text.");
|
|
26
29
|
}
|
|
27
30
|
|
|
28
|
-
const
|
|
31
|
+
const referenceImages = ctx.options.reference && await Promise.all(ctx.options.reference.map(async source => {
|
|
32
|
+
if (isUrl(source) || source.startsWith("data:")) {
|
|
33
|
+
return source;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (!/\.(png|jpe?g|webp|gif)$/i.test(source)) {
|
|
37
|
+
throw new UsageError(`Unsupported reference image ${source}. Use a png, jpg, jpeg, webp or gif file.`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if ((await openFile(source)).size > 8 * 1024 * 1024) {
|
|
41
|
+
throw new UsageError(`Reference image ${source} is larger than 8 MB.`);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return await dataUrl(source);
|
|
45
|
+
}));
|
|
46
|
+
|
|
47
|
+
const body = {
|
|
48
|
+
model: ctx.options.model,
|
|
49
|
+
input,
|
|
50
|
+
count: ctx.options.count,
|
|
51
|
+
referenceImages,
|
|
52
|
+
size: ctx.options.size,
|
|
53
|
+
format: ctx.options.format,
|
|
54
|
+
quality: ctx.options.quality
|
|
55
|
+
};
|
|
29
56
|
await call(ctx, "POST", "/api/v1/generations/images", { body });
|
|
30
57
|
}
|
|
31
58
|
};
|
|
@@ -85,11 +112,19 @@ const describe = {
|
|
|
85
112
|
description: "Describe media (images, audio, video, documents) as text.",
|
|
86
113
|
options: {
|
|
87
114
|
...documentsOptions,
|
|
88
|
-
|
|
89
|
-
|
|
115
|
+
imageEngine: { value: "<engine>", description: "InferenceLow (default), InferenceHigh or Ocr." },
|
|
116
|
+
audioEngine: { value: "<engine>", description: "InferenceLow (default), InferenceHigh or Stt." },
|
|
117
|
+
videoEngine: { value: "<engine>", description: "InferenceLow (default) or InferenceHigh." },
|
|
118
|
+
fileEngine: { value: "<engine>", description: "InferenceLow (default), InferenceHigh or Ocr." },
|
|
119
|
+
guidance: { alias: "g", value: "<text>", description: "Extraction guidance. Ignored by Ocr and Stt." }
|
|
90
120
|
},
|
|
91
121
|
async run(ctx) {
|
|
92
|
-
const
|
|
122
|
+
const { imageEngine, audioEngine, videoEngine, fileEngine } = ctx.options;
|
|
123
|
+
const body = {
|
|
124
|
+
input: await documentParts(ctx),
|
|
125
|
+
options: { imageEngine, audioEngine, videoEngine, fileEngine },
|
|
126
|
+
extractionGuidance: ctx.options.guidance
|
|
127
|
+
};
|
|
93
128
|
await call(ctx, "POST", "/api/v1/generations/descriptions", { body });
|
|
94
129
|
}
|
|
95
130
|
};
|
|
@@ -173,25 +208,87 @@ const rerank = {
|
|
|
173
208
|
};
|
|
174
209
|
|
|
175
210
|
const decide = {
|
|
176
|
-
description: "Evaluate semantic decisions (noul, choice, score) over a state.",
|
|
211
|
+
description: "Evaluate semantic decisions (noul, choice, score) over a state or a conversation input.",
|
|
177
212
|
options: {
|
|
178
213
|
model: { alias: "m", value: "<model>", description: "Semantic decision model." },
|
|
179
|
-
state: { value: "<json>", description: "JSON state (JSON, @file or -)." },
|
|
214
|
+
state: { value: "<json>", description: "JSON state (JSON, @file or -). Not combinable with --input." },
|
|
215
|
+
input: { value: "<json>", description: "Array of OpenAI-style messages (JSON, @file or -). Media parts are sent as media. Not combinable with --state." },
|
|
180
216
|
questions: { value: "<json>", description: "Questions object (JSON, @file or -)." },
|
|
181
217
|
data: dataOption()
|
|
182
218
|
},
|
|
183
219
|
async run(ctx) {
|
|
220
|
+
const input = ctx.options.input && await readJson(ctx.options.input, "--input");
|
|
221
|
+
|
|
222
|
+
if (input !== undefined && (!Array.isArray(input) || !input.length)) {
|
|
223
|
+
throw new UsageError("--input must be a non-empty JSON array of messages.");
|
|
224
|
+
}
|
|
225
|
+
|
|
184
226
|
const body = await payload(ctx, {
|
|
185
227
|
model: ctx.options.model,
|
|
186
228
|
state: ctx.options.state && await readJson(ctx.options.state, "--state"),
|
|
229
|
+
input,
|
|
187
230
|
questions: ctx.options.questions && await readJson(ctx.options.questions, "--questions")
|
|
188
231
|
});
|
|
189
232
|
|
|
233
|
+
if (body.input !== undefined && body.state !== undefined) {
|
|
234
|
+
throw new UsageError("Use either input or state, not both.");
|
|
235
|
+
}
|
|
236
|
+
|
|
190
237
|
await call(ctx, "POST", "/api/v1/generations/decisions", { body });
|
|
191
238
|
}
|
|
192
239
|
};
|
|
193
240
|
|
|
241
|
+
const refinementViews = ["micro", "macro"];
|
|
242
|
+
const refinementTypes = ["instruction", "prompt", "skill", "tool", "knowledge", "documentation"];
|
|
243
|
+
|
|
244
|
+
const refine = {
|
|
245
|
+
description: "Review instructions, prompts, skills and tools. Prints a score, findings and suggested fixes.",
|
|
246
|
+
options: {
|
|
247
|
+
view: { value: "<view>", description: `Review depth: ${refinementViews.join(" or ")}. Defaults to micro.` },
|
|
248
|
+
purpose: { value: "<text>", description: "What the context is meant to achieve (text, @file or -)." },
|
|
249
|
+
context: { value: "<json>", description: `Array of { type, title?, description?, content } (JSON, @file or -). Types: ${refinementTypes.join(", ")}.` },
|
|
250
|
+
data: dataOption()
|
|
251
|
+
},
|
|
252
|
+
async run(ctx) {
|
|
253
|
+
const { view, purpose, context } = ctx.options;
|
|
254
|
+
|
|
255
|
+
if (view !== undefined && !refinementViews.includes(view)) {
|
|
256
|
+
throw new UsageError(`--view must be one of: ${refinementViews.join(", ")}.`);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
if (ctx.options.data === undefined && context === undefined) {
|
|
260
|
+
throw new UsageError("Provide --context <json> or --data <json>.");
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const items = context && await readJson(context, "--context");
|
|
264
|
+
|
|
265
|
+
if (items !== undefined) {
|
|
266
|
+
if (!Array.isArray(items) || !items.length) {
|
|
267
|
+
throw new UsageError("--context must be a non-empty JSON array.");
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
items.forEach((item, index) => {
|
|
271
|
+
if (!refinementTypes.includes(item?.type)) {
|
|
272
|
+
throw new UsageError(`--context[${index}].type must be one of: ${refinementTypes.join(", ")}.`);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if (typeof item.content !== "string" || !item.content.trim()) {
|
|
276
|
+
throw new UsageError(`--context[${index}].content must be a non-empty string.`);
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
const body = await payload(ctx, {
|
|
282
|
+
view,
|
|
283
|
+
purpose: purpose && await readSource(purpose),
|
|
284
|
+
context: items
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
await call(ctx, "POST", "/api/v1/generations/instruction-refinement", { body });
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
|
|
194
291
|
export default {
|
|
195
292
|
description: "Media and text generation commands.",
|
|
196
|
-
commands: { image, speech, transcribe, describe, summarize, translate, extract, classify, segment, rerank, decide }
|
|
293
|
+
commands: { image, speech, transcribe, describe, summarize, translate, extract, classify, segment, rerank, decide, refine }
|
|
197
294
|
};
|
package/src/commands/models.js
CHANGED
|
@@ -24,6 +24,7 @@ export default {
|
|
|
24
24
|
description: `Show a detailed catalog with pricing: ${Object.keys(catalogs).join(", ")}.`,
|
|
25
25
|
args: "<type>",
|
|
26
26
|
minArgs: 1,
|
|
27
|
+
options: { name: { alias: "q", value: "<name>", description: "Exact model name or dated snapshot. Only for the chat catalog." } },
|
|
27
28
|
run(ctx) {
|
|
28
29
|
const path = catalogs[ctx.args[0]];
|
|
29
30
|
|
|
@@ -31,7 +32,11 @@ export default {
|
|
|
31
32
|
throw new UsageError(`Unknown catalog "${ctx.args[0]}". Use one of: ${Object.keys(catalogs).join(", ")}.`);
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
|
|
35
|
+
if (ctx.options.name !== undefined && ctx.args[0] !== "chat") {
|
|
36
|
+
throw new UsageError("--name is only supported by the chat catalog.");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return call(ctx, "GET", path, { query: { name: ctx.options.name } });
|
|
35
40
|
}
|
|
36
41
|
}
|
|
37
42
|
}
|
package/src/http.js
CHANGED
|
@@ -4,7 +4,7 @@ import { Agent, fetch as fetchWithoutTimeouts } from "undici";
|
|
|
4
4
|
import { ApiError, UsageError } from "./errors.js";
|
|
5
5
|
import { defaultEndpoint, resolveSession } from "./profiles.js";
|
|
6
6
|
|
|
7
|
-
export const VERSION = "1.
|
|
7
|
+
export const VERSION = "1.2";
|
|
8
8
|
|
|
9
9
|
export const seg = encodeURIComponent;
|
|
10
10
|
|
package/src/input.js
CHANGED
|
@@ -40,6 +40,21 @@ export async function readJson(value, flag = "--data") {
|
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
export async function readContent(value, flag) {
|
|
44
|
+
const text = await readSource(value);
|
|
45
|
+
|
|
46
|
+
if (!/^\s*[[{]/.test(text)) {
|
|
47
|
+
return text;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
return JSON.parse(text);
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
throw new UsageError(`${flag} is not valid JSON: ${error.message}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
43
58
|
export async function payload(ctx, fields = {}) {
|
|
44
59
|
const data = ctx.options.data === undefined ? {} : await readJson(ctx.options.data);
|
|
45
60
|
const defined = Object.fromEntries(Object.entries(fields).filter(([, value]) => value !== undefined));
|