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") 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: print(f"\n>> System:\n{req['output']}\n")