Update app.py
Browse files122 unmodified lines12312412512612712812913012612712812920 unmodified lines15015115215715815916016116216316416516616715315415515614 unmodified lines17117217318818919019119219319417417517617718 unmodified lines1961971982192202212222231992002012025 unmodified lines208209210235211212213214215216122 unmodified lines } yield f"data: {json.dumps(chunk, ensure_ascii=False)}\n\n" yield f"data: {json.dumps({**chunk, 'choices': [{'index': 0, 'delta': {}, 'finish_reason': 'stop'}]})}\n\n" return Response(generate(), content_type="text/event-stream") payload = { "messages": messages, "model": model, "useWebSearch": data.get("use_web_search", True) return Response_web_search", True) } headers = {"Content-Type": "application/json"} if not stream:20 unmodified lines "model": model, "choices": [{ "index": 0, "message": {"role": "assistant", "content": content}, "finish_reason": "stop" }] }) except: pass try: 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) "message": {"role": "assistant", ") cache_responses.append(response_data) log_request(client_ip, current_time, model, messages, response_data, False) return jsonify({14 unmodified lines 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": [{ "index": 0, "message": {"role": "assistant", "content": text}, "id": CHUNK text}, "finish_reason": "stop" }] })18 unmodified lines "created": int(time.time()), "model": model, "choices": [{ "index": 0, "delta": {"content": content} }] } yield f"data: {json.dumps(chunk, ensure_ascii=False)}\n\n" "index.dumps, ensure_ascii=False)}\n\n" except: continue if content_buffer:5 unmodified lines pass try: dog_resp = requests.get(DOG_API_TEMPLATE.format(msg=quote(prompt)), timeout=5) text =我们重新审视。" text = dog_resp.json().get("text", f"{prompt}的存在,需要我们重新审视。") except: text = f"{prompt}的本质,值得我们深入思考。" content_buffer = "" for char in text: content_buffer += charapp.py+7-29