Share via

azurekeycredential is not constructor

中谷 海斗 0 Reputation points
2024-10-17T04:02:04.43+00:00
const { AzureOpenAI } = require("openai");

// Load the .env file if it exists
const dotenv = require("dotenv");
dotenv.config();

// You will need to set these environment variables or edit the following values
const endpoint = process.env["AZURE_OPENAI_ENDPOINT"] || "https://kuraken-openai.openai.azure.com/";
const apiKey = process.env["AZURE_OPENAI_API_KEY"] || "ad9720265b1f4053b7bc2682beacc94e";
const apiVersion = "2023-03-15-preview";
const deployment = "gpt-4"; //This must match your deployment name.
require("dotenv/config");


async function main() {

  const client = new AzureOpenAI({ endpoint, apiKey, apiVersion}); //, deployment 
  console.log(typeof(client));
  const result = await client.streamChat.completions.create({
  

  //  const result = await client.getChatCompletions({
    messages: [
    { role: "system", content: "You are a helpful assistant." },
    { role: "user", content: "Does Azure OpenAI support customer managed keys?" },
    { role: "assistant", content: "Yes, customer managed keys are supported by Azure OpenAI?" },
    { role: "user", content: "Do other Azure AI services support this too?" },
    ],
    model: "gpt-4",
  });


  for (const choice of result.choices) {
    console.log(choice.message);
  }
}

main().catch((err) => {
  console.error("The sample encountered an error:", err);
});

module.exports = { main };



Azure OpenAI in Foundry Models

1 answer

Sort by: Most helpful
  1. navba-MSFT 27,625 Reputation points Microsoft Employee Moderator
    2024-10-17T10:36:46.2233333+00:00

    @中谷 海斗 Welcome to Microsoft Q&A Forum, Thank you for posting your query here! .

    API keys are not recommended for production use because they are less secure than other authentication methods.

    The Azure OpenAI client library for JavaScript beta will be retired on January 14th, 2025. More info here.

    .

    Please migrate to the stable OpenAI SDK for JavaScript using the migration guide and use the sample mentioned there.

    . Please let me know if you have any follow-up queries. I would be happy to help.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.