Пример #1
0
 def test_decomp_10(self):
     el = eliza.Eliza()
     self.assertEqual([['0'], []],
                      el._match_decomp(['*', 'a', '*'], ['0', 'a']))
     self.assertEqual([[], []], el._match_decomp(['*', 'a', '*'], ['a']))
     self.assertEqual([[], ['b']],
                      el._match_decomp(['*', 'a', '*'], ['a', 'b']))
Пример #2
0
 def test_syn_1(self):
     el = eliza.Eliza()
     el.load("doctor.txt")
     self.assertEqual([["am"]], el._match_decomp(["@be"], ["am"]))
     self.assertEqual([["am"]], el._match_decomp(["@be", "a"], ["am", "a"]))
     self.assertEqual([["am"]],
                      el._match_decomp(["a", "@be", "b"], ["a", "am", "b"]))
Пример #3
0
 def test_syn_1(self):
     el = eliza.Eliza()
     el.load('doctor.txt')
     self.assertEqual([['am']], el._match_decomp(['@be'], ['am']))
     self.assertEqual([['am']], el._match_decomp(['@be', 'a'], ['am', 'a']))
     self.assertEqual([['am']],
                      el._match_decomp(['a', '@be', 'b'], ['a', 'am', 'b']))
Пример #4
0
 def test_decomp_10(self):
     el = eliza.Eliza()
     self.assertEqual([["0"], []],
                      el._match_decomp(["*", "a", "*"], ["0", "a"]))
     self.assertEqual([[], []], el._match_decomp(["*", "a", "*"], ["a"]))
     self.assertEqual([[], ["b"]],
                      el._match_decomp(["*", "a", "*"], ["a", "b"]))
Пример #5
0
    def startup(self):

        self.chat = toga.DetailedList(data=[{
            'icon': toga.Icon(),
            'title': 'RisBot',
            'subtitle': 'Hello,Wassup?',
        }],
                                      style=Pack(flex=1))

        self.text_input = toga.TextInput(style=Pack(flex=1))
        send_button = toga.Button('Send',
                                  style=Pack(padding_left=5),
                                  on_press=self.handle_input)

        input_box = toga.Box(children=[self.text_input, send_button],
                             style=Pack(direction=ROW,
                                        alignment='CENTER',
                                        padding=5))

        # Create a main window with a name matching the app
        self.main_window = toga.MainWindow(title=self.name)

        # Create a main content box
        main_box = toga.Box()

        # Add the content on the main window
        self.main_window.content = toga.Box(children=[self.chat, input_box],
                                            style=Pack(direction=COLUMN))

        self.partner = eliza.Eliza()
        # Show the main window
        self.main_window.show()
Пример #6
0
 def test_response_2(self):
     el = eliza.Eliza()
     el.load('doctor.txt')
     self.assertEqual(el.initial(), 'How do you do.  Please tell me your problem.')
     self.assertIn(el.respond('Hello'), [
         'How do you do. Please state your problem.',
         'Hi. What seems to be your problem ?'])
     self.assertEqual(el.final(), 'Goodbye.  Thank you for talking to me.')
Пример #7
0
 def test_response_2(self):
     el = eliza.Eliza()
     el.load("doctor.txt")
     self.assertEqual(el.initial(),
                      "How do you do.  Please tell me your problem.")
     self.assertIn(el.respond("Hello"), [
         "How do you do. Please state your problem.",
         "Hi. What seems to be your problem ?"
     ])
     self.assertEqual(el.final(), "Goodbye.  Thank you for talking to me.")
Пример #8
0
 def test_response_1(self):
     el = eliza.Eliza()
     el.load("doctor.txt")
     self.assertEqual("In what way ?", el.respond("Men are all alike."))
     self.assertEqual(
         "Can you think of a specific example ?",
         el.respond("They're always bugging us about something or other."))
     self.assertEqual("Your boyfriend made you come here ?",
                      el.respond("Well, my boyfriend made me come here."))
     self.assertEqual("I am sorry to hear that you are depressed .",
                      el.respond("He says I'm depressed much of the time."))
     self.assertEqual(
         "Do you think that coming here will help you not to be unhappy ?",
         el.respond("It's true. I am unhappy."))
     self.assertEqual(
         "What would it mean to you if you got some help ?",
         el.respond("I need some help, that much seems certain."))
     self.assertEqual(
         "Tell me more about your family.",
         el.respond("Perhaps I could learn to get along with my mother."))
     self.assertEqual("Who else in your family takes care of you ?",
                      el.respond("My mother takes care of me."))
     self.assertEqual("Your father ?", el.respond("My father."))
     self.assertEqual("What resemblence do you see ?",
                      el.respond("You are like my father in some ways."))
     self.assertEqual(
         "What makes you think I am not very aggressive ?",
         el.respond(
             "You are not very aggressive, but I think you don't want me to notice that."
         ),
     )
     self.assertEqual("Why do you think I don't argue with you ?",
                      el.respond("You don't argue with me."))
     self.assertEqual("Does it please you to believe I am afraid of you ?",
                      el.respond("You are afraid of me."))
     self.assertEqual(
         "What else comes to mind when you think of your father ?",
         el.respond("My father is afraid of everybody."))
     self.assertIn(
         el.respond("Bullies."),
         [
             "Lets discuss further why your boyfriend made you come here .",
             "Earlier you said your mother .",
             "But your mother takes care of you .",
             "Does that have anything to do with the fact that your boyfriend made you come here ?",
             "Does that have anything to do with the fact that your father ?",
             "Lets discuss further why your father is afraid of everybody .",
         ],
     )
Пример #9
0
async def chat(chat_session: ChatSession, person: str):
    response = ""
    match person:
        case "librarian":
            import eliza
            eliza_james = eliza.Eliza()
            eliza_james.load("assets/txt/librarian.txt")
            branch_chat = pathlib.Path(f"assets/txt/{branch}.txt")
            if branch and branch_chat.exists():
                eliza_james.load(branch_chat.path)
            response = eliza_james.respond(chat_session.question)
            if response is None:
                response = "Thank-you for your question, my name is Eliza"
        case _:
            response = f"{person} unknown"
    return { "response": response }
Пример #10
0
 def test_response_1(self):
     el = eliza.Eliza()
     el.load('doctor_de.txt')
     self.assertEqual('In what way ?', el.respond('Men are all alike.'))
     self.assertEqual(
         'Can you think of a specific example ?',
         el.respond('They\'re always bugging us about something or other.'))
     self.assertEqual('Your boyfriend made you come here ?',
                      el.respond('Well, my boyfriend made me come here.'))
     self.assertEqual(
         'I am sorry to hear that you are depressed .',
         el.respond('He says I\'m depressed much of the time.'))
     self.assertEqual(
         'Do you think that coming here will help you not to be unhappy ?',
         el.respond('It\'s true. I am unhappy.'))
     self.assertEqual(
         'What would it mean to you if you got some help ?',
         el.respond('I need some help, that much seems certain.'))
     self.assertEqual(
         'Tell me more about your family.',
         el.respond('Perhaps I could learn to get along with my mother.'))
     self.assertEqual('Who else in your family takes care of you ?',
                      el.respond('My mother takes care of me.'))
     self.assertEqual('Your father ?', el.respond('My father.'))
     self.assertEqual('What resemblence do you see ?',
                      el.respond('You are like my father in some ways.'))
     self.assertEqual(
         'What makes you think I am not very aggressive ?',
         el.respond(
             'You are not very aggressive, but I think you don\'t want me to notice that.'
         ))
     self.assertEqual('Why do you think I don\'t argue with you ?',
                      el.respond('You don\'t argue with me.'))
     self.assertEqual('Does it please you to believe I am afraid of you ?',
                      el.respond('You are afraid of me.'))
     self.assertEqual(
         'What else comes to mind when you think of your father ?',
         el.respond('My father is afraid of everybody.'))
     self.assertIn(el.respond('Bullies.'), [
         'Lets discuss further why your boyfriend made you come here .',
         'Earlier you said your mother .',
         'But your mother takes care of you .',
         'Does that have anything to do with the fact that your boyfriend made you come here ?',
         'Does that have anything to do with the fact that your father ?',
         'Lets discuss further why your father is afraid of everybody .',
     ])
Пример #11
0
def get_bot_response():
    userText = request.args.get('msg')
    eliz = eliza.Eliza()
    eliz.load('doctor.txt')
    response = eliz.respond(userText)
    return str(response)
Пример #12
0
 def test_decomp_1(self):
     el = eliza.Eliza()
     self.assertEqual([], el._match_decomp(['a'], ['a']))
     self.assertEqual([], el._match_decomp(['a', 'b'], ['a', 'b']))
Пример #13
0
 def test_decomp_8(self):
     el = eliza.Eliza()
     self.assertIsNone(el._match_decomp(['*', 'a'], ['a', 'b']))
     self.assertIsNone(el._match_decomp(['*', 'a'], ['0', 'a', 'b']))
     self.assertIsNone(el._match_decomp(['*', 'a'], ['0', '1', 'a', 'b']))
Пример #14
0
 def test_decomp_7(self):
     el = eliza.Eliza()
     self.assertEqual([[]], el._match_decomp(['*', 'a'], ['a']))
Пример #15
0
 def test_decomp_8(self):
     el = eliza.Eliza()
     self.assertIsNone(el._match_decomp(["*", "a"], ["a", "b"]))
     self.assertIsNone(el._match_decomp(["*", "a"], ["0", "a", "b"]))
     self.assertIsNone(el._match_decomp(["*", "a"], ["0", "1", "a", "b"]))
Пример #16
0
import eliza

sentry_sdk.init(os.getenv("SENTRY_DSN"))

# VECTORIZER_FILE = os.getenv("VECTORIZER_FILE", "/global_data/*vectorizer*.zip")

logging.basicConfig(
    format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
    level=logging.INFO)
logger = logging.getLogger(__name__)

app = Flask(__name__)

# src from https://github.com/wadetb/eliza
eliza_init_model = eliza.Eliza()
eliza_init_model.load("./doctor.txt")


# for tests
# curl -X POST "http://*****:*****@app.route("/respond", methods=["POST"])
def respond():
    st_time = time.time()
    last_utterance_batch = request.json.get("last_utterance_batch", [])
    human_utterance_history_batch = request.json.get(
        "human_utterance_history_batch", [])
    logger.info(f"input data: {request.json}s")
    response = []
Пример #17
0
                    'local/sounds/' + settings["wake-sound"],
                    settings["wake-sound"].split('.')[-1]), ))
            process.daemon = True
            process.start()
            input = stt(recognizer, microphone)
        else:
            input = None

    process = threading.Thread(target=processInput, args=(input, ))
    process.daemon = True
    process.start()


if __name__ == "__main__":
    try:
        eliza = eliza.Eliza()
        eliza.load('doctor.txt')
        eliza.initial()
        ws = AsyncWebsocket(msg_callback)
        assistant = Assistant({
            "answerPath":
            os.path.dirname(os.path.abspath(__file__)) + "/local/" +
            settings['language'] + "/",
            "inputText":
            "",
            "inputLine":
            "",
            "question":
            "",
            "webSocket":
            ws,
Пример #18
0
def init_session(name):
    session['handle'] = name
    session['eliza'] = eliza.Eliza()
    session['eliza'].load('doctor.txt')
    return session['eliza'].initial()
Пример #19
0
import eliza

therapist = eliza.Eliza()
while some_condition:
    input = prompt("> ")
    reply = therapist.respond(input)
    print(reply)
Пример #20
0
 def test_syn_3(self):
     el = eliza.Eliza()
     el.load("doctor.txt")
     self.assertIsNotNone(
         el._match_decomp(["*", "i", "am", "@sad", "*"],
                          ["its", "true", "i", "am", "unhappy"]))
Пример #21
0
 def test_syn_2(self):
     el = eliza.Eliza()
     el.load("doctor.txt")
     self.assertIsNone(el._match_decomp(["@be"], ["a"]))
Пример #22
0
 def test_decomp_7(self):
     el = eliza.Eliza()
     self.assertEqual([[]], el._match_decomp(["*", "a"], ["a"]))
Пример #23
0
 def test_syn_2(self):
     el = eliza.Eliza()
     el.load('doctor.txt')
     self.assertIsNone(el._match_decomp(['@be'], ['a']))
Пример #24
0
 def test_syn_3(self):
     el = eliza.Eliza()
     el.load('doctor.txt')
     self.assertIsNotNone(
         el._match_decomp(['*', 'i', 'am', '@sad', '*'],
                          ['its', 'true', 'i', 'am', 'unhappy']))
Пример #25
0
 def test_decomp_4(self):
     el = eliza.Eliza()
     self.assertEqual([], el._match_decomp([], []))
     self.assertEqual([[]], el._match_decomp(['*'], []))
Пример #26
0
 def test_decomp_5(self):
     el = eliza.Eliza()
     self.assertIsNone(el._match_decomp(['a'], []))
     self.assertIsNone(el._match_decomp([], ['a']))
Пример #27
0
 def test_decomp_1(self):
     el = eliza.Eliza()
     self.assertEqual([], el._match_decomp(["a"], ["a"]))
     self.assertEqual([], el._match_decomp(["a", "b"], ["a", "b"]))