Summraize long text using chatgpt and angular

i try to summarize text using chatgpt and angular but all endpoint return with error
and i dont know how to solve that by change many models but also there is no result

Welcome to the forum @oshaa you will need to provide more detail for anyone to be able to help you.

hi lachie
this is my code
async summarizeText(text: string): Promise {
try {
const response = await axios.post(
this.apiUrl,
{
model: ‘text-davinci-003’, // or ‘gpt-3.5-turbo’ if you have access to GPT-3.5
prompt: تلخيص المقال التالي:\n\n${text},
max_tokens: 150,
},
{
headers: {
‘Authorization’: Bearer ${this.chatGptApiKey},
‘Content-Type’: ‘application/json’,
},
}
);
return response.data.choices[0].text.trim();
} catch (error) {
console.error(‘Error summarizing text:’, error);
throw new Error(‘Failed to summarize text.’);
}
}
and this is my model
{
“model”: “gpt-3.5-turbo”,
“prompt”: "تلخيص المقال التالي:\n\n# _ قصة قصيرة # __ حرص ول تخون من السفر الي زوجته بعد طول غياب ً ذات يوم ذهب عادرجل فرحآ مشتاق ، طرق الباب فتحت له ، نظر لها فوجدها تحمل طفل في احشائها و الخر علي كتفها … تبدلت ملمحه و احمرت عيناه و ظل ينظر لها في صمت مندهشآ بعد أن غابت الكلمات من علي لسانه . خرج زوجها الخر من الداخل و قال : ماذا تريد يا رجل ؟ ! فقال الزوج القديم وهو متلعثم : انا اا انا اا ل شئ . خرج من المنزل فاغلق الزوج الجديد خلفه الباب و احتضن زوجته و قبلها . ظل الزوج القديم خارج المنزل منكس الرأس غير مدرك للواقع الجديد ، . ",
“max_tokens”: 150
}
last my endpoint : v1/engines/davinci/completions

and get this error
{
** “error”: {**
** “message”: “The model text-davinci-003 has been deprecated, learn more here: https://platform.openai.com/docs/deprecations”,**
** “type”: “invalid_request_error”,**
** “param”: null,**
** “code”: “model_not_found”**
** }**
} also change error to many types with no solve

The model text-davinci-003 was deprecated on January 4, 2024. Please use gpt-3.5-turbo instead.

I am not very familiar with TypeScript, but since you are getting such an error with the code above, I believe the API key is set up correctly.

Below is an example code that will probably work.

async summarizeText(text: string): Promise<string> {
  try {
    const response = await axios.post(
      this.apiUrl,
      {
        model: 'gpt-3.5-turbo',
        messages: [{ "role": "user", "content": `تلخيص المقال التالي ${text}` }],
        max_tokens: 150,
      },
      {
        headers: {
          'Authorization': `Bearer ${this.chatGptApiKey}`,
          'Content-Type': 'application/json',
        },
      }
    );
    return response.data.choices[0].message.content.trim();
  } catch (error) {
    console.error('Error summarizing text:', error);
    throw new Error('Failed to summarize text.');
  }
}
1 Like

hi i try that and get same error for model
{
“error”: {
“message”: “Cannot specify both model and engine”,
“type”: “invalid_request_error”,
“param”: null,
“code”: null
}
}

i need to know if i need to pay anything to test this code?

Yes, you need to pre-load credits to use the API.

https://platform.openai.com/settings/organization/billing/overview

Additionally, phone verification is required to create an API key. This verification is only needed once at the start and not for subsequent API key generations.

Phone verification is now mandated on platform.openai.com for generating your initial API key, though not for any subsequent API key generation after that.

https://help.openai.com/en/articles/6613520-phone-verification-faq

1 Like

i do that and also error 400