Spaces:
Runtime error
Runtime error
# Function to update the Domain file with new intents and responses | |
def update_domain_file(intent_name, domain_file_path="domain.yml"): | |
# Create the 'data' directory if it doesn't exist | |
if not os.path.exists("data"): | |
os.makedirs("data") | |
# If the Domain file doesn't exist, create it with a default structure | |
if os.path.exists(domain_file_path): | |
with open(domain_file_path, "r") as file: | |
domain_data = yaml.safe_load(file) | |
# If domain_data is None, initialize it with a default structure | |
if domain_data is None: | |
domain_data = {"intents": [], "responses": {}} | |
else: | |
domain_data = {"intents": [], "responses": {}} | |
# Add the new intent to the domain | |
if intent_name not in domain_data["intents"]: | |
domain_data["intents"].append(intent_name) | |
# Add a new response if the intent doesn't already have a response | |
if f"utter_{intent_name}" not in domain_data["responses"]: | |
domain_data["responses"][f"utter_{intent_name}"] = [ | |
{"text": f"Response for {intent_name}"} | |
] | |
# Write back the updated Domain file | |
with open(domain_file_path, "w") as file: | |
yaml.dump(domain_data, file) | |
return f"Domain file updated with intent: {intent_name}" | |