Thanks to you, I tried your suggestions but doesn't work. Then I came to this solution and this worked for me.
const { OpenAIClient, AzureKeyCredential } = require("@azure/openai");
const generateSummary = async (data) => {
const messages = [
{ role: "user", content: `Provide a summary of the text: ${data}` },
];
try {
const client = new OpenAIClient(endpoint, new AzureKeyCredential(azureApiKey));
const deploymentId = "<YOUR_DEPLOYMENT_NAME>";
const result = await client.getChatCompletions(deploymentId, messages);
for (const choice of result.choices) {
const summary = choice.message.content;
return summary;
}
} catch (err) {
console.error("The sample encountered an error:", err);
}
};