import cloud from ‘@lafjs/cloud’
export async function main(ctx: FunctionContext) {
const { ChatGPTAPI } = await import(‘chatgpt’)
const api = new ChatGPTAPI({ apiKey: cloud.env.CHAT_GPT_API_KEY })
let res = await api.sendMessage(‘怎么游览长城’)
console.log(res)
return res.text
}
RequestID: 8437f999-e75e-4af6-8ef0-59581727c10b
[2023-04-18 08:23:53]
‘fetch failed’ ‘TypeError: fetch failed\n’ +
‘ at Object.fetch (node:internal/deps/undici/undici:11413:11)\n’ +
‘ at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n’ +
‘ at async Promise.then.promptTokens (file:///app/node_modules/chatgpt/build/index.js:298:25)’