embedding-studio-cli 0.1.2 → 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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/studio.js +20 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "embedding-studio-cli",
3
- "version": "0.1.2",
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
6
  "studio": "studio.js"
package/studio.js CHANGED
@@ -79,6 +79,20 @@ 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 = { _: [] };
@@ -185,17 +199,17 @@ const COMMANDS = {
185
199
  } else process.stdout.write(buf.toString("utf8"));
186
200
  },
187
201
  "decide": async (argv) => {
188
- const a = parse(argv, { "text": "value", "idempotency-key": "value" });
189
- const text = a.text !== undefined ? a.text : await readStdin();
190
- const body = { text };
202
+ const a = parse(argv, { "text": "value", "file": "value", "simple": "flag",
203
+ "idempotency-key": "value" });
204
+ const body = await recordBody(a);
191
205
  if (a["idempotency-key"]) body.idempotency_key = a["idempotency-key"];
192
206
  say(await call("POST", `/v1/projects/${a._[0]}/decide`, { body }));
193
207
  },
194
208
  "ask": async (argv) => {
195
- const a = parse(argv, { "text": "value", "template": "value", "questions": "value" });
209
+ const a = parse(argv, { "text": "value", "file": "value", "simple": "flag",
210
+ "template": "value", "questions": "value" });
196
211
  if (!a.template === !a.questions) fail("ask needs exactly one of --template or --questions", 2);
197
- const text = a.text !== undefined ? a.text : await readStdin();
198
- const body = { text };
212
+ const body = await recordBody(a);
199
213
  if (a.template) body.template = a.template;
200
214
  else body.questions = JSON.parse(fs.readFileSync(a.questions, "utf8"));
201
215
  say(await call("POST", "/v1/decide", { body }));