+
80
-

vue3中如何使用axios来直接请求chatgpt官方api接口进行问答?

vue3中如何使用axios来直接请求chatgpt官方api接口进行问答?


网友回复

+
0
-

import {  getCurrentInstance } from 'vue';

const { proxy } = getCurrentInstance()
proxy.$http.post("https://api.openai.com/v1/chat/completions", {
      model: 'gpt-3.5-turbo',
      messages: [
        {
          role: 'user',
          content: "你好",
        },
      ],
      temperature: 0.9,
      max_tokens: 100,
      
    },
    {
      headers: {
        'Content-Type': 'application/json',
        Authorization: `Bearer ${API-KEY}`,
      },
    }).then((response)=>{
        console.log(response.data.choices[0].message.content)
      
  
      
})

前提是你本地能访问chatgpt的api,如何不能直接的话,可以访问镜像或中转站来实现。
我知道答案,我要回答