import OpenAI from "openai";const client = new OpenAI({ baseURL: "https://api.sambanova.ai/v1", apiKey: "<YOUR API KEY>",});const chatCompletion = await client.chat.completions.create({ messages: [ { role: "system", content: "Answer the question in a couple sentences." }, { role: "user", content: "Share a happy story with me" }, ], model: "Meta-Llama-3.1-405B-Instruct",});console.log(chatCompletion.choices[0].message.content);
"<YOUR API KEY>"の部分を、実際のAPIキーに置き換えてください。その後、ターミナルウィンドウで以下のコマンドを使用して、ファイルを実行します。
Copy
node hello-world.js
実行すると、以下のような出力が表示されます。
Copy
Here’s a happy story: One day, a little girl named Sophie found a lost puppy in her neighborhood and decided to take it home to care for it. As she nursed the puppy back to health, she named it Max and the two became inseparable best friends, going on adventures and playing together every day.