mirror of
https://github.com/Kakune55/PyGetGPT.git
synced 2025-06-28 15:58:04 +08:00
添加了上下文关联功能
This commit is contained in:
parent
4c9a602244
commit
02ee3f8396
43
client.py
43
client.py
@ -2,14 +2,14 @@ import requests , json
|
||||
|
||||
data = {
|
||||
"prompt":"你好",
|
||||
"userkey":"5b32f7z1"
|
||||
"userkey":"111111"
|
||||
}
|
||||
|
||||
|
||||
|
||||
config = {
|
||||
"url":"http://localhost:5000/api/user",
|
||||
"userkey":"123456"
|
||||
"url":"api url",
|
||||
"userkey":"userkey",
|
||||
"context":0
|
||||
|
||||
}
|
||||
try:
|
||||
f = open("config.json", "r")
|
||||
@ -24,10 +24,36 @@ except IOError:
|
||||
with open('config.json', 'r') as file:
|
||||
config = json.loads(file.read())
|
||||
|
||||
data["userkey"] = config["userkey"]
|
||||
|
||||
|
||||
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:
|
||||
@ -35,6 +61,11 @@ while True:
|
||||
break
|
||||
if req["code"] == 200:
|
||||
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:
|
||||
|
14
server.py
14
server.py
@ -18,9 +18,16 @@ def request_TY(userkey,prompt,history = ""):
|
||||
"prompt":f"{prompt}"
|
||||
}
|
||||
}
|
||||
else:
|
||||
data = {
|
||||
"model": "qwen-turbo",
|
||||
"input":{
|
||||
"prompt":f"{prompt}",
|
||||
"history":history
|
||||
}
|
||||
}
|
||||
# 发送POST请求
|
||||
response = json.loads(requests.post(url, json=data ,headers=header).text)
|
||||
print(response)
|
||||
if 'code' in response:
|
||||
if response['code'] == 'DataInspectionFailed':
|
||||
return response['message']
|
||||
@ -96,7 +103,10 @@ def post_data():
|
||||
return {"code":400,"output":"UserKey is empty"}
|
||||
|
||||
if surplus > 0:
|
||||
return {"code":200,"output":f"{request_TY(userrequest['userkey'],userrequest['prompt'])}","surplus":userSurplus(userrequest['userkey'])}
|
||||
if userrequest["context"] == 1:
|
||||
return {"code":200,"output":f"{request_TY(userrequest['userkey'],userrequest['prompt'],userrequest['history'])}","surplus":userSurplus(userrequest['userkey'])}
|
||||
else:
|
||||
return {"code":200,"output":f"{request_TY(userrequest['userkey'],userrequest['prompt'])}","surplus":userSurplus(userrequest['userkey'])}
|
||||
elif surplus == -99999:
|
||||
return {"code":400,"output":"No User"}
|
||||
elif surplus <= 0:
|
||||
|
Loading…
x
Reference in New Issue
Block a user