Created
October 6, 2023 20:13
-
-
Save mhaligowski/0e8240ce0e45d3ee3dffc5f514a45c1c to your computer and use it in GitHub Desktop.
ESM example with @gradientai/nodejs-sdk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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 <[email protected]>", | |
"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