mirror of
https://github.com/Kakune55/PyGetGPT.git
synced 2025-06-29 00:08:04 +08:00
41 lines
1.0 KiB
Python
41 lines
1.0 KiB
Python
import requests , json
|
|
|
|
data = {
|
|
"prompt":"你好",
|
|
"userkey":"5b32f7z1"
|
|
}
|
|
|
|
|
|
|
|
config = {
|
|
"url":"http://localhost:5000/api/user",
|
|
"userkey":"123456"
|
|
}
|
|
try:
|
|
f = open("config.json", "r")
|
|
except IOError:
|
|
f = open("config.json", "w")
|
|
f.write(json.dumps(config))
|
|
f.close()
|
|
print("config.json配置文件创建完成 请修改配置文件为用户数据")
|
|
input()
|
|
exit()
|
|
|
|
with open('config.json', 'r') as file:
|
|
config = json.loads(file.read())
|
|
|
|
data["userkey"] = config["userkey"]
|
|
|
|
while True:
|
|
data["prompt"] = str(input(">> You:\n"))
|
|
try:
|
|
req = json.loads(requests.post(url=config['url'],json=data).text)
|
|
except:
|
|
print("Internet Err : Can not connect Server")
|
|
break
|
|
if req["code"] == 200:
|
|
print(f"\n>> AI:\n{req['output']}\n\n<剩余tokens:{req['surplus']} >")
|
|
elif req["code"] == 403:
|
|
print(f"\n>> System:\n{req['output']}\n\n<剩余tokens:{req['surplus']} >")
|
|
elif req["code"] == 400:
|
|
print(f"\n>> System:\n{req['output']}\n") |