-
Notifications
You must be signed in to change notification settings - Fork 0
/
chat.py
59 lines (39 loc) · 1.19 KB
/
chat.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from typing import List, Dict, Optional
import random
import subprocess
from subprocess import signal
import os
from time import sleep
import numpy as np
import math
import json
from automaton import VoiceControlledAutomaton, State, Exit, DEBUG
from revChatGPT.revChatGPT import Chatbot as ChatGPT
# VCA code
class ChatState(State):
pass
class ChatBot(VoiceControlledAutomaton):
def __init__(self, **kwargs):
super().__init__(name="chat gpt", **kwargs)
self.SideEffectTransitionMatrix = {
ChatState.enter: self.converse,
}
self.config_file = ".auth.json"
self.init_chatgpt()
def init_chatgpt(self):
with open(self.config_file, "r") as auth:
config = json.load(auth)
self.chatbot = ChatGPT(config)
def converse(self, prompt: str) -> ChatState:
prompt = prompt.replace("chat", "").strip()
print("="* 20)
print("You:")
print(prompt)
print("="* 20)
response = self.chatbot.get_chat_response(prompt)['message']
print("+"* 20)
print("ChatGPT:")
print(response)
print("+"* 20)
self.speak(response)
return self.state