-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchatcls.py
45 lines (40 loc) · 1.28 KB
/
chatcls.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
import openai
import os
from prompt_toolkit import prompt
import kernel
import sys
import ekernel
from blessed import Terminal
term = Terminal()
def generate_response(prompt_text):
response = openai.Completion.create(
engine="davinci",
prompt=prompt_text,
max_tokens=150,
n=1,
stop=None,
temperature=0.9,
)
return response.choices[0].text.strip()
def chat():
kernel.printInfo("Type 'exit' to end the conversation.")
openai.api_key = os.getenv(kernel.centered_input(term, "Enter your OpenAI API key: "))
while True:
user_input = kernel.centered_input(term, "You ↓ ")
if user_input.lower() == 'exit':
kernel.println("Goodbye!")
break
response = generate_response(user_input)
kernel.println(f"ChatCLS : {response}")
def main():
if len(sys.argv) >= 2:
if sys.argv[1] >= "2.3.5":
ekernel.splashScreen("Procyon ChatCLS", "Version 2.3.5")
ekernel.printHeader("ChatCLS")
chat()
else:
kernel.printError("This version of market is incompatible with current version of ProcyonCLS")
else:
kernel.printError("OS Scope Error")
if __name__ == "__main__":
main()