packages/tasks-gen/snippets-fixtures/with-access-token/js/openai/0.hf-inference.js (15 lines of code) (raw):

import { OpenAI } from "openai"; const client = new OpenAI({ baseURL: "https://router.huggingface.co/hf-inference/models/meta-llama/Llama-3.1-8B-Instruct/v1", apiKey: "hf_xxx", }); const chatCompletion = await client.chat.completions.create({ model: "meta-llama/Llama-3.1-8B-Instruct", messages: [ { role: "user", content: "What is the capital of France?", }, ], }); console.log(chatCompletion.choices[0].message);