npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

nvidia-ai-client

v0.2.7

Published

Cliente TypeScript para la API de NVIDIA AI, facilitando el uso de los modelos de chat, embeddings y generación de imágenes

Downloads

12

Readme

NVIDIA AI Client

Cliente TypeScript para la API de NVIDIA AI, facilitando el uso de los modelos de chat, embeddings y generación de imágenes.

Instalación

npm install nvidia-ai-client

Formas de importación

El paquete es híbrido y soporta tanto CommonJS como ES Modules automáticamente:

CommonJS (Node.js tradicional)

// Importar todo el cliente
const { NvidiaAI } = require('nvidia-ai-client');

// O importar como default
const NvidiaAI = require('nvidia-ai-client').default;

ES Modules (ESM)

// Importar todo el cliente
import { NvidiaAI } from 'nvidia-ai-client';

// O importar como default
import NvidiaAI from 'nvidia-ai-client';

TypeScript

// Importar todo el cliente
import { NvidiaAI } from 'nvidia-ai-client';

// O importar como default
import NvidiaAI from 'nvidia-ai-client';

// También puedes importar tipos específicos
import { NvidiaAI, ChatMessage, EmbeddingResponse } from 'nvidia-ai-client';

Ejemplos de uso

Chat con modelos de IA

const { NvidiaAI } = require('nvidia-ai-client');
require('dotenv').config();

const nvidia = new NvidiaAI({
  apiKey: process.env.NVIDIA_API_KEY
});

async function main() {
  const respuesta = await nvidia.chat.create({
    model: 'mistralai/mistral-7b-instruct-v0.3',
    messages: [
      { role: "system", content: "Eres un asistente útil." },
      { role: "user", content: "¿Qué son las GPUs de NVIDIA?" }
    ],
    temperature: 0.2,
    max_tokens: 300
  });
  
  console.log(respuesta.choices[0].message.content);
}

main();

Generación de imágenes con Stable Diffusion XL

const { NvidiaAI } = require('nvidia-ai-client');
require('dotenv').config();
const fs = require('fs');
const path = require('path');

// Configurar cliente
const nvidia = new NvidiaAI({
  apiKey: process.env.NVIDIA_API_KEY,
  baseURL: 'https://ai.api.nvidia.com/v1'
});

async function main() {
  const respuesta = await nvidia.images.generateWithStableDiffusionXL({
    text_prompts: [
      {
        text: "a magical forest with glowing plants, high detail",
        weight: 1
      }
    ],
    cfg_scale: 7,
    sampler: "DDIM",
    steps: 30
  });
  
  // Guardar imagen
  await nvidia.images.saveImageToFile(
    respuesta.artifacts[0].base64,
    path.join(__dirname, 'magical_forest.png')
  );
}

main();

Generación de embeddings

const { NvidiaAI } = require('nvidia-ai-client');
require('dotenv').config();

const nvidia = new NvidiaAI({
  apiKey: process.env.NVIDIA_API_KEY
});

async function main() {
  const respuesta = await nvidia.embeddings.create({
    model: 'nvidia/nv-embedcode-7b-v1',
    input: ["Las GPUs de NVIDIA son herramientas esenciales para IA."],
    input_type: "query",
    encoding_format: "float",
    truncate: "NONE"
  });
  
  console.log(`Dimensiones del embedding: ${respuesta.data[0].embedding.length}`);
}

main();

Configuración de timeouts

// Configuración global de timeouts antes de crear instancias
const { NvidiaAI } = require('nvidia-ai-client');

// Actualizar configuración global
NvidiaAI.updateConfig({
  DEFAULT_TIMEOUT: 60000,  // 60 segundos por defecto
  CHAT_TIMEOUT: 120000,    // 120 segundos para chat
  EMBEDDINGS_TIMEOUT: 30000 // 30 segundos para embeddings
});

// Crear instancia que usará la configuración anterior
const nvidia = new NvidiaAI({
  apiKey: process.env.NVIDIA_API_KEY
});

Compatibilidad entre sistemas de módulos

Este paquete utiliza la característica "exports" de Node.js para proporcionar una experiencia híbrida:

  • En entornos CommonJS, Node.js cargará automáticamente dist/index.js
  • En entornos ES Modules, Node.js cargará automáticamente dist/index.mjs
  • Los tipos TypeScript siempre estarán disponibles en dist/index.d.ts

No es necesario especificar manualmente qué formato usar: el sistema detectará automáticamente el entorno y utilizará el formato adecuado.

Documentación

Para más detalles, consulta los ejemplos en la carpeta examples/:

  • chat-example.js - Uso de modelos de chat
  • embeddings-example.js - Generación de embeddings
  • stable-diffusion-xl-example.js - Generación de imágenes con SDXL
  • flux-example.js - Generación de imágenes con Flux.1-dev
  • nvidia-complete-example.js - Ejemplo completo con todas las funcionalidades