index.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import type { AxiosProgressEvent, GenericAbortSignal } from 'axios'
  2. import { post, get } from '@/utils/request'
  3. import { useAuthStore, useSettingStore } from '@/store'
  4. export function fetchChatAPI<T = any>(
  5. prompt: string,
  6. options?: { conversationId?: string; parentMessageId?: string },
  7. signal?: GenericAbortSignal
  8. ) {
  9. return post<T>({
  10. url: '/chat/chat',
  11. data: { prompt, options },
  12. signal
  13. })
  14. }
  15. export function fetchChatConfig<T = any>() {
  16. return post<T>({
  17. url: '/chat/config'
  18. })
  19. }
  20. export function fetchChatAPIProcess<T = any>(params: {
  21. prompt: string
  22. options?: { conversationId?: string; parentMessageId?: string }
  23. signal?: GenericAbortSignal
  24. onDownloadProgress?: (progressEvent: AxiosProgressEvent) => void
  25. }) {
  26. const settingStore = useSettingStore()
  27. const authStore = useAuthStore()
  28. let data: Record<string, any> = {
  29. prompt: params.prompt,
  30. options: params.options
  31. }
  32. if (authStore.isChatGPTAPI) {
  33. data = {
  34. ...data,
  35. systemMessage: settingStore.systemMessage,
  36. temperature: settingStore.temperature,
  37. top_p: settingStore.top_p
  38. }
  39. }
  40. return post<T>({
  41. url: '/chat/chat-process1',
  42. data,
  43. signal: params.signal,
  44. onDownloadProgress: params.onDownloadProgress
  45. })
  46. }
  47. export function fetchSession<T>() {
  48. return post<T>({
  49. url: '/chat/session'
  50. })
  51. }
  52. export function fetchVerify<T>(token: string) {
  53. return post<T>({
  54. url: '/verify',
  55. data: { token }
  56. })
  57. }
  58. export function fetchPhoneLogin<T>(phone: string | number, code: string | number, invitor?: string | number) {
  59. return post<T>({
  60. url: '/auth/phoneLogin',
  61. data: { phone, code, invitor }
  62. })
  63. }
  64. export function fetchMy<T>() {
  65. return get<T>({
  66. url: '/users/my'
  67. })
  68. }
  69. export function fetchSendVerify<T>(data: { phone: string | number; token: string; sig: string; sessionId: string }) {
  70. return post<T>({
  71. url: '/sms/sendVerify',
  72. data
  73. })
  74. }
  75. export function fetchOpenid<T>(code: string) {
  76. return get<T>({
  77. url: '/weixin/code2openid',
  78. data: { code }
  79. })
  80. }
  81. export function fetchJsapiSign<T>(url: string) {
  82. return get<T>({
  83. url: '/weixin/jsapiSign',
  84. data: { url }
  85. })
  86. }
  87. export function fetchPay<T>(openid: string) {
  88. return get<T>({
  89. url: '/weixin/pay',
  90. data: { openid }
  91. })
  92. }