我试图将开放式信标纳入我的快车道申请,以建立一个聊天室。 然而,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语。