index.ts 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. import type { AxiosProgressEvent, GenericAbortSignal } from 'axios'
  2. import { post, get, put } 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. console.log(authStore.isChatGPTAPI)
  33. // if (authStore.isChatGPTAPI) {
  34. data = {
  35. ...data,
  36. systemMessage: settingStore.systemMessage,
  37. temperature: settingStore.temperature,
  38. top_p: settingStore.top_p
  39. }
  40. // }
  41. return post<T>({
  42. url: '/chat/chat-process1',
  43. data,
  44. signal: params.signal,
  45. onDownloadProgress: params.onDownloadProgress
  46. })
  47. }
  48. export function fetchSession<T>() {
  49. return post<T>({
  50. url: '/chat/session'
  51. })
  52. }
  53. export function fetchVerify<T>(token: string) {
  54. return post<T>({
  55. url: '/verify',
  56. data: { token }
  57. })
  58. }
  59. export function fetchPhoneLogin<T>(phone: string | number, code: string | number, invitor?: string | number) {
  60. return post<T>({
  61. url: '/auth/phoneLogin',
  62. data: { phone, code, invitor }
  63. })
  64. }
  65. export function fetchMy<T>() {
  66. return get<T>({
  67. url: '/users/my'
  68. })
  69. }
  70. export function fetchSendVerify<T>(data: { phone: string | number; token: string; sig: string; sessionId: string }) {
  71. return post<T>({
  72. url: '/sms/sendVerify',
  73. data
  74. })
  75. }
  76. export function fetchOpenid<T>(code: string) {
  77. return get<T>({
  78. url: '/weixin/code2openid',
  79. data: { code }
  80. })
  81. }
  82. export function fetchJsapiSign<T>(url: string) {
  83. return post<T>({
  84. url: '/weixin/jsapiSign',
  85. data: { url }
  86. })
  87. }
  88. export function fetchPay<T>(openid: string) {
  89. return get<T>({
  90. url: '/weixin/pay',
  91. data: { openid }
  92. })
  93. }
  94. export function fetchRedirectUrl<T>(url: string, state?: string) {
  95. return post<T>({
  96. url: '/weixin/redirectUrl',
  97. data: { url, state }
  98. })
  99. }
  100. export function fetchMyMember<T>() {
  101. return get<T>({
  102. url: '/membership/get'
  103. })
  104. }
  105. export function fetchGetMemberships<T>() {
  106. return get<Array<T>>({
  107. url: '/membership/plans'
  108. })
  109. }
  110. export function fetchMembershipRenew<T>(planId: string | number) {
  111. return post<T>({
  112. url: '/membership/renew',
  113. data: {
  114. planId,
  115. type: 'JSAPI',
  116. openid: window.sessionStorage.getItem('openid')
  117. }
  118. })
  119. }
  120. export function fetchUserBalance<T>() {
  121. return get<T>({
  122. url: '/userBalance/get'
  123. })
  124. }
  125. export function fetchUserBalanceRecords<T>() {
  126. return get<Array<T>>({
  127. url: '/userBalance/records/get'
  128. })
  129. }
  130. export function fetchWithdraw<T>(data: any) {
  131. return post<Array<T>>({
  132. url: '/withdraw/apply',
  133. data: data
  134. })
  135. }
  136. export function fetchCommissionRecords<T>() {
  137. return get<Array<T>>({
  138. url: '/commission/records/get'
  139. })
  140. }
  141. export function fetchSystemMessage<T>() {
  142. return get<T>({
  143. url: '/sys-config/system_message'
  144. })
  145. }
  146. export function fetchMasks<T>(num: number) {
  147. return get<T>({
  148. url: '/admin/mask/getRandom/' + num
  149. })
  150. }
  151. export function fetchGetMask<T>(id: any) {
  152. return get<T>({
  153. url: `/admin/mask/get/${id}`
  154. })
  155. }
  156. export function fetchGetMoments<T>(data: any) {
  157. return post<T>({
  158. url: `/moments`,
  159. data: data
  160. })
  161. }
  162. export function fetchGetMomentsDetail<T>(id: any) {
  163. return get<T>({
  164. url: `/moments/get/${id}`
  165. })
  166. }
  167. export function fetchChatRoles<T>(num: number) {
  168. return get<T>({
  169. url: '/chatRole/getRandom/' + num
  170. })
  171. }
  172. export function fetchGetChatRole<T>(id: any) {
  173. return get<T>({
  174. url: '/chatRole/get/' + id
  175. })
  176. }
  177. export function fetchSendComment<T>(data: any) {
  178. return put<T>({
  179. url: '/comment',
  180. data: data
  181. })
  182. }
  183. export function fetchComments<T>(data: any) {
  184. return post<T>({
  185. url: '/comment',
  186. data: data
  187. })
  188. }