mirror of
https://github.com/Kakune55/PyGetGPT.git
synced 2025-06-28 15:58:04 +08:00
76 lines
1.8 KiB
Python
76 lines
1.8 KiB
Python
import requests , json
|
|
|
|
data = {
|
|
"prompt":"你好",
|
|
"userkey":"111111"
|
|
}
|
|
|
|
config = {
|
|
"url":"api url",
|
|
"userkey":"userkey",
|
|
"context":0
|
|
|
|
}
|
|
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())
|
|
|
|
|
|
|
|
history = [
|
|
["null","null"],
|
|
["null","null"],
|
|
]
|
|
|
|
|
|
|
|
|
|
#主循环
|
|
while True:
|
|
data = {
|
|
"prompt":"你好",
|
|
"userkey":"111111",
|
|
"context":0,
|
|
"history":[
|
|
{
|
|
"user":f"{history[1][0]}",
|
|
"bot":f"{history[1][1]}"
|
|
},
|
|
{
|
|
"user":f"{history[0][0]}",
|
|
"bot":f"{history[0][1]}"
|
|
}
|
|
]
|
|
}
|
|
data["context"] = config["context"]
|
|
data["prompt"] = str(input(">> You:\n"))
|
|
data["userkey"] = config["userkey"]
|
|
try:
|
|
req = json.loads(requests.post(url=config['url'],json=data).text)
|
|
except:
|
|
print("Internet Err : Can not connect Server")
|
|
input()
|
|
break
|
|
if req["code"] == 200:
|
|
if config["context"] == 1:
|
|
print(f"\n>> AI:\n{req['output']}\n\n<剩余tokens:{req['surplus']} ><已启用上下文关联>")
|
|
else:
|
|
print(f"\n>> AI:\n{req['output']}\n\n<剩余tokens:{req['surplus']} >")
|
|
history[1][1] = history[0][1]
|
|
history[1][0] = history[0][0]
|
|
history[0][1] = req['output']
|
|
history[0][0] = data["prompt"]
|
|
|
|
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") |