Browse Source

Change the url of auto labeling APIs

pull/1650/head
Hironsan 3 years ago
parent
commit
8dbf84d719
6 changed files with 27 additions and 24 deletions
  1. 11
      backend/auto_labeling/tests/test_views.py
  2. 18
      backend/auto_labeling/urls.py
  3. 2
      backend/auto_labeling/views.py
  4. 2
      frontend/domain/models/tasks/annotationRepository.ts
  5. 14
      frontend/repositories/autoLabeling/config/apiConfigRepository.ts
  6. 4
      frontend/repositories/autoLabeling/template/apiTemplateRepository.ts

11
backend/auto_labeling/tests/test_views.py

@ -150,7 +150,7 @@ class TestConfigCreation(CRUDMixin):
self.assertEqual(len(response.data), 1)
class TestAutomatedCategoryLabeling(CRUDMixin):
class TestAutomatedLabeling(CRUDMixin):
def setUp(self):
self.project = prepare_project(task=DOCUMENT_CLASSIFICATION, single_class_classification=False)
@ -162,7 +162,8 @@ class TestAutomatedCategoryLabeling(CRUDMixin):
'CategoryType', project=self.project.item, text='NEG'
)
self.loc = mommy.make('SpanType', project=self.project.item, text='LOC')
self.url = reverse(viewname='automated_labeling', args=[self.project.item.id, self.example.id])
self.url = reverse(viewname='auto_labeling', args=[self.project.item.id])
self.url += f'?example={self.example.id}'
@patch('auto_labeling.views.execute_pipeline', return_value=Categories([{'label': 'POS'}]))
def test_category_labeling(self, mock):
@ -226,7 +227,8 @@ class TestAutomatedSpanLabeling(CRUDMixin):
self.project = prepare_project(task=SEQUENCE_LABELING)
self.example = make_doc(self.project.item)
self.loc = mommy.make('SpanType', project=self.project.item, text='LOC')
self.url = reverse(viewname='automated_labeling', args=[self.project.item.id, self.example.id])
self.url = reverse(viewname='auto_labeling', args=[self.project.item.id])
self.url += f'?example={self.example.id}'
@patch(
'auto_labeling.views.execute_pipeline',
@ -247,7 +249,8 @@ class TestAutomatedTextLabeling(CRUDMixin):
def setUp(self):
self.project = prepare_project(task=SEQ2SEQ)
self.example = make_doc(self.project.item)
self.url = reverse(viewname='automated_labeling', args=[self.project.item.id, self.example.id])
self.url = reverse(viewname='auto_labeling', args=[self.project.item.id])
self.url += f'?example={self.example.id}'
@patch(
'auto_labeling.views.execute_pipeline',

18
backend/auto_labeling/urls.py

@ -6,43 +6,43 @@ from .views import (ConfigDetail, AutomatedLabeling,
urlpatterns = [
path(
route='auto-labeling-templates',
route='auto-labeling/templates',
view=TemplateListAPI.as_view(),
name='auto_labeling_templates'
),
path(
route='auto-labeling-templates/<str:option_name>',
route='auto-labeling/templates/<str:option_name>',
view=TemplateDetailAPI.as_view(),
name='auto_labeling_template'
),
path(
route='auto-labeling-configs',
route='auto-labeling/configs',
view=ConfigList.as_view(),
name='auto_labeling_configs'
),
path(
route='auto-labeling-configs/<int:config_id>',
route='auto-labeling/configs/<int:config_id>',
view=ConfigDetail.as_view(),
name='auto_labeling_config'
),
path(
route='auto-labeling-parameter-testing',
route='auto-labeling/request-testing',
view=RestAPIRequestTesting.as_view(),
name='auto_labeling_parameter_testing'
),
path(
route='auto-labeling-template-testing',
route='auto-labeling/label-extractor-testing',
view=LabelExtractorTesting.as_view(),
name='auto_labeling_template_test'
),
path(
route='auto-labeling-mapping-testing',
route='auto-labeling/label-mapper-testing',
view=LabelMapperTesting.as_view(),
name='auto_labeling_mapping_test'
),
path(
route='examples/<int:example_id>/auto-labeling',
route='auto-labeling',
view=AutomatedLabeling.as_view(),
name='automated_labeling'
name='auto_labeling'
),
]

2
backend/auto_labeling/views.py

@ -148,7 +148,7 @@ class AutomatedLabeling(generics.CreateAPIView):
def create(self, request, *args, **kwargs):
project = get_object_or_404(Project, pk=self.kwargs['project_id'])
example = get_object_or_404(Example, pk=self.kwargs['example_id'])
example = project.examples.get(pk=self.request.query_params['example'])
configs = AutoLabelingConfig.objects.filter(project=project)
# Todo: make async calls or celery tasks to reduce waiting time.
for config in configs:

2
frontend/domain/models/tasks/annotationRepository.ts

@ -31,7 +31,7 @@ export abstract class AnnotationRepository<T extends AnnotationModel> {
}
public async autoLabel(projectId: string, docId: number): Promise<void> {
const url = `/projects/${projectId}/examples/${docId}/auto-labeling`
const url = `/projects/${projectId}/auto-labeling?example=${docId}`
await this.request.post(url, {})
}

14
frontend/repositories/autoLabeling/config/apiConfigRepository.ts

@ -17,7 +17,7 @@ export class APIConfigRepository implements ConfigRepository {
) {}
async list(projectId: string): Promise<ConfigItemList> {
const url = `/projects/${projectId}/auto-labeling-configs`
const url = `/projects/${projectId}/auto-labeling/configs`
const response = await this.request.get(url)
const responseItems: ConfigItemResponse[] = response.data
return ConfigItemList.valueOf(
@ -26,14 +26,14 @@ export class APIConfigRepository implements ConfigRepository {
}
async create(projectId: string, item: ConfigItem): Promise<ConfigItem> {
const url = `/projects/${projectId}/auto-labeling-configs`
const url = `/projects/${projectId}/auto-labeling/configs`
const response = await this.request.post(url, item.toAPI())
const responseItem: ConfigItemResponse = response.data
return ConfigItem.valueOf(responseItem)
}
async update(projectId: string, item: ConfigItem): Promise<ConfigItem> {
const url = `/projects/${projectId}/auto-labeling-configs/${item.id}`
const url = `/projects/${projectId}/auto-labeling/configs/${item.id}`
const response = await this.request.put(url, {
id: item.id,
model_name: item.modelName,
@ -46,12 +46,12 @@ export class APIConfigRepository implements ConfigRepository {
}
async delete(projectId: string, itemId: number): Promise<void> {
const url = `/projects/${projectId}/auto-labeling-configs/${itemId}`
const url = `/projects/${projectId}/auto-labeling/configs/${itemId}`
await this.request.delete(url)
}
async testParameters(projectId: string, item: ConfigItem, text: string) {
const url = `/projects/${projectId}/auto-labeling-parameter-testing`
const url = `/projects/${projectId}/auto-labeling/request-testing`
const response = await this.request.post(url, {...item.toAPI(), text})
const responseItem: ConfigTestResponse = response.data
return responseItem
@ -59,14 +59,14 @@ export class APIConfigRepository implements ConfigRepository {
async testTemplate(projectId: string, response: any, item: ConfigItem): Promise<ConfigTestResponse> {
console.log(projectId)
const url = `/projects/${projectId}/auto-labeling-template-testing`
const url = `/projects/${projectId}/auto-labeling/label-extractor-testing`
const _response = await this.request.post(url, { response, ...item.toAPI() })
const responseItem: ConfigTestResponse = _response.data
return responseItem
}
async testMapping(projectId: string, item: ConfigItem, response: any): Promise<ConfigTestResponse> {
const url = `/projects/${projectId}/auto-labeling-mapping-testing`
const url = `/projects/${projectId}/auto-labeling/label-mapper-testing`
const _response = await this.request.post(url, {...item.toAPI(), response})
const responseItem: ConfigTestResponse = _response.data
return responseItem

4
frontend/repositories/autoLabeling/template/apiTemplateRepository.ts

@ -8,14 +8,14 @@ export class APITemplateRepository implements TemplateRepository {
) {}
async list(projectId: string, taskName: string): Promise<string[]> {
const url = `/projects/${projectId}/auto-labeling-templates?task_name=${taskName}`
const url = `/projects/${projectId}/auto-labeling/templates?task_name=${taskName}`
const response = await this.request.get(url)
const responseItems: string[] = response.data
return responseItems
}
async find(projectId: string, optionName: string): Promise<ConfigTemplateItem> {
const url = `/projects/${projectId}/auto-labeling-templates/${optionName}`
const url = `/projects/${projectId}/auto-labeling/templates/${optionName}`
const response = await this.request.get(url)
const responseItem: ConfigResponse = response.data
return ConfigTemplateItem.valueOf(responseItem)

Loading…
Cancel
Save