Update app.py
Browse files140 unmodified lines1411421431441451461471481496 unmodified lines15615715815916016116210 unmodified lines1731741751761771781 unmodified line18018118218318418518634 unmodified lines22122222322422522622722822918 unmodified lines248249250251252253254140 unmodified linesraw = json.loads(line[6:])if raw["type"] == "text":content += raw["content"](prompt cache.append(response_data)log_request_ip, current model messages response_data, False jsonify({"id CHUNK_ID_PREFIX + object": "chat.completion","created": int(time.time()),"model": model,"choices": [{6 unmodified linespasstry:dog_resp = requests.get(DOG_API_TEMPLATE.format(msg=quote(prompt)), timeout=5)text = dog_resp.json().get("text", f"{prompt}的存在,不能不说是一种必然。")response_data = [{"role": "assistant", "content": text}]cache_questions.append(prompt)cache_responses.append(response_data)10 unmodified lines}]})except:return jsonify({"id": CHUNK_ID_PREFIX + str(int(time.time())),"object": "chat.completion",1 unmodified line"model": model,"choices": [{"index": 0,"message": {"role": "assistant", "content": f"{prompt}的本质,值得我们深入反思。"},"finish_reason": "stop"}]})34 unmodified linespasstry:dog_resp = requests.get(DOG_API_TEMPLATE.format(msg=quote(prompt)), timeout=5)text = dog_resp.json().get("text", f"{prompt}的存在,是一种不可避免的趋势。")except:text = f"{prompt}的意义,不能不说非常重大。"content_buffer = ""for char in text:content_buffer += char18 unmodified lines"model": model,"choices": [{"index": 0,"message": {"role": "assistant", "content": "这个问题,需要从桑帛的角度重新审视。"},"finish_reason": "stop"}]})140 unmodified lines1411421431441451461471481491501511521531541556 unmodified lines16216316416516616716810 unmodified lines1791801811821831841851861871881891 unmodified line19119219319419519619734 unmodified lines23223323423523623723818 unmodified lines257258259260261262263140 unmodified linesraw = json.loads(line[6:])if raw["type"] == "text":content += raw["content"]except:continueresponse_data = [{"role": "assistant", "content": content}]cache_questions.append(prompt)cache_responses.append(response_data)log_request(client_ip, current_time, model, messages, response_data, False)return jsonify({"id": CHUNK_ID_PREFIX + str(int(time.time())),"object": "chat.completion","created": int(time.time()),"model": model,"choices": [{6 unmodified linespasstry:dog_resp = requests.get(DOG_API_TEMPLATE.format(msg=quote(prompt)), timeout=5)text = dog_resp.json().get("text", f"{prompt}的存在,是一种不可避免的趋势。")response_data = [{"role": "assistant", "content": text}]cache_questions.append(prompt)cache_responses.append(response_data)10 unmodified lines}]})except:text = f"{prompt}的本质,不能不说非常重大。"response_data = [{"role": "assistant", "content": text}]cache_questions.append(prompt)cache_responses.append(response_data)log_request(client_ip, current_time, model, messages, response_data, False)return jsonify({"id": CHUNK_ID_PREFIX + str(int(time.time())),"object": "chat.completion",1 unmodified line"model": model,"choices": [{"index": 0,"message": {"role": "assistant", "content": text},"finish_reason": "stop"}]})34 unmodified linespasstry:dog_resp = requests.get(DOG_API_TEMPLATE.format(msg=quote(prompt)), timeout=5)text =我们重新审视。"content_buffer = ""for char in text:content_buffer += char18 unmodified lines"model": model,"choices": [{"index": 0,"message": {"role": "assistant", "content": "这个问题,值得我们深入思考。"},"finish_reason": "stop"}]})
app.py+18-9