-
Notifications
You must be signed in to change notification settings - Fork 0
/
example-datasets.ts
38 lines (31 loc) · 1.2 KB
/
example-datasets.ts
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
// Run example with "npx ts-node ./examples/example-datasets.ts"
import "dotenv/config";
import Client from "../src";
// Your API key will be loaded from the environment variable OPPER_API_KEY if not provided
const client = new Client();
(async () => {
// Ensure the function exists
await client.call({
name: "node-sdk/datasets",
input: "what is the capital of sweden",
});
// Get the function
const fn = await client.functions.get({ name: "node-sdk/datasets" });
// Or get the dataset for a given function directly
// const dataset = await client.functions.dataset({ name: "node-sdk/datasets" });
// Get the dataset for the function
const dataset = await fn.dataset();
// Add an entry to the dataset
const entry = await dataset.add({
input: "Hello, world!",
output: "Hello, world!",
expected: "Hello, world!",
});
console.log("Entry added: ", entry);
// Get all entries from the dataset
const entries = await dataset.getEntries();
console.log("Entries: ", entries);
// Delete an entry from the dataset
const deleted = await dataset.deleteEntry(entry.uuid);
console.log("Entry deleted: ", deleted);
})();