English 中文(简体)
不能在快递使用开放式信标时读出未定错误的特性。 j)
原标题:Cannot read properties of undefined error when using OpenAI API in Express.js

我试图将开放式信标纳入我的快车道申请,以建立一个聊天室。 然而,Im遇到一个错误,即“TypeError:当我向聊天线发出要求时,Cannot读到未经界定(翻新造物)的财产”。 我对我的守则和APIC钥匙进行了双重检查,但我看不出造成这一问题的原因。

在此,我服务器中的相关代码。 js file:

// ... (express and bodyParser imports)

const openai = require( openai ); // I ve also tried  const { OpenAIApi } = require( openai ); 

const app = express();
const port = process.env.PORT || 3000;
const apiKey =  MyApiKEy ; // My actual OpenAI API key

app.use(express.static( public ));
app.use(bodyParser.json());

// GET route for /chat
app.get( /chat , (req, res) => {
  res.send( This is the chat page. You can use it for testing or debugging. );
});

// POST route for /chat
app.post( /chat , async (req, res) => {
    const { message } = req.body;
    
    // Use OpenAI API to generate a response
    try {
        const response = await openai.completions.create({
            engine:  text-davinci-002 ,
            prompt: message,
            max_tokens: 50,
        });

        const chatbotResponse = response.choices[0].text;

        res.json({ chatbotResponse });
    } catch (error) {
        console.error( Error: , error);
        res.status(500).json({ error:  An error occurred while fetching the response from the chatbot.  });
    }
});

app.listen(port, () => {
    console.log(`Server is running on port ${port}`);
});

我也提到了我的聊天界面前端部分的超文本和Java语。

问题回答

我也存在同样的问题,而是利用这一工具解决了这一问题:

const completion = await openai.createCompletion({ model: text-davinci-002 , prompt: "what is the temperature in Los Angeles?", max_tokens: 50});





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签