File size: 452 Bytes
e9da344
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

import random
import json

class DialogueEngine:
    def __init__(self, persona, templates):
        self.persona = persona
        self.templates = templates
        self.history = []

    def respond(self, user_input):
        self.history.append(user_input)
        response = random.choice(self.templates["poetic"]) + "。"
        support = random.choice(self.templates["support"])
        return f"{self.persona['name']}{response} {support}"