Skip to content

Commit 631a707

Browse files
author
Johannes Hötter
committed
adds exeptions to rasa adapter
1 parent 15172a7 commit 631a707

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

kern/adapter/rasa.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import Any, List, Optional
44
import pandas as pd
55
import yaml
6-
from kern import Client
6+
from kern import Client, exceptions
77
from collections import OrderedDict
88

99
# https://stackoverflow.com/questions/8640959/how-can-i-control-what-scalar-form-pyyaml-uses-for-my-data
@@ -119,11 +119,18 @@ def build_intent_yaml(
119119
file_name (str, optional): name of the file you want to store the data to. Defaults to "nlu.yml".
120120
constant_outside (str, optional): constant to be used for outside labels in token-level tasks. Defaults to CONSTANT_OUTSIDE.
121121
version (str, optional): Rasa version. Defaults to "3.1".
122+
123+
Raises:
124+
exceptions.UnknownItemError: if the item you are looking for is not found.
122125
"""
123126
msg.info("Building training data for Rasa")
124127
msg.warn("If you haven't done so yet, please install rasa and run `rasa init`")
125128
df = client.get_record_export(tokenize=(tokenized_label_task is not None))
126129

130+
for attribute in [text_name, intent_label_task, metadata_label_task, tokenized_label_task]:
131+
if attribute is not None and attribute not in df.columns:
132+
raise exceptions.UnknownItemError(f"Can't find argument '{attribute}' in the existing export schema: {df.columns.tolist()}")
133+
127134
if tokenized_label_task is not None:
128135
text_name_injected = f"{text_name}__injected"
129136
df[text_name_injected] = df.apply(

kern/exceptions.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,36 @@
11
# -*- coding: utf-8 -*-
22
from typing import Optional
33

4+
class LocalError(Exception):
5+
pass
6+
7+
class UnknownItemError(LocalError):
8+
pass
9+
410
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses
5-
class SDKError(Exception):
11+
class APIError(Exception):
612
def __init__(self, message: Optional[str] = None):
713
if message is None:
814
message = "Please check the SDK documentation at https://github.com/code-kern-ai/kern-python"
915
super().__init__(message)
1016

1117

1218
# 401 Unauthorized
13-
class UnauthorizedError(SDKError):
19+
class UnauthorizedError(APIError):
1420
pass
1521

1622

1723
# 404 Not Found
18-
class NotFoundError(SDKError):
24+
class NotFoundError(APIError):
1925
pass
2026

21-
class UnknownProjectError(SDKError):
27+
class UnknownProjectError(APIError):
2228
def __init__(self, project_id: str):
2329
super().__init__(message=f"Could not find project '{project_id}'. Please check your input.")
2430

2531

2632
# 500 Server Error
27-
class InternalServerError(SDKError):
33+
class InternalServerError(APIError):
2834
pass
2935

3036

@@ -48,8 +54,8 @@ def get_api_exception_class(
4854
status_code: int,
4955
error_code: Optional[str] = None,
5056
error_message: Optional[str] = None,
51-
) -> SDKError:
52-
exception_or_dict = RESPONSE_CODES_API_EXCEPTION_MAP.get(status_code, SDKError)
57+
) -> APIError:
58+
exception_or_dict = RESPONSE_CODES_API_EXCEPTION_MAP.get(status_code, APIError)
5359
if isinstance(exception_or_dict, dict):
5460
exception_class = exception_or_dict.get(error_code, exception_or_dict["*"])
5561
else:

0 commit comments

Comments
 (0)