// ** api接口部分根据自己项目的情况 自行处理

import instance from './request.js'

let params = {
  url: '/ygfGateway/ai-model/api/v1/chat/completions',
  bearer: 'fastgpt-bNntk8P36NVMB7kOELLz2J9gftT7hm80XaEgRAwkdSsCt1SCbYAx5h2',
  userInfo: {
    uid: 'asdfadsfasfd2323',
    name: '体验用户'
  }
}
/**
 * @description: 数据初始化 请在调用组件的created生命周期中调用
 * @param {object} options { url, bearer, userInfo }
 * @return {*}
 */
export function init (options) {
  params = { ...params, ...options }
  return params
}

// 留一个外置参数 给用户手动进行修改
const chatId = localStorage.getItem('chatId')
/**
 * @description fastGPT
 * @param {string} message 问题
 */
export function fastGPTChat (message) {
  return instance({
    url: params.url,
    method: 'post',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${params.bearer}`
    },
    data: {
      chatId: chatId ? JSON.parse(chatId) : 'abcd',
      stream: false,
      detail: false,
      variables: {
        uid: params.userInfo.uid,
        name: params.userInfo.name
      },
      messages: [
        {
          content: message,
          role: 'user'
        }
      ]
    }
  })
}
