Skip to content

Instantly share code, notes, and snippets.

@mhaligowski
Created October 6, 2023 20:13
Show Gist options
  • Save mhaligowski/0e8240ce0e45d3ee3dffc5f514a45c1c to your computer and use it in GitHub Desktop.
Save mhaligowski/0e8240ce0e45d3ee3dffc5f514a45c1c to your computer and use it in GitHub Desktop.
ESM example with @gradientai/nodejs-sdk
import ora from "ora";
import { Gradient } from "@gradientai/nodejs-sdk";
const spinner = ora("").start();
async function run() {
spinner.start("Creating a new Gradient client");
const gradient = new Gradient({});
spinner.stopAndPersist({
text: "Gradient client created successfully",
symbol: "✅",
});
spinner.start("Obtaining a list of models");
const models = await gradient.listModels({ onlyBase: false });
spinner.stopAndPersist({
symbol: "✅",
text: "Models obtained successfully",
});
for (const model of models) {
const name = model.baseModelId === undefined ? model.slug : model.name;
console.log(name);
}
}
run()
.catch(console.error)
.finally(() => {
spinner.stop();
});
{
"name": "hello-gradient-on-esm",
"version": "1.0.0",
"description": "Testing ESM modules for GradientAI SDK",
"exports": "./index.js",
"scripts": {
"test": "node ./index.js",
},
"type": "module",
"author": "Mateusz Haligowski <matehal@gradient.ai>",
"license": "ISC",
"dependencies": {
"@gradientai/nodejs-sdk": "^1.1.1",
"ora": "^7.0.1"
},
"engines": {
"node": ">=16"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment