2024-05-07 21:40:14 +02:00
|
|
|
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, list] = json.load(file)
|
2024-05-07 23:14:14 +02:00
|
|
|
self.intent_to_response_key = {
|
|
|
|
"ask_name": "name_response",
|
|
|
|
"unknown": "unknown"
|
|
|
|
}
|
2024-05-07 21:40:14 +02:00
|
|
|
|
|
|
|
def generate(self, response_key: str) -> str:
|
2024-05-07 23:14:14 +02:00
|
|
|
response_key = self.intent_to_response_key.get(response_key, "unknown")
|
2024-05-07 21:40:14 +02:00
|
|
|
return random.choice(self.responses.get(response_key, ["Przepraszam, nie rozumiem. Możesz to powtórzyć?"]))
|