Cognigy.AI Lab
You've entered the Cognigy.AI Lab. This content and example code is inspirational.
In this article, Microsoft Excel will be used in order to create and manage FAQ intents in Cognigy.AI. While it is recommended to manage intents in the Cognigy.AI User Interface, it could be the case, in a project, that a person, which is not onboarded to Cognigy.AI, will create FAQ content.
Create the Excel File
The Excel file should provide a very easy-to-understand structure, such as the following:
In this case, one can fill three different columns with content:
- Name
- The intent name.
- Question
- The list of example sentences.
- Answer
- The list of answers that will be inserted into a default reply in the intent itself.
With this format, the non-onboarded expert can fill the table with valuable information, which the bot should be able to talk about.
Convert the Excel to Intents
As soon as the table is ready for a first import, the Excel needs to be translated into a valid format. In this case, the target is to simply upload the intents into Cognigy.AI and train the new model. However, the current Excel format is not importable since it does not fit into the CSV or JSON format.
Script
In order to convert the Excel file, one could, for example, use a short Python script:
# Import the required python modules
import pandas as pd import math import json import csv
# Define the name of the Excel file fileName = "My-FAQ-Excel-File"
# Read the Excel file df = pd.read_excel("{}.xlsx".format(fileName), sheet_name="FAQs") intents = [] intentNames = df["Name"]
# Loop through the list of Names and create a new intent for each row for index, name in enumerate(intentNames): if name is not None: exampleSentences = [] defaultReplies = [] if df["Question"][index] is not None and df["Question"][index] is not float: try: exampleSentences = df["Question"][index].split("\n") exampleSentences = list(filter(None, exampleSentences)) defaultReplies = df["Answer"][index].split("\n") defaultReplies = list(filter(None, defaultReplies)) except: continue intents.append({ "name": name, "exampleSentences": exampleSentences, "rules": [], "tags": [], "confirmationSentences": [], "condition": "", "disambiguationSentence": "", "childFeatures": False, "parent": "", "defaultReply": { "text": defaultReplies, "type": "text" } })
# Write the list of created Cognigy.AI intents into a JSON file with open("{}.json".format(fileName), "w", encoding="utf-8") as outputFile: json.dump(intents, outputFile, ensure_ascii=False)
Run the Script
One will need a folder that consists of the FAQ Excel file and the Python script, while the folder could look like this:
- my-cognigy-faq
- FAQ-Excel.xlsx
- script.py
In order to convert the FAQ-Excel.xlsx file, one needs to execute the Python script:
python script.py
This will create a FAQ-Excel.json JSON file in the same folder:
- my-cognigy-faq
- FAQ-Excel.xlsx
- script.py
- FAQ-Excel.json
The JSON file will look similar to this:
[
{ "name": "About Cognigy", "exampleSentences": [ "Who is Cognigy?",
"..." ], "rules": [], "tags": [], "confirmationSentences": [], "condition": "", "disambiguationSentence": "", "childFeatures": false, "parent": "", "defaultReply": { "text": [ "Cognigy is an enterprise software provider for Conversational AI automation." ], "type": "text" } }
]
The recently created JSON file can now be upload to a Flow in a Cognigy.AI agent. One can read more about uploading intents here.
Comments
0 comments