forked from joshcho/ChatGPT.el
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchatgpt.py
47 lines (37 loc) · 907 Bytes
/
chatgpt.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
# chatgpt.py
import sys
sys.path.insert(0, '/Users/carlos/Downloads/chatgpt-wrapper')
from epc.server import EPCServer
from chatgpt_wrapper import ChatGPT
server = EPCServer(('localhost', 0))
bot = None
stringbot = None
def get_cahtgpt_bot():
global bot
if bot == None:
bot = ChatGPT()
@server.register_function
def query(query):
global bot
get_cahtgpt_bot()
return bot.ask(query)
@server.register_function
def querystream(query):
global bot
get_cahtgpt_bot()
global stringbot
if stringbot == None:
stringbot = iter(bot.ask_stream(query))
try:
return next(stringbot)
except StopIteration:
stringbot = None
return None
@server.register_function
def switch_to_chat(chat_uuid):
global bot
get_cahtgpt_bot()
# bot.switch_to_conversation(chat_uuid)
return ""
server.print_port()
server.serve_forever()