0

I tried below code and getting error, I am simply trying API to generate some question based on topic given. How can I do that?

Like if I define a topic of Games, I want to generate two questions for that:

{
    code: 'OperationNotSupported',
    message: 'The completion operation does not work with the specified model, gpt-35-turbo. Please choose different model and try again. You can learn more about which models can be used with each operation here: https://go.microsoft.com/fwlink/?linkid=2197993.'
}

Code

const { OpenAIClient, AzureKeyCredential } = require("@azure/openai");

(async function main() {
  const endpoint = "https://profileforslack.openai.azure.com/";
  const key = "";
  const client = new OpenAIClient(endpoint, new AzureKeyCredential(key));

  const textToSummarize = `
    Two independent experiments reported their results this morning at CERN, Europe's high-energy physics laboratory near Geneva in Switzerland. Both show convincing evidence of a new boson particle weighing around 125 gigaelectronvolts, which so far fits predictions of the Higgs previously made by theoretical physicists.

    ""As a layman I would say: 'I think we have it'. Would you agree?"" Rolf-Dieter Heuer, CERN's director-general, asked the packed auditorium. The physicists assembled there burst into applause.
  :`;

  const summarizationPrompt = [
    `
    Summarize the following text.

    Text:
    """"""
    ${textToSummarize}
    """"""

    Summary:
  `,
  ];

  console.log(`Input: ${summarizationPrompt}`);

  const deploymentName = "gpt";
  try {
    const { choices } = await client.getCompletions(
      deploymentName,
      summarizationPrompt
    );
    const completion = choices[0].text;
    console.log(`Summarization: ${completion}`);
  } catch (err) {
    console.log(err);
  }
})();
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
sahil
  • 13
  • 3

1 Answers1

0

use a model supported by Azure Open AI. https://learn.microsoft.com/en-us/azure/ai-services/openai/concepts/models

  • gpt-35-turbo
  • gpt-35-turbo-16k
  • gpt-4
  • gpt-4-32k

You may be trying to use the Completions api rather than the Chat Completions api.

https://www.educative.io/answers/openai-api-error-not-supported-in-the-v1-completions-endpoint

take this example: https://learn.microsoft.com/en-us/azure/ai-services/openai/chatgpt-quickstart?tabs=command-line&pivots=programming-language-javascript#create-a-sample-application

const textToSummarize = `
    Two independent experiments reported their results this morning at CERN, Europe's high-energy physics laboratory near Geneva in Switzerland. Both show convincing evidence of a new boson particle weighing around 125 gigaelectronvolts, which so far fits predictions of the Higgs previously made by theoretical physicists.

    ""As a layman I would say: 'I think we have it'. Would you agree?"" Rolf-Dieter Heuer, CERN's director-general, asked the packed auditorium. The physicists assembled there burst into applause.
  :`;

  const summarizationPrompt = [
    {
    "user": "system",
    "content": `
    Summarize the following text.

    Text:
    """"""
    ${textToSummarize}
    """"""

    Summary:
  `,
  }];

  console.log(`Input: ${summarizationPrompt}`);

const deploymentName = "gpt-35-turbo";
try {
 const { choices } = await client.getChatCompletions(
      deploymentName,
      summarizationPrompt
    );
    const completion = choices[0].message;
    console.log(`Summarization: ${completion}`);
  } catch (err) {
    console.log(err);
  }
}
Jeremy Fiel
  • 140
  • 10
  • My model is `gpt-35-turbo` this `gpt` just alias name for deployment – sahil Sep 01 '23 at 18:29
  • you will also find backticks (string interpolation) is not supported in JSON objects, so you need to embedded your `textToSummarize` inside the `content` node as a regular string. – Jeremy Fiel Sep 01 '23 at 18:41