24 lines
755 B
Python
24 lines
755 B
Python
import json
|
|
from typing import Dict
|
|
from .config import Config
|
|
import random
|
|
|
|
|
|
class ResponseGenerator:
|
|
def __init__(self, config: Config):
|
|
with config.responses_path.open('r', encoding='utf-8') as file:
|
|
self.responses: Dict[str, dict] = json.load(file)
|
|
|
|
def nlg(self, system_act):
|
|
intent = system_act.intent
|
|
slot = system_act.slots[0].name if system_act.slots else None
|
|
|
|
intent_responses = self.responses.get(intent, {})
|
|
slot_responses = intent_responses.get(slot)
|
|
|
|
if isinstance(slot_responses, list):
|
|
return random.choice(slot_responses)
|
|
elif isinstance(slot_responses, str):
|
|
return slot_responses
|
|
else:
|
|
return "Nieznane zapytanie." |