You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.8 KiB

3 years ago
3 years ago
3 years ago
  1. import ApiService from '@/services/api.service'
  2. import { ConfigRepository, ConfigTestResponse } from '~/domain/models/autoLabeling/configRepository'
  3. import { ConfigItemList, ConfigItem } from '~/domain/models/autoLabeling/config'
  4. export interface ConfigItemResponse {
  5. id: number,
  6. model_name: string,
  7. model_attrs: object,
  8. template: string,
  9. label_mapping: object,
  10. task_type: string,
  11. }
  12. export class APIConfigRepository implements ConfigRepository {
  13. constructor(
  14. private readonly request = ApiService
  15. ) {}
  16. async list(projectId: string): Promise<ConfigItemList> {
  17. const url = `/projects/${projectId}/auto-labeling/configs`
  18. const response = await this.request.get(url)
  19. const responseItems: ConfigItemResponse[] = response.data
  20. return ConfigItemList.valueOf(
  21. responseItems.map(item => ConfigItem.valueOf(item))
  22. )
  23. }
  24. async create(projectId: string, item: ConfigItem): Promise<ConfigItem> {
  25. const url = `/projects/${projectId}/auto-labeling/configs`
  26. const response = await this.request.post(url, item.toAPI())
  27. const responseItem: ConfigItemResponse = response.data
  28. return ConfigItem.valueOf(responseItem)
  29. }
  30. async update(projectId: string, item: ConfigItem): Promise<ConfigItem> {
  31. const url = `/projects/${projectId}/auto-labeling/configs/${item.id}`
  32. const response = await this.request.put(url, {
  33. id: item.id,
  34. model_name: item.modelName,
  35. model_attrs: item.modelAttrs,
  36. template: item.template,
  37. label_mapping: item.labelMapping
  38. })
  39. const responseItem: ConfigItemResponse = response.data
  40. return ConfigItem.valueOf(responseItem)
  41. }
  42. async delete(projectId: string, itemId: number): Promise<void> {
  43. const url = `/projects/${projectId}/auto-labeling/configs/${itemId}`
  44. await this.request.delete(url)
  45. }
  46. async testParameters(projectId: string, item: ConfigItem, text: string) {
  47. const url = `/projects/${projectId}/auto-labeling/request-testing`
  48. const response = await this.request.post(url, {...item.toAPI(), text})
  49. const responseItem: ConfigTestResponse = response.data
  50. return responseItem
  51. }
  52. async testTemplate(projectId: string, response: any, item: ConfigItem): Promise<ConfigTestResponse> {
  53. console.log(projectId)
  54. const url = `/projects/${projectId}/auto-labeling/label-extractor-testing`
  55. const _response = await this.request.post(url, { response, ...item.toAPI() })
  56. const responseItem: ConfigTestResponse = _response.data
  57. return responseItem
  58. }
  59. async testMapping(projectId: string, item: ConfigItem, response: any): Promise<ConfigTestResponse> {
  60. const url = `/projects/${projectId}/auto-labeling/label-mapper-testing`
  61. const _response = await this.request.post(url, {...item.toAPI(), response})
  62. const responseItem: ConfigTestResponse = _response.data
  63. return responseItem
  64. }
  65. }