diff --git a/bothub_api.py b/bothub_api.py index 2c438b2..1d5e514 100644 --- a/bothub_api.py +++ b/bothub_api.py @@ -65,6 +65,7 @@ def create_example(example, *args): "repository": repository, "repository_version": repository_version, "text": example.get('text'), + "language": example.get('language'), "intent": example.get('intent'), "entities": entities } @@ -101,14 +102,21 @@ def delete_all_examples(*args): print(response) -def create_evaluate_examples(*args): - with open('examples/rasa-dataset-testing.json', encoding="utf-8") as json_file: +def create_evaluate_examples(filename, *args): + with open(f'{filename}.json', encoding="utf-8") as json_file: examples = json.load(json_file) count = len(examples) index = 0 for example in examples: + entities = [] + for entity in example['entities']: + entities.append({ + "entity": entity['entity'], + "start": entity['start'], + "end": entity['end'] + }) data = { "is_corrected": False, "repository": repository, @@ -116,7 +124,7 @@ def create_evaluate_examples(*args): "text": example['text'], "language": example['language'], "intent": example['intent'], - "entities": [] + "entities": entities } response = requests.post( diff --git a/main.py b/main.py index 6e222fd..a807945 100644 --- a/main.py +++ b/main.py @@ -4,7 +4,7 @@ from decouple import config -from bothub_api import get_all_examples, create_example, delete_example, get_examples_count +from bothub_api import get_all_examples, create_example, delete_example, get_examples_count, create_evaluate_examples repository = config('REPOSITORY_UUID') repository_version = config('REPOSITORY_VERSION_ID') @@ -51,6 +51,21 @@ def export_to_json(filename, *args): with open(f'{filename}.json', 'w') as outfile: json.dump(examples, outfile) +def export_evaluate_to_json(filename, *args): + # Getting all evaluate sentences from a bothub repository + results = get_all_examples( + headers=headers, + next_call=f'{base_url}/repository/evaluate/', + params=params + ) + examples = [] + for result in results: + for sentence in result: + examples.append(sentence) + # Save results in a JSON file + with open(f'{filename}.json', 'w') as outfile: + json.dump(examples, outfile) + def train_json_sentences(filename, *args): # Read the examples in JSON file and save in a List @@ -97,7 +112,7 @@ def train_chatito(filename, *args): result = { "text": example['text'], - "language": "pt-br", + "language": "pt_br", "intent": example['intent'], "entities": entities }