Files
hack/tools/scripts/llm-key-hunter/results/_cache/content/605333616_text-expansion-program-based-on-deepseek-api.json
T

1 line
2.9 KiB
JSON

{"repo": "605333616/text-expansion-program-based-on-deepseek-api", "files": {"web-txt-expansion.py": {"df589fb547c7a9159919f2e3ce4923b3e4e5f3ce": {"t": 1785768179.444435, "n": 2445, "h": "2e22be6fb2af2c17", "c": "from flask import Flask, request, render_template\nfrom openai import OpenAI\nfrom flask import send_file\n\napp = Flask(__name__)\n\n#主页面\n@app.route('/')\ndef index():\n number='1' # 每次生成一个数字就发送 \\n 最好不要删除\n\n return render_template('index.html',display='请提交txt文件')\n\n\n#文件上传\n@app.route('/upload', methods=['POST'])\ndef upload():\n file = request.files['file']\n print(file)\n file.save('temporaryData/1.txt')\n # 在这里实现文件的处理逻辑\n select_file()\n #---------------------\n\n return render_template('index.html',display='修改完成')\n\n\n#文本扩充\ndef select_file():\n i = 0\n txt_address = 'temporaryData/1.txt'\n client = OpenAI(\n api_key='sk-27gM2TB6wULaSmeCmaHsI7mi7X2vneAX2ziR95NeWtlXKDrw', # 知识引擎原子能力 APIKey\n base_url=\"https://api.lkeap.cloud.tencent.com/v1\",\n )\n # 打开文件\n with open(txt_address, 'r', encoding='utf-8') as f:\n txt_content = f.read()\n txt_content=txt_content.split('\\n')\n\n s_value = True\n # 请求\n for element in txt_content:\n chat_completion = client.chat.completions.create(\n model=\"deepseek-r1\",\n messages=[\n {\n 'role': 'system',\n 'content': '只填充细节,不扩充情节,要有画面感,尽量简洁,限制在一个自然段以内:',\n },\n {\n \"role\": \"user\",\n \"content\": element\n }\n ],\n stream=s_value,\n )\n\n textGather=''\n\n if s_value:\n for chunk in chat_completion:\n # 打印思维链内容\n if hasattr(chunk.choices[0].delta, 'reasoning_content'):\n print(f\"{chunk.choices[0].delta.reasoning_content}\", end=\"\")\n if hasattr(chunk.choices[0].delta, 'content'):\n if chunk.choices[0].delta.content != None and len(chunk.choices[0].delta.content) != 0:\n textGather=textGather+chunk.choices[0].delta.content\n print(chunk.choices[0].delta.content, end=\"\")\n else:\n result = chat_completion.choices[0].message.content\n txt_content[i]=textGather\n i = i + 1\n address = txt_address.split('.', 1)\n full_text = '\\n'.join(txt_content)\n with open('temporaryData/已扩充.txt',\"w\") as file:\n file.write(full_text)\n\n@app.route('/download')\ndef download_file():\n return send_file('temporaryData/已扩充.txt', as_attachment=True)\n\nif __name__ == '__main__':\n app.run(debug=True)\n"}}}}