Summraize long text using chatgpt and angular

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