-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathask.mjs
More file actions
32 lines (26 loc) · 1.07 KB
/
Copy pathask.mjs
File metadata and controls
32 lines (26 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**
* Visual Q&A — up to 5 questions about one file, priced like a single extraction.
*
* node examples/ask.mjs photo.jpg "Is there a dog in the image?" "How many people?"
*/
import { VisionAPI } from '@devrobotlabs/visionapi';
const [path, ...questions] = process.argv.slice(2);
if (!path) {
console.error('usage: node examples/ask.mjs <file> [question…]');
process.exit(1);
}
const vision = new VisionAPI();
const res = await vision.ask({
file: path,
questions: questions.length ? questions : ['What is in this image?'],
});
for (const a of res.answers) {
// `verdict` is the machine-readable half: 'yes' | 'no' | 'uncertain' | 'n/a'.
// 'uncertain' is a yes/no question the image does not settle — a real answer, not a
// failure. 'n/a' means it wasn't a yes/no question in the first place.
console.log(`Q: ${a.question}`);
console.log(`A: ${a.answer}`);
console.log(` verdict=${a.verdict} confidence=${a.confidence}\n`);
}
console.log(`${res.credits_used} credit(s) — the questions themselves are free, ` +
`you pay per image or per selected page.`);