Skip to content

Instantly share code, notes, and snippets.

@mhlgio
Created October 6, 2023 20:13
Show Gist options
  • Select an option

  • Save mhlgio/0e8240ce0e45d3ee3dffc5f514a45c1c to your computer and use it in GitHub Desktop.

Select an option

Save mhlgio/0e8240ce0e45d3ee3dffc5f514a45c1c to your computer and use it in GitHub Desktop.

Revisions

  1. mhlgio created this gist Oct 6, 2023.
    31 changes: 31 additions & 0 deletions index.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    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();
    });
    19 changes: 19 additions & 0 deletions package.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    {
    "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"
    }
    }