Browse Source

Show response on testing config

pull/1206/head
Hironsan 4 years ago
parent
commit
7c880c40cd
4 changed files with 32 additions and 6 deletions
  1. 9
      app/api/exceptions.py
  2. 6
      app/api/views.py
  3. 21
      frontend/components/containers/settings/ConfigCreationForm.vue
  4. 2
      frontend/repositories/config/interface.ts

9
app/api/exceptions.py

@ -1,5 +1,5 @@
from rest_framework import status
from rest_framework.exceptions import APIException, PermissionDenied, NotFound, ValidationError
from rest_framework.exceptions import APIException, PermissionDenied, ValidationError
class FileParseException(APIException):
@ -22,9 +22,14 @@ class AutoLabeliingPermissionDenied(PermissionDenied):
'Please ask the project administrators to add you.'
class URLConnectionError(NotFound):
class URLConnectionError(ValidationError):
default_detail = 'Failed to establish a connection. Please check the URL or network.'
class AWSTokenError(ValidationError):
default_detail = 'The security token included in the request is invalid.'
class SampleDataException(ValidationError):
default_detail = 'The response is empty. Maybe the sample data is not appropriate.' \
'Please specify another sample data which returns at least one label.'

6
app/api/views.py

@ -27,7 +27,7 @@ from rest_framework.views import APIView
from rest_framework.parsers import MultiPartParser
from rest_framework_csv.renderers import CSVRenderer
from .exceptions import AutoLabelingException, AutoLabeliingPermissionDenied, URLConnectionError, AWSTokenError
from .exceptions import AutoLabelingException, AutoLabeliingPermissionDenied, URLConnectionError, AWSTokenError, SampleDataException
from .filters import DocumentFilter
from .models import Project, Label, Document, RoleMapping, Role, Comment, AutoLabelingConfig
from .permissions import IsProjectAdmin, IsAnnotatorAndReadOnly, IsAnnotator, IsAnnotationApproverAndReadOnly, IsOwnAnnotation, IsAnnotationApprover, IsOwnComment
@ -539,6 +539,8 @@ class AutoLabelingConfigTest(APIView):
try:
output = self.pass_config_validation()
output = self.pass_pipeline_call(output)
if not output:
raise SampleDataException()
return Response(
data={'valid': True, 'labels': output},
status=status.HTTP_200_OK
@ -547,6 +549,8 @@ class AutoLabelingConfigTest(APIView):
raise URLConnectionError()
except botocore.exceptions.ClientError:
raise AWSTokenError()
except ValidationError as e:
raise e
except Exception as e:
raise e

21
frontend/components/containers/settings/ConfigCreationForm.vue

@ -100,6 +100,20 @@
outlined
label="Sample Text"
/>
<h4
v-if="response.length > 0"
class="text-h6"
>
Response
</h4>
<v-sheet
v-if="response.length > 0"
:dark="!$vuetify.theme.dark"
:light="$vuetify.theme.dark"
class="mb-5 pa-5"
>
<pre>{{ JSON.stringify(response, null, 4) }}</pre>
</v-sheet>
<v-alert
v-for="(error, index) in errors"
prominent
@ -183,7 +197,8 @@ export default Vue.extend({
templateName: null,
templateConfig: {},
templateNames: [] as string[],
labelMapping: []
labelMapping: [],
response: [] as object[]
}
},
@ -245,13 +260,15 @@ export default Vue.extend({
const projectId = this.$route.params.id
const item = this.createConfig()
this.isLoading = true
this.errors = []
this.response = []
this.configService.testConfig(projectId, item, this.sampleText)
.then(value => {
this.passTesting = value.valid
this.response = value.labels
})
.catch((error) => {
const data = error.response.data
this.errors = []
if ('non_field_errors' in data) {
this.errors = data['non_field_errors']
} else if ('template' in data) {

2
frontend/repositories/config/interface.ts

@ -2,7 +2,7 @@ import { ConfigItem, ConfigItemList } from '@/models/config/config-item-list'
export interface ConfigTestResponse {
valid: boolean,
labels?: object[]
labels: object[]
}
export interface ConfigItemListRepository {

Loading…
Cancel
Save