由于 url 错误,将 Open Ai 视觉引入 react native 应用程序的问题

Issues with Open Ai vision into react native application due to url error

提问人:ojandali 提问时间:11/16/2023 更新时间:11/16/2023 访问量:22

问:

我有一个react native应用程序。我希望此应用程序允许用户上传图像。选择并上传图片后,该图片将发布到 firebase 并获取可下载的公共链接。

然后,我想将可下载图像的此链接传递给 Open Ai 的视觉 api。一旦它被传递给 OpenAi,我希望它扫描图像并回答有关图像的问题。

我已经尝试了一切,但我不确定发生了什么。

这是我拥有的代码:

import OpenAI from 'openai';
import {OPEN_AI_API_KEY} from '../../Utils/Authentication';
import {uploadNewImage} from '../../Utils/Firebase';

const openai = new OpenAI({apiKey: OPEN_AI_API_KEY});
console.log(openai);

...

const performOCR = () => {
    const fileName = 'receipt-' + Math.floor(Math.random() * 100000000 + 1);
    uploadNewImage(preprocessedImage, fileName)
      .then(downloadableUrl => {
        console.log('received downloadable url');
        if (downloadableUrl) {
          console.log(downloadableUrl);
          scanImage(downloadableUrl);
        }
      })
      .catch(error => {
        console.error(error);
      });
  };

async function scanImage(downloadableUrl: string) {
    const response = await openai.chat.completions.create({
      model: 'gpt-4-vision-preview',
      messages: [
        {
          role: 'user',
          content: [
            {
              type: 'text',
              text: 'Scan the image of the receipt and extract the business information. Then itemize all of the items that were ordered?',
            },
            {
              type: 'image_url',
              image_url: {
                url: downloadableUrl,
              },
            },
          ],
        },
      ],
    });
    console.log(response.choices[0]);
  }

因此,在该过程的某个时候,它会不断抛出有关我的 url 失败的错误。我在网上查看并向聊天 gpt 寻求帮助,但一无所获。

以下是完整的错误区域:

 LOG  https://firebasestorage.googleapis.com/v0/b/ioweyou-9d178.appspot.com/o/ProfilePictures%2Freceipt-27195586?alt=media&token=a4320778-e64e-4325-a236-460bb7d9e3c1
 WARN  Possible Unhandled Promise Rejection (id: 0):
Error: 404 Invalid URL (POST /v1/chat/completions/)
Error: 404 Invalid URL (POST /v1/chat/completions/)
    at construct (native)
    at Wrapper (http://192.168.86.62:8081/node_modules/expo/AppEntry.bundle//&platform=ios&dev=true&hot=false&lazy=true:26976:64)
    at construct (native)
    at _createSuperInternal (http://192.168.86.62:8081/node_modules/expo/AppEntry.bundle//&platform=ios&dev=true&hot=false&lazy=true:219299:406)
    at apply (native)
    at OpenAIError (http://192.168.86.62:8081/node_modules/expo/AppEntry.bundle//&platform=ios&dev=true&hot=false&lazy=true:219310:26)
    at construct (native)
    at _createSuperInternal (http://192.168.86.62:8081/node_modules/expo/AppEntry.bundle//&platform=ios&dev=true&hot=false&lazy=true:219299:406)
    at call (native)
    at APIError (http://192.168.86.62:8081/node_modules/expo/AppEntry.bundle//&platform=ios&dev=true&hot=false&lazy=true:219321:27)
    at construct (native)
    at _createSuperInternal (http://192.168.86.62:8081/node_modules/expo/AppEntry.bundle//&platform=ios&dev=true&hot=false&lazy=true:219299:406)
    at apply (native)
    at NotFoundError (http://192.168.86.62:8081/node_modules/expo/AppEntry.bundle//&platform=ios&dev=true&hot=false&lazy=true:219477:29)
    at generate (http://192.168.86.62:8081/node_modules/expo/AppEntry.bundle//&platform=ios&dev=true&hot=false&lazy=true:219365:35)
    at makeStatusError (http://192.168.86.62:8081/node_modules/expo/AppEntry.bundle//&platform=ios&dev=true&hot=false&lazy=true:217534:79)
    at ?anon_0_ (http://192.168.86.62:8081/node_modules/expo/AppEntry.bundle//&platform=ios&dev=true&hot=false&lazy=true:217592:43)
    at next (native)
    at asyncGeneratorStep (http://192.168.86.62:8081/node_modules/expo/AppEntry.bundle//&platform=ios&dev=true&hot=false&lazy=true:28227:26)
    at _next (http://192.168.86.62:8081/node_modules/expo/AppEntry.bundle//&platform=ios&dev=true&hot=false&lazy=true:28246:29)
    at tryCallOne (/private/var/folders/yw/6bx918xn4671rggfcdxz7fph0000gn/T/hermes/build_iphonesimulator/lib/InternalBytecode/InternalBytecode.js:53:16)
    at anonymous (/private/var/folders/yw/6bx918xn4671rggfcdxz7fph0000gn/T/hermes/build_iphonesimulator/lib/InternalBytecode/InternalBytecode.js:139:27)
    at apply (native)
    at anonymous (http://192.168.86.62:8081/node_modules/expo/AppEntry.bundle//&platform=ios&dev=true&hot=false&lazy=true:34858:26)
    at _callTimer (http://192.168.86.62:8081/node_modules/expo/AppEntry.bundle//&platform=ios&dev=true&hot=false&lazy=true:34737:17)
    at _callReactNativeMicrotasksPass (http://192.168.86.62:8081/node_modules/expo/AppEntry.bundle//&platform=ios&dev=true&hot=false&lazy=true:34782:17)
    at callReactNativeMicrotasks (http://192.168.86.62:8081/node_modules/expo/AppEntry.bundle//&platform=ios&dev=true&hot=false&lazy=true:34988:44)
    at __callReactNativeMicrotasks (http://192.168.86.62:8081/node_modules/expo/AppEntry.bundle//&platform=ios&dev=true&hot=false&lazy=true:3623:46)
    at anonymous (http://192.168.86.62:8081/node_modules/expo/AppEntry.bundle//&platform=ios&dev=true&hot=false&lazy=true:3397:45)
    at __guard (http://192.168.86.62:8081/node_modules/expo/AppEntry.bundle//&platform=ios&dev=true&hot=false&lazy=true:3596:15)
    at flushedQueue (http://192.168.86.62:8081/node_modules/expo/AppEntry.bundle//&platform=ios&dev=true&hot=false&lazy=true:3396:21)
javascript reactjs react-native openai-api chatgpt-api

评论


答: 暂无答案