chat.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import request from '@/utils/request'
  2. /**
  3. * AI对话API - 简化版
  4. *
  5. * 使用 serviceId 替代 configId
  6. * 向后兼容:后端同时支持 serviceId 和 configId
  7. */
  8. // 发送聊天消息(非流式)
  9. export function sendMessage(data) {
  10. return request({
  11. url: '/system/ai/chat/send',
  12. method: 'post',
  13. data: data,
  14. timeout: 60000 // 60秒超时
  15. })
  16. }
  17. // 获取会话历史
  18. export function getHistory(conversationId) {
  19. return request({
  20. url: '/system/ai/chat/history/' + conversationId,
  21. method: 'get'
  22. })
  23. }
  24. // 创建新会话
  25. export function createConversation(data) {
  26. return request({
  27. url: '/system/ai/chat/conversation',
  28. method: 'post',
  29. data: data
  30. })
  31. }
  32. // 获取用户的会话列表
  33. export function getConversations() {
  34. return request({
  35. url: '/system/ai/chat/conversations',
  36. method: 'get'
  37. })
  38. }
  39. // 删除会话
  40. export function deleteConversation(conversationId) {
  41. return request({
  42. url: '/system/ai/chat/conversation/' + conversationId,
  43. method: 'delete'
  44. })
  45. }
  46. // 流式发送消息(SSE)
  47. export function streamMessage(serviceId, message, conversationId) {
  48. const params = new URLSearchParams()
  49. params.append('serviceId', serviceId)
  50. params.append('message', message)
  51. if (conversationId) {
  52. params.append('conversationId', conversationId)
  53. }
  54. return `/system/ai/chat/stream?${params.toString()}`
  55. }