This repo contains a "hello world" example demonstrating the how to prompt a machine learning model hosted by Replicate via node.js. This example is for the Programming from A to Z class at ITP, NYU. (Students in the class, contact me for your API key!)
import Replicate from 'replicate';
import * as dotenv from 'dotenv';
dotenv.config();
const replicate = new Replicate({
auth: process.env.REPLICATE_API_TOKEN,
});
const version = '8e6975e5ed6174911a6ff3d60540dfd4844201974602551e10e9e87ab143d81e';
const model = 'meta/llama-2-7b-chat';
go();
async function go() {
const input = {
prompt: 'Help me with a thesis idea.',
system_prompt: 'You are a student at ITP, Tisch School of the Arts, NYU.',
};
const output = await replicate.run(`${model}:${version}`, { input });
console.log(output.join('').trim());
}
Replicate is a platform for running machine learning models in the cloud from your own code. Browse models.
For detailed usage, setup, and more, here is the official Replicate Documentation for Node.js.