transitive-bullshit / agentic

AI agent stdlib that works with any LLM and TypeScript AI SDK.
https://agentic.so
MIT License
16.26k stars 2.12k forks source link

Openai can success But chatgpt failed #529

Closed ltinerary closed 1 year ago

ltinerary commented 1 year ago

Verify latest release

Verify webapp is working

Environment details

Node: Node.js 18.x

Browser : Microsoft Edge Version 111.0.1661.62

OS: Linux. The Server Running on Vercel

Describe the Bug

My Test Server was deployed on the Vercel.

https://transit-node-gpt.vercel.app/ai: This Interface use openai to request.

And

https://transit-node-gpt.vercel.app/chat: This Interface use chatgpt-api to request.

Both of all are in the same Vercel Server.

But the path of ‘ai’ request success,

The path of 'chat' request fail because 504: GATEWAY_TIMEOUT

You can visit the link above to verify,Thanks!

Code:

import { ChatGPTAPI } from 'chatgpt'
import { Configuration, OpenAIApi } from 'openai'
import express from 'express'
import bodyParser from 'body-parser'
const app = express();
app.use(bodyParser.json())
app.all("*", function (req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "Content-Type");
    res.header("Access-Control-Allow-Methods", "*");
    next();
});

// const { Configuration, OpenAIApi } = require("openai");

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

const api = new ChatGPTAPI({
    apiKey: process.env?.OPENAI_API_KEY || 'a'
})
app.get('/', async (req, res) => {
    res.send(`<h1>🍒Welcome!${Date.now()}</h1>`);
    res.end();
})
app.get('/ai', async (req, res) => {
    const completion = await openai.createCompletion({
        model: "text-davinci-003",
        prompt: `Can you help me write a bubbling sort? use javascript`,
    });
    res.send(completion.data);
    res.end();
})
app.get('/chat', async (req, res) => {
    try {
        const data = await api.sendMessage('Can you help me write a bubbling sort? use javascript', {
            timeoutMs: 2 * 60 * 1000
        })
        res.send(data.text);
        res.end();
    } catch (err) {
        console.log('err',err)
        res.send(err?.message);
        res.end();
    }
})

app.listen(4014, () => {
    console.info(`server start success,port:4012`)
});
ltinerary commented 1 year ago

Maybe I know why this is happening 🥲

c16ff4564c63dc932977671682982de Serverless Functions on Vercel enforce a maximum execution timeout