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.

85 lines
3.2 KiB

3 years ago
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. }
  11. export class APIConfigRepository implements ConfigRepository {
  12. constructor(
  13. private readonly request = ApiService
  14. ) {}
  15. async list(projectId: string): Promise<ConfigItemList> {
  16. const url = `/projects/${projectId}/auto-labeling-configs`
  17. const response = await this.request.get(url)
  18. const responseItems: ConfigItemResponse[] = response.data
  19. return ConfigItemList.valueOf(
  20. responseItems.map(item => ConfigItem.valueOf(item))
  21. )
  22. }
  23. async create(projectId: string, item: ConfigItem): Promise<ConfigItem> {
  24. const url = `/projects/${projectId}/auto-labeling-configs`
  25. const response = await this.request.post(url, {
  26. model_name: item.modelName,
  27. model_attrs: item.modelAttrs,
  28. template: item.template,
  29. label_mapping: item.labelMapping
  30. })
  31. const responseItem: ConfigItemResponse = response.data
  32. return ConfigItem.valueOf(responseItem)
  33. }
  34. async update(projectId: string, item: ConfigItem): Promise<ConfigItem> {
  35. const url = `/projects/${projectId}/auto-labeling-configs/${item.id}`
  36. const response = await this.request.put(url, {
  37. id: item.id,
  38. model_name: item.modelName,
  39. model_attrs: item.modelAttrs,
  40. template: item.template,
  41. label_mapping: item.labelMapping
  42. })
  43. const responseItem: ConfigItemResponse = response.data
  44. return ConfigItem.valueOf(responseItem)
  45. }
  46. async delete(projectId: string, itemId: number): Promise<void> {
  47. const url = `/projects/${projectId}/auto-labeling-configs/${itemId}`
  48. await this.request.delete(url)
  49. }
  50. async testConfig(projectId: string, item: ConfigItem, text: string): Promise<ConfigTestResponse> {
  51. const url = `/projects/${projectId}/auto-labeling-config-testing`
  52. const response = await this.request.post(url, {config: {...item.toAPI()}, input: text})
  53. const responseItem: ConfigTestResponse = response.data
  54. return responseItem
  55. }
  56. async testParameters(item: ConfigItem, text: string) {
  57. const url = 'auto-labeling-parameter-testing'
  58. const response = await this.request.post(url, {...item.toAPI(), text})
  59. const responseItem: ConfigTestResponse = response.data
  60. return responseItem
  61. }
  62. async testTemplate(projectId: string, response: any, item: ConfigItem): Promise<ConfigTestResponse> {
  63. console.log(projectId)
  64. const url = `/projects/${projectId}/auto-labeling-template-testing`
  65. const _response = await this.request.post(url, { response, ...item.toAPI() })
  66. const responseItem: ConfigTestResponse = _response.data
  67. return responseItem
  68. }
  69. async testMapping(projectId: string, item: ConfigItem, response: any): Promise<ConfigTestResponse> {
  70. const url = `/projects/${projectId}/auto-labeling-mapping-testing`
  71. const _response = await this.request.post(url, {...item.toAPI(), response})
  72. const responseItem: ConfigTestResponse = _response.data
  73. return responseItem
  74. }
  75. }