English 中文(简体)
当你在一只手里有长途电话时,会防止504次停机?
原标题:Ho to prevent 504 timeout when you have a long running api call within an api handler?

在我的“下游”项目中,Im提出了从前线到我一把终点/路线的要求。 最终点使用开放式图书馆<代码>。

它认为,<条码>createChatCompletion的功能太长了,请求是时间性的。

在大约5秒之后,我从<条码>获取以下格奥尔语错误:https://foo.vercel.app/api/ai-chat。

An error occurred with your deployment
FUNCTION_INVOCATION_TIMEOUT

我假设,我会给我一些额外的时间。

前线法典

const response = await fetch( /api/ai-chat , {
  method:  POST ,
  headers: {
     Content-Type :  application/json ,
  },
  body: JSON.stringify({ prompt }),
})

公益物

import { Configuration, OpenAIApi } from  openai 

const configuration = new Configuration({
  apiKey: process.env.OPENAI_API_KEY,
})

const openai = new OpenAIApi(configuration)

export default async function POST({ body: { prompt } }, response) {
  try {
    const res = await openai.createChatCompletion({
      model:  gpt-3.5-turbo ,
      top_p: 0.1,
      n: 1,
      messages: [
        {
          role:  system ,
          content: prompt,
        },
      ],
    })

    return response.json({ suggestion: res.data.choices[0].message.content })
  } catch (error) {
  }
}
问题回答

暂无回答




相关问题
Java RMI - Client Timeout

I m building a Distributed System using Java RMI and it must support a server loss. If my client is connected to a Server using RMI, if this server goes down (cable problems for example), my client ...

PHP Max Execution Time: Incorrect Reporting?

Is there any reason for a PHP script to return a fatal error of: Fatal error: Maximum execution time of 60 seconds exceeded in H:xampplitehtdocsmlm era.php on line 1 When my PHP ini is set to "...

SQL-Server infinite loop

how does sql-server handle infinite loops? Does it detect it or kill the server. EG: WHILE (@number = 3) BEGIN print @number END

Detecting early failure in php fwrite

Earlier today I noticed some calls to php fwrite failing as the destination socket was in a mixed state. There were numerous connections stuck in SYN_SENT and were seemingly not coming back as ...

Multiprocessing Pool inside Process time out

When ever I use the following code the pool result always returns a timeout, is there something logically incorrect I am doing? from multiprocessing import Pool, Process, cpu_count def add(num): ...

Run a program from PowerShell with timeout

I ll write a script that runs a program and wait for it finished. But if the program is not finished within a specified time I want that the program is killed.

open webim ( Mibew Messenger ) time out, reconnecting

i hope you guys know about webim a.k.a mibew messenger. I know only java, jsp and no idea about php except for some basics. Anyways, i ran this app in my apache2.2 local server. Everything works ...

热门标签