0 0 0

如果你在本地测试环境开发,你需要看看这个

夏天玩Chat
2023-3-7 910

1.第一步是打开一个梯子,让你的电脑连接到国际互联网。

2.安装axios

3.使用axios向openai发送post请求,最重要的是,在请求中指定你的梯子。

const axios = require('axios');

const itRealyFuckedMe= async (input) => {
    try {
        let data = {
            model: "gpt-3.5-turbo",
            messages: [
                { "role": "user", "content": input }
            ]
        };

        let config = {
            method: 'post',
            maxBodyLength: Infinity,
            url: 'https://api.openai.com/v1/chat/completions',
            headers: {
                'Content-Type': 'application/json',
                'Authorization': `Bearer ${openAIKeys}`
            },
            data: data,
            proxy: {
            /*
            It depends on your real proxy configuration,
            Open your proxy client and view the configuration information.
            */
                host: "127.0.0.1",
                port: 7890,
                protocol: "http"
            }
        };
        let completion = await axios(config)
            .then((response) => {
                console.log("response.data:", JSON.stringify(response.data));
                return response.data.choices[0].message
            })
            .catch((error) => {
                console.log(error);
            });
      
        return completion
    } catch (error) {
        console.log(error);
    }
};
AD:GPT-4官方账号:点击购买

请先登录后发表评论!

最新回复 (0)

    暂无评论

返回
请先登录后发表评论!