annotation.ts 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import type { Fetcher } from 'swr'
  2. import { del, get, post } from './base'
  3. import type { AnnotationEnableStatus, AnnotationItemBasic, EmbeddingModelConfig } from '@/app/components/app/annotation/type'
  4. import { ANNOTATION_DEFAULT } from '@/config'
  5. export const fetchAnnotationConfig = (appId: string) => {
  6. return get(`apps/${appId}/annotation-setting`)
  7. }
  8. export const updateAnnotationStatus = (appId: string, action: AnnotationEnableStatus, embeddingModel?: EmbeddingModelConfig, score?: number) => {
  9. let body: any = {
  10. score_threshold: score || ANNOTATION_DEFAULT.score_threshold,
  11. }
  12. if (embeddingModel) {
  13. body = {
  14. ...body,
  15. ...embeddingModel,
  16. }
  17. }
  18. return post(`apps/${appId}/annotation-reply/${action}`, {
  19. body,
  20. })
  21. }
  22. export const updateAnnotationScore = (appId: string, settingId: string, score: number) => {
  23. return post(`apps/${appId}/annotation-settings/${settingId}`, {
  24. body: { score_threshold: score },
  25. })
  26. }
  27. export const queryAnnotationJobStatus = (appId: string, action: AnnotationEnableStatus, jobId: string) => {
  28. return get(`apps/${appId}/annotation-reply/${action}/status/${jobId}`)
  29. }
  30. export const fetchAnnotationList = (appId: string, params: Record<string, any>) => {
  31. return get(`apps/${appId}/annotations`, { params })
  32. }
  33. export const fetchExportAnnotationList = (appId: string) => {
  34. return get(`apps/${appId}/annotations/export`)
  35. }
  36. export const addAnnotation = (appId: string, body: AnnotationItemBasic) => {
  37. return post(`apps/${appId}/annotations`, { body })
  38. }
  39. export const annotationBatchImport: Fetcher<{ job_id: string; job_status: string }, { url: string; body: FormData }> = ({ url, body }) => {
  40. return post<{ job_id: string; job_status: string }>(url, { body }, { bodyStringify: false, deleteContentType: true })
  41. }
  42. export const checkAnnotationBatchImportProgress: Fetcher<{ job_id: string; job_status: string }, { jobID: string; appId: string }> = ({ jobID, appId }) => {
  43. return get<{ job_id: string; job_status: string }>(`/apps/${appId}/annotations/batch-import-status/${jobID}`)
  44. }
  45. export const editAnnotation = (appId: string, annotationId: string, body: AnnotationItemBasic) => {
  46. return post(`apps/${appId}/annotations/${annotationId}`, { body })
  47. }
  48. export const delAnnotation = (appId: string, annotationId: string) => {
  49. return del(`apps/${appId}/annotations/${annotationId}`)
  50. }
  51. export const fetchHitHistoryList = (appId: string, annotationId: string, params: Record<string, any>) => {
  52. return get(`apps/${appId}/annotations/${annotationId}/hit-histories`, { params })
  53. }