chat.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // ** api接口部分根据自己项目的情况 自行处理
  2. import instance from './request.js'
  3. let params = {
  4. url: '/ygfGateway/ai-model/api/v1/chat/completions',
  5. bearer: 'fastgpt-bNntk8P36NVMB7kOELLz2J9gftT7hm80XaEgRAwkdSsCt1SCbYAx5h2',
  6. userInfo: {
  7. uid: 'asdfadsfasfd2323',
  8. name: '体验用户'
  9. }
  10. }
  11. /**
  12. * @description: 数据初始化 请在调用组件的created生命周期中调用
  13. * @param {object} options { url, bearer, userInfo }
  14. * @return {*}
  15. */
  16. export function init (options) {
  17. params = { ...params, ...options }
  18. return params
  19. }
  20. // 留一个外置参数 给用户手动进行修改
  21. const chatId = localStorage.getItem('chatId')
  22. /**
  23. * @description fastGPT
  24. * @param {string} message 问题
  25. */
  26. export function fastGPTChat (message) {
  27. return instance({
  28. url: params.url,
  29. method: 'post',
  30. headers: {
  31. 'Content-Type': 'application/json',
  32. 'Authorization': `Bearer ${params.bearer}`
  33. },
  34. data: {
  35. chatId: chatId ? JSON.parse(chatId) : 'abcd',
  36. stream: false,
  37. detail: false,
  38. variables: {
  39. uid: params.userInfo.uid,
  40. name: params.userInfo.name
  41. },
  42. messages: [
  43. {
  44. content: message,
  45. role: 'user'
  46. }
  47. ]
  48. }
  49. })
  50. }