-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-publish-instruction.js
More file actions
37 lines (31 loc) · 1.28 KB
/
test-publish-instruction.js
File metadata and controls
37 lines (31 loc) · 1.28 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
33
34
35
36
37
const { spawn } = require("child_process");
const grpc = require("@grpc/grpc-js");
const protoLoader = require("@grpc/proto-loader");
const PROTO_PATH = "./ai_network_dag.proto";
// Load the protobuf definition
const packageDefinition = protoLoader.loadSync(PROTO_PATH, {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true,
});
const ainProto = grpc.loadPackageDefinition(packageDefinition).ain;
// Access the correct service definition
const AINetworkMerkleDAGService = ainProto.AINetworkMerkleDAG;
const client = new AINetworkMerkleDAGService("localhost:50051", grpc.credentials.createInsecure());
function runInstruction(instruction) {
try {
client.publish({ topic: 'TRAIN_MNIST', instruction: instruction }, (error, response) => {
if (error) {
console.error(`Error publishing instruction: ${error.message}`);
return;
}
console.log(`Instruction published successfully: ${JSON.stringify(response)}`);
});
} catch (err) {
console.error(`Invalid instruction format: ${err.message}`);
}
}
const instruction = JSON.stringify({ command: "train", container_id: "mnist-train", container_args: { worker_pk: "pksample", data: "cf6a6e9921cd35b4ee39e74df3fedaaa40fab250029b1e1092da70e1c38b57e8" }});
runInstruction(instruction);