embedding-studio-cli 0.1.0 → 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/package.json +2 -2
- package/studio.js +30 -3
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "embedding-studio-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "The Embedding Studio API from a terminal: push labelled data, fit and calibrate, place the review band, decide, and download the calibration file. JSON out, non-zero exit on refusal.",
|
|
5
5
|
"bin": {
|
|
6
|
-
"studio": "
|
|
6
|
+
"studio": "studio.js"
|
|
7
7
|
},
|
|
8
8
|
"files": [
|
|
9
9
|
"studio.js"
|
package/studio.js
CHANGED
|
@@ -79,11 +79,29 @@ function readStdin() {
|
|
|
79
79
|
});
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
+
/* The record, whichever way it arrived: --file sends the bytes (an image, recording or clip; the
|
|
83
|
+
* server sniffs what they are, so there is no --type flag to get wrong), --text or stdin the
|
|
84
|
+
* words. --simple asks for plain values back: {answers: {qid: value}, route, confidence}. */
|
|
85
|
+
async function recordBody(a) {
|
|
86
|
+
const body = {};
|
|
87
|
+
if (a.file !== undefined) {
|
|
88
|
+
body.input = { data: fs.readFileSync(a.file).toString("base64") };
|
|
89
|
+
} else {
|
|
90
|
+
body.text = a.text !== undefined ? a.text : await readStdin();
|
|
91
|
+
}
|
|
92
|
+
if (a.simple) body.simple = true;
|
|
93
|
+
return body;
|
|
94
|
+
}
|
|
95
|
+
|
|
82
96
|
/* ---- a small flag parser: --name value, --flag, and positionals, nothing cleverer ---- */
|
|
83
97
|
function parse(argv, spec) {
|
|
84
98
|
const out = { _: [] };
|
|
85
99
|
for (let i = 0; i < argv.length; i++) {
|
|
86
100
|
const a = argv[i];
|
|
101
|
+
if (a === "-o") { /* the one short flag argparse gives the Python side */
|
|
102
|
+
out.o = argv[++i];
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
87
105
|
if (a.startsWith("--")) {
|
|
88
106
|
const name = a.slice(2);
|
|
89
107
|
if (!(name in spec)) fail(`unknown flag --${name}`, 2);
|
|
@@ -181,12 +199,21 @@ const COMMANDS = {
|
|
|
181
199
|
} else process.stdout.write(buf.toString("utf8"));
|
|
182
200
|
},
|
|
183
201
|
"decide": async (argv) => {
|
|
184
|
-
const a = parse(argv, { "text": "value", "
|
|
185
|
-
|
|
186
|
-
const body =
|
|
202
|
+
const a = parse(argv, { "text": "value", "file": "value", "simple": "flag",
|
|
203
|
+
"idempotency-key": "value" });
|
|
204
|
+
const body = await recordBody(a);
|
|
187
205
|
if (a["idempotency-key"]) body.idempotency_key = a["idempotency-key"];
|
|
188
206
|
say(await call("POST", `/v1/projects/${a._[0]}/decide`, { body }));
|
|
189
207
|
},
|
|
208
|
+
"ask": async (argv) => {
|
|
209
|
+
const a = parse(argv, { "text": "value", "file": "value", "simple": "flag",
|
|
210
|
+
"template": "value", "questions": "value" });
|
|
211
|
+
if (!a.template === !a.questions) fail("ask needs exactly one of --template or --questions", 2);
|
|
212
|
+
const body = await recordBody(a);
|
|
213
|
+
if (a.template) body.template = a.template;
|
|
214
|
+
else body.questions = JSON.parse(fs.readFileSync(a.questions, "utf8"));
|
|
215
|
+
say(await call("POST", "/v1/decide", { body }));
|
|
216
|
+
},
|
|
190
217
|
"decisions": async (argv) =>
|
|
191
218
|
say(await call("GET", `/v1/projects/${parse(argv, {})._[0]}/decisions`)),
|
|
192
219
|
"audit": async (argv) => say(await call("GET", `/v1/projects/${parse(argv, {})._[0]}/audit`)),
|