-
-
Save pietheinstrengholt/dff8b87d3520f527015954f24f5ec255 to your computer and use it in GitHub Desktop.
Azure OpenAI demo using azure-sdk-for-js
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
| OPENAI_API_HOST=https://endpointname.openai.azure.com/ | |
| OPENAI_API_KEY=xxxxxxxxxxxxxxxxxxxxxx | |
| AZURE_DEPLOYMENT_ID=text-davinci-003 |
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
| import { OpenAIClient, AzureKeyCredential } from "@azure/openai"; | |
| // Load the .env file if it exists | |
| import * as dotenv from "dotenv"; | |
| dotenv.config(); | |
| // You will need to set these environment variables or edit the following values | |
| const endpoint = process.env["OPENAI_API_HOST"] || "<endpoint>"; | |
| const azureApiKey = process.env["OPENAI_API_KEY"] || "<api key>"; | |
| const deploymentId = process.env["AZURE_DEPLOYMENT_ID"] || "<text-davinci-003>"; | |
| const prompt = ["What is Azure OpenAI?"]; | |
| export async function main() { | |
| const client = new OpenAIClient(endpoint, new AzureKeyCredential(azureApiKey)); | |
| const result = await client.getCompletions(deploymentId, prompt, { maxTokens: 2048 }); | |
| console.log(result.choices[0].text); | |
| } | |
| 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