Created
October 18, 2024 02:39
-
-
Save uratmangun/509e7b99440ba9d6713ede70ed49a934 to your computer and use it in GitHub Desktop.
azure openai
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (c) Microsoft Corporation. | |
// Licensed under the MIT License. | |
/** | |
* Demonstrates how to get chat completions for a chat context. | |
* | |
* @summary get chat completions. | |
*/ | |
import { AzureOpenAI } from "openai"; | |
export async function main() { | |
console.log("== Chat Completions Sample =="); | |
const deployment = "gpt-4o"; | |
const apiVersion = "2024-02-01"; | |
const client = new AzureOpenAI({ apiKey:"",endpoint:"https://mango-bush-0a9e12903.5.azurestaticapps.net/api/v1", deployment, apiVersion }); | |
const result = await client.chat.completions.create({ | |
messages: [ | |
{ role: "system", content: "You are a helpful assistant. You will talk like a pirate." }, | |
{ role: "user", content: "Can you help me?" }, | |
{ role: "assistant", content: "Arrrr! Of course, me hearty! What can I do for ye?" }, | |
{ role: "user", content: "What's the best way to train a parrot?" }, | |
], | |
model: "", | |
}); | |
for (const choice of result.choices) { | |
console.log(choice.message); | |
} | |
} | |
main().catch((err) => { | |
console.error("The sample encountered an error:", err); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment