-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrequest.mjs
39 lines (32 loc) · 1.17 KB
/
request.mjs
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
33
34
35
36
37
38
39
// Usage: node ./request.mjs
import "dotenv/config";
import { inspect } from "util";
import { setupOracle, allowIfRequired } from "./common/index.mjs";
async function main() {
const oracle = await setupOracle();
await allowIfRequired(oracle);
// make a request
console.log("Preparing request");
const input = process.argv[2];
if (!input) {
throw new Error("Provide an input.");
}
const model = "*";
const requestObj = await oracle.request(input, model, {
taskParameters: { difficulty: 2, numGenerations: 1, numValidations: 1 },
});
console.log("Making a request:", requestObj);
const taskId = await oracle.waitRequest(requestObj.txHash);
console.log(`Waiting for completions on task: ${taskId}`);
await oracle.wait(taskId);
console.log("Best result:");
const response = await oracle.read(taskId);
console.log(response);
console.log("Validations:");
const validations = await oracle.getValidations(taskId);
for (const validationRaw of validations) {
const validation = await oracle.processValidation(validationRaw);
console.log(inspect(validation, { showHidden: true, depth: null, colors: true }));
}
}
main().catch(console.error);