We are getting errors when trying to upload a image_URL to the GPT-4o API

Nikolai Lind 0 Reputation points
2024-07-09T13:34:46.4166667+00:00

We are getting an error while trying to upload an Image with an URL through the GPT4o API. The error we are getting:

Exception from a finished function: TypeError: Cannot read properties of undefined (reading 'stack')

import { AzureKeyCredential, OpenAIClient } from '@azure/openai';

export const openaiPrompt = async (promptText: string, imageUrl: string) => {
  const resource = process.env.RESOURCE_NAME;
  const apiKey = process.env.AZURE_API_KEY || '';
  const endpoint = `https://${resource}.openai.azure.com/`;

  const credential = new AzureKeyCredential(apiKey);
  try {
    const client = new OpenAIClient(endpoint, credential);
    console.log('Prompt azure:', imageUrl);
    const messages = [
      {
        role: 'system',
        content: 'You are a helpful assistant. Help me with my math homework!',
      },
      {
        role: 'user',
        content: {
          type: 'text',
          text: promptText,
        },
      },
      {
        role: 'user',
        content: {
          type: 'image_url',
          image_url: imageUrl,
        },
      },
    ];
    const response = await client.getChatCompletions(
      'its-koral-enrich-v1',
      messages,
      {
        temperature: 1.1,
        topP: 1,
        frequencyPenalty: 0,
        presencePenalty: 0,
      }
    );
    console.log('Response:', response);
    if (response.choices) {
      console.dir(response.choices[0]?.message?.content, { depth: null });
      return response.choices[0]?.message?.content;
    }
  } catch (error) {
    console.error('Error details:', error);
  }
  return '';
};

What is wrong?

Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
3,132 questions
{count} votes

Your answer

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