chart.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import {
  2. http,
  3. Method
  4. } from '@/utils/request.js';
  5. // 使用storage模块的方法设置登录状态为false
  6. import storage from "@/utils/storage.js";
  7. import api from "@/config/api.js";
  8. const request = http.request;
  9. /**
  10. * 上传用户头像和昵称
  11. * @param params
  12. */
  13. export function chartStream(params) {
  14. return http.request({
  15. url: "dify/chart/stream",
  16. method: Method.POST,
  17. // needToken: true,
  18. data:params,
  19. });
  20. }
  21. // 发送流式AI聊天请求(返回fetch Promise)
  22. export function postChatMessageData(data) {
  23. console.log("JSON.stringify(data)",JSON.stringify(data));
  24. const baseUrl =api.serve || '';
  25. const url = `${baseUrl}/uniapp/dify/chat/stream`;
  26. return fetch(url, {
  27. method: 'POST',
  28. headers: {
  29. 'Content-Type': 'application/json',
  30. 'Accept': 'text/event-stream',
  31. 'Authorization': `Bearer ${storage.getAccessToken()}`
  32. },
  33. body: JSON.stringify(data),
  34. credentials: 'include', // 确保发送凭证(cookie等)
  35. mode: 'cors' // 允许跨域请求
  36. });
  37. }
  38. // 终止流式请求
  39. export function stopChatStream(data) {
  40. return request({
  41. url: '/uniapp/dify/chat/stop',
  42. method: 'post',
  43. data: data
  44. })
  45. }
  46. // 获取下一轮建议问题列表
  47. export function chatStreamSuggested(data) {
  48. return http.request({
  49. url: '/uniapp/dify/chat/suggested',
  50. method: 'get',
  51. params: data
  52. })
  53. }