-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
client.py
55 lines (40 loc) · 1.01 KB
/
client.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
import requests
import sys
IP_ADDR = '192.168.0.196'
PORT = '31337'
def ask_ai(user_input: str) -> dict:
headers = {
'Content-Type': 'application/json',
}
prefix = (
"<|im_start|>system You are a helpful assistant. <|im_end|> "
"<|im_start|>user "
)
postfix = (
"<|im_end|><|im_start|>assistant "
)
json_data = {
'PROMPT_TEXT_PREFIX': prefix,
'input_str': str(user_input) + ' ',
'PROMPT_TEXT_POSTFIX': postfix,
}
response = requests.post(
f"http://{IP_ADDR}:{PORT}",
headers=headers,
json=json_data
)
return response.json()
def main():
while True:
user_input = input("ai> ")
if user_input.lower() in ['quit', 'exit']:
sys.exit("Goodbye!")
else:
answer = ask_ai(user_input)
print(answer['content'])
if __name__ == "__main__":
print(
"Type anything then press enter. "
"Type exit or quit to do so."
)
main()