sklep-internetowy-systemy-d.../chatbot/modules/generator.py
2024-05-07 23:14:14 +02:00

19 lines
652 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, list] = json.load(file)
self.intent_to_response_key = {
"ask_name": "name_response",
"unknown": "unknown"
}
def generate(self, response_key: str) -> str:
response_key = self.intent_to_response_key.get(response_key, "unknown")
return random.choice(self.responses.get(response_key, ["Przepraszam, nie rozumiem. Możesz to powtórzyć?"]))