当前位置: 首页 > 知识库问答 >
问题:

javascript - Nextjs连接OPENAI 的API,请求出现错误?是否为网络问题?

韩捷
2024-04-18

Nextjs了一个openai服务,请求发现不走梯子,连接不上,有没有解决方案?

搭了个梯子用openai的api。结果发现nextjs不走梯子。梯子改为全局也不行,用终端代理命令启动服务也不行。有没有朋友知道神木原因?

GET / 200 in 2524ms ✓ Compiled in 237ms (581 modules)RetryError [AI_RetryError]: Failed after 3 attemps. Last error: Cannot connect to API: read ECONNRESET    at _retryWithExponentialBackoff (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:718:13)    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)    at async experimental_generateObject (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:839:30)    at async taskManager (webpack-internal:///(rsc)/./lib/agents/task-manager.tsx:13:20)    at async processEvents (webpack-internal:///(rsc)/./app/action.tsx:55:29) {  reason: 'maxRetriesExceeded',  errors: [    APICallError [AI_APICallError]: Cannot connect to API: read ECONNRESET        at postToApi (webpack-internal:///(rsc)/./node_modules/ai/openai/dist/index.mjs:398:15)        at process.processTicksAndRejections (node:internal/process/task_queues:95:5)        at async OpenAIChatLanguageModel.doGenerate (webpack-internal:///(rsc)/./node_modules/ai/openai/dist/index.mjs:783:22)        at async _retryWithExponentialBackoff (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:706:12)        at async experimental_generateObject (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:839:30)        at async taskManager (webpack-internal:///(rsc)/./lib/agents/task-manager.tsx:13:20)        at async processEvents (webpack-internal:///(rsc)/./app/action.tsx:55:29) {      url: 'https://api.openai.com/v1/chat/completions',      requestBodyValues: [Object],      statusCode: undefined,      responseBody: undefined,      cause: [Error],      isRetryable: true,      data: undefined    },    APICallError [AI_APICallError]: Cannot connect to API: read ECONNRESET        at postToApi (webpack-internal:///(rsc)/./node_modules/ai/openai/dist/index.mjs:398:15)        at process.processTicksAndRejections (node:internal/process/task_queues:95:5)        at async OpenAIChatLanguageModel.doGenerate (webpack-internal:///(rsc)/./node_modules/ai/openai/dist/index.mjs:783:22)        at async _retryWithExponentialBackoff (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:706:12)        at async experimental_generateObject (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:839:30)        at async taskManager (webpack-internal:///(rsc)/./lib/agents/task-manager.tsx:13:20)        at async processEvents (webpack-internal:///(rsc)/./app/action.tsx:55:29) {      url: 'https://api.openai.com/v1/chat/completions',      requestBodyValues: [Object],      statusCode: undefined,      responseBody: undefined,      cause: [Error],      isRetryable: true,      data: undefined    },    APICallError [AI_APICallError]: Cannot connect to API: read ECONNRESET        at postToApi (webpack-internal:///(rsc)/./node_modules/ai/openai/dist/index.mjs:398:15)        at process.processTicksAndRejections (node:internal/process/task_queues:95:5)        at async OpenAIChatLanguageModel.doGenerate (webpack-internal:///(rsc)/./node_modules/ai/openai/dist/index.mjs:783:22)        at async _retryWithExponentialBackoff (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:706:12)        at async experimental_generateObject (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:839:30)        at async taskManager (webpack-internal:///(rsc)/./lib/agents/task-manager.tsx:13:20)        at async processEvents (webpack-internal:///(rsc)/./app/action.tsx:55:29) {      url: 'https://api.openai.com/v1/chat/completions',      requestBodyValues: [Object],      statusCode: undefined,      responseBody: undefined,      cause: [Error],      isRetryable: true,      data: undefined    }  ],  lastError: APICallError [AI_APICallError]: Cannot connect to API: read ECONNRESET      at postToApi (webpack-internal:///(rsc)/./node_modules/ai/openai/dist/index.mjs:398:15)      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)      at async OpenAIChatLanguageModel.doGenerate (webpack-internal:///(rsc)/./node_modules/ai/openai/dist/index.mjs:783:22)      at async _retryWithExponentialBackoff (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:706:12)      at async experimental_generateObject (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:839:30)      at async taskManager (webpack-internal:///(rsc)/./lib/agents/task-manager.tsx:13:20)      at async processEvents (webpack-internal:///(rsc)/./app/action.tsx:55:29) {    url: 'https://api.openai.com/v1/chat/completions',    requestBodyValues: {      model: 'gpt-3.5-turbo',      logit_bias: undefined,      user: undefined,      max_tokens: undefined,      temperature: undefined,      top_p: undefined,      frequency_penalty: undefined,      presence_penalty: undefined,      seed: undefined,      messages: [Array],      tool_choice: [Object],      tools: [Array]    },    statusCode: undefined,    responseBody: undefined,    cause: Error: read ECONNRESET        at TLSWrap.onStreamRead (node:internal/stream_base_commons:217:20)        at TLSWrap.callbackTrampoline (node:internal/async_hooks:130:17) {      errno: -54,      code: 'ECONNRESET',      syscall: 'read'    },    isRetryable: true,    data: undefined  }} ⨯ unhandledRejection: RetryError [AI_RetryError]: Failed after 3 attemps. Last error: Cannot connect to API: read ECONNRESET    at _retryWithExponentialBackoff (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:718:13)    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)    at async experimental_generateObject (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:839:30)    at async taskManager (webpack-internal:///(rsc)/./lib/agents/task-manager.tsx:13:20)    at async processEvents (webpack-internal:///(rsc)/./app/action.tsx:55:29) {  reason: 'maxRetriesExceeded',  errors: [    APICallError [AI_APICallError]: Cannot connect to API: read ECONNRESET        at postToApi (webpack-internal:///(rsc)/./node_modules/ai/openai/dist/index.mjs:398:15)        at process.processTicksAndRejections (node:internal/process/task_queues:95:5)        at async OpenAIChatLanguageModel.doGenerate (webpack-internal:///(rsc)/./node_modules/ai/openai/dist/index.mjs:783:22)        at async _retryWithExponentialBackoff (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:706:12)        at async experimental_generateObject (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:839:30)        at async taskManager (webpack-internal:///(rsc)/./lib/agents/task-manager.tsx:13:20)        at async processEvents (webpack-internal:///(rsc)/./app/action.tsx:55:29) {      url: 'https://api.openai.com/v1/chat/completions',      requestBodyValues: [Object],      statusCode: undefined,      responseBody: undefined,      cause: [Error],      isRetryable: true,      data: undefined    },    APICallError [AI_APICallError]: Cannot connect to API: read ECONNRESET        at postToApi (webpack-internal:///(rsc)/./node_modules/ai/openai/dist/index.mjs:398:15)        at process.processTicksAndRejections (node:internal/process/task_queues:95:5)        at async OpenAIChatLanguageModel.doGenerate (webpack-internal:///(rsc)/./node_modules/ai/openai/dist/index.mjs:783:22)        at async _retryWithExponentialBackoff (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:706:12)        at async experimental_generateObject (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:839:30)        at async taskManager (webpack-internal:///(rsc)/./lib/agents/task-manager.tsx:13:20)        at async processEvents (webpack-internal:///(rsc)/./app/action.tsx:55:29) {      url: 'https://api.openai.com/v1/chat/completions',      requestBodyValues: [Object],      statusCode: undefined,      responseBody: undefined,      cause: [Error],      isRetryable: true,      data: undefined    },    APICallError [AI_APICallError]: Cannot connect to API: read ECONNRESET        at postToApi (webpack-internal:///(rsc)/./node_modules/ai/openai/dist/index.mjs:398:15)        at process.processTicksAndRejections (node:internal/process/task_queues:95:5)        at async OpenAIChatLanguageModel.doGenerate (webpack-internal:///(rsc)/./node_modules/ai/openai/dist/index.mjs:783:22)        at async _retryWithExponentialBackoff (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:706:12)        at async experimental_generateObject (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:839:30)        at async taskManager (webpack-internal:///(rsc)/./lib/agents/task-manager.tsx:13:20)        at async processEvents (webpack-internal:///(rsc)/./app/action.tsx:55:29) {      url: 'https://api.openai.com/v1/chat/completions',      requestBodyValues: [Object],      statusCode: undefined,      responseBody: undefined,      cause: [Error],      isRetryable: true,      data: undefined    }  ],  lastError: APICallError [AI_APICallError]: Cannot connect to API: read ECONNRESET      at postToApi (webpack-internal:///(rsc)/./node_modules/ai/openai/dist/index.mjs:398:15)      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)      at async OpenAIChatLanguageModel.doGenerate (webpack-internal:///(rsc)/./node_modules/ai/openai/dist/index.mjs:783:22)      at async _retryWithExponentialBackoff (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:706:12)      at async experimental_generateObject (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:839:30)      at async taskManager (webpack-internal:///(rsc)/./lib/agents/task-manager.tsx:13:20)      at async processEvents (webpack-internal:///(rsc)/./app/action.tsx:55:29) {    url: 'https://api.openai.com/v1/chat/completions',    requestBodyValues: {      model: 'gpt-3.5-turbo',      logit_bias: undefined,      user: undefined,      max_tokens: undefined,      temperature: undefined,      top_p: undefined,      frequency_penalty: undefined,      presence_penalty: undefined,      seed: undefined,      messages: [Array],      tool_choice: [Object],      tools: [Array]    },    statusCode: undefined,    responseBody: undefined,    cause: Error: read ECONNRESET        at TLSWrap.onStreamRead (node:internal/stream_base_commons:217:20)        at TLSWrap.callbackTrampoline (node:internal/async_hooks:130:17) {      errno: -54,      code: 'ECONNRESET',      syscall: 'read'    },    isRetryable: true,    data: undefined  }} ⨯ unhandledRejection: RetryError [AI_RetryError]: Failed after 3 attemps. Last error: Cannot connect to API: read ECONNRESET    at _retryWithExponentialBackoff (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:718:13)    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)    at async experimental_generateObject (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:839:30)    at async taskManager (webpack-internal:///(rsc)/./lib/agents/task-manager.tsx:13:20)    at async processEvents (webpack-internal:///(rsc)/./app/action.tsx:55:29) {  reason: 'maxRetriesExceeded',  errors: [    APICallError [AI_APICallError]: Cannot connect to API: read ECONNRESET        at postToApi (webpack-internal:///(rsc)/./node_modules/ai/openai/dist/index.mjs:398:15)        at process.processTicksAndRejections (node:internal/process/task_queues:95:5)        at async OpenAIChatLanguageModel.doGenerate (webpack-internal:///(rsc)/./node_modules/ai/openai/dist/index.mjs:783:22)        at async _retryWithExponentialBackoff (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:706:12)        at async experimental_generateObject (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:839:30)        at async taskManager (webpack-internal:///(rsc)/./lib/agents/task-manager.tsx:13:20)        at async processEvents (webpack-internal:///(rsc)/./app/action.tsx:55:29) {      url: 'https://api.openai.com/v1/chat/completions',      requestBodyValues: [Object],      statusCode: undefined,      responseBody: undefined,      cause: [Error],      isRetryable: true,      data: undefined    },    APICallError [AI_APICallError]: Cannot connect to API: read ECONNRESET        at postToApi (webpack-internal:///(rsc)/./node_modules/ai/openai/dist/index.mjs:398:15)        at process.processTicksAndRejections (node:internal/process/task_queues:95:5)        at async OpenAIChatLanguageModel.doGenerate (webpack-internal:///(rsc)/./node_modules/ai/openai/dist/index.mjs:783:22)        at async _retryWithExponentialBackoff (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:706:12)        at async experimental_generateObject (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:839:30)        at async taskManager (webpack-internal:///(rsc)/./lib/agents/task-manager.tsx:13:20)        at async processEvents (webpack-internal:///(rsc)/./app/action.tsx:55:29) {      url: 'https://api.openai.com/v1/chat/completions',      requestBodyValues: [Object],      statusCode: undefined,      responseBody: undefined,      cause: [Error],      isRetryable: true,      data: undefined    },    APICallError [AI_APICallError]: Cannot connect to API: read ECONNRESET        at postToApi (webpack-internal:///(rsc)/./node_modules/ai/openai/dist/index.mjs:398:15)        at process.processTicksAndRejections (node:internal/process/task_queues:95:5)        at async OpenAIChatLanguageModel.doGenerate (webpack-internal:///(rsc)/./node_modules/ai/openai/dist/index.mjs:783:22)        at async _retryWithExponentialBackoff (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:706:12)        at async experimental_generateObject (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:839:30)        at async taskManager (webpack-internal:///(rsc)/./lib/agents/task-manager.tsx:13:20)        at async processEvents (webpack-internal:///(rsc)/./app/action.tsx:55:29) {      url: 'https://api.openai.com/v1/chat/completions',      requestBodyValues: [Object],      statusCode: undefined,      responseBody: undefined,      cause: [Error],      isRetryable: true,      data: undefined    }  ],  lastError: APICallError [AI_APICallError]: Cannot connect to API: read ECONNRESET      at postToApi (webpack-internal:///(rsc)/./node_modules/ai/openai/dist/index.mjs:398:15)      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)      at async OpenAIChatLanguageModel.doGenerate (webpack-internal:///(rsc)/./node_modules/ai/openai/dist/index.mjs:783:22)      at async _retryWithExponentialBackoff (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:706:12)      at async experimental_generateObject (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:839:30)      at async taskManager (webpack-internal:///(rsc)/./lib/agents/task-manager.tsx:13:20)      at async processEvents (webpack-internal:///(rsc)/./app/action.tsx:55:29) {    url: 'https://api.openai.com/v1/chat/completions',    requestBodyValues: {      model: 'gpt-3.5-turbo',      logit_bias: undefined,      user: undefined,      max_tokens: undefined,      temperature: undefined,      top_p: undefined,      frequency_penalty: undefined,      presence_penalty: undefined,      seed: undefined,      messages: [Array],      tool_choice: [Object],      tools: [Array]    },    statusCode: undefined,    responseBody: undefined,    cause: Error: read ECONNRESET        at TLSWrap.onStreamRead (node:internal/stream_base_commons:217:20)        at TLSWrap.callbackTrampoline (node:internal/async_hooks:130:17) {      errno: -54,      code: 'ECONNRESET',      syscall: 'read'    },    isRetryable: true,    data: undefined  }}

共有1个答案

叶卓君
2024-04-18

可以用nginx反代openai的地址,然后nextjs访问nginx的地址,亲测有效。

 类似资料:
  • 我们有很多客户使用我们的应用程序(HR),我们正在使用codenameone构建它,一切都可能正常工作,但今天我们收到了一个客户的问题,其中有一条消息显示包含400错误请求,其他客户正在工作没有任何问题。 该行被赋予400错误请求NetworkManager。getInstance()。addToQueueAndWait(请求) 我们检查了网络监视器并检查了返回json的URL,没有任何问题。 如

  • 我正在尝试从macos上使用swift开发的应用程序连接到realm object server 当我尝试连接时,会出现“网络连接丢失”错误,但我可以从浏览器中毫无问题地打开领域服务器。。顺便说一句,这个问题最近发生了,它在几周前工作正常 这里,用户总是,错误描述是 这发生在本地服务器和一个托管在数字海洋 服务器版本1.8。3. xcode控制台日志 2018-01-15 12:46:07.077

  • ✔加200积分响应期权法 ✔将Access-Control-Allog-Headers,Access-Control-Allog-Methods,Access-Control-Allog-Origin方法响应头添加到OPTIONS ✔将Access-Control-Allow-Headers,Access-Control-Allow-Methods,Access-Control-Allow-Ori

  • 我试图调用一些API在我的javascript代码中获取。我正在我的机器中使用ReactJs开发,并在同一网络中使用另一台机器中的. net开发API。有了邮递员,我可以调用应用编程接口,但是没有。我尝试调用其他服务器中的另一个API,结果是成功的。 我正在使用fetch并尝试使用axios。我在这个API的堆栈溢出中发现了另一个问题:https://gturnquist-quoters.cfap

  • 在做了一些研究后,我发现这是一个CORS问题。我正在使用谷歌应用程序引擎与Python。这个错误是我可以修复的,还是API的bug?我已经设法用这个API做了一个POST请求,没有问题。我已经阅读了很多关于CORS的信息,但还没有找到解决这个问题的方法。 下面是GET请求的Javascript代码,它只是从Trello API复制/粘贴的,所以我不确定哪里出了问题:

  • 我正在使用rest模板调用外部系统,它在本地运行正常,没有任何超时设置,但在我的测试服务器上,它给了我以下错误: “的POST请求时出现I/O错误”https://externalsystem/url“:连接被拒绝:连接;嵌套的异常是java。网ConnectException:连接被拒绝:连接