sklep-internetowy-systemy-d.../chatbot/modules/generator.py

14 lines
448 B
Python
Raw Normal View History

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)
def generate(self, response_key: str) -> str:
return random.choice(self.responses.get(response_key, ["Przepraszam, nie rozumiem. Możesz to powtórzyć?"]))