Files
hack/tools/scripts/llm-key-hunter/results/_cache/content/bh3gei_deepseekapitest.json
T

1 line
5.2 KiB
JSON

{"repo": "bh3gei/deepseekapitest", "files": {"app.py": {"78d09251d949c64bf39d18e752da82c645ab9efd": {"t": 1785674055.29983, "n": 2341, "h": "b04c0dd7211b4dba", "c": "import requests\nimport json\nfrom flask import Flask, request, jsonify, render_template\nimport sqlite3\n\napp = Flask(__name__)\n\n# 初始化数据库\ndef init_db():\n conn = sqlite3.connect('chat_history.db')\n cursor = conn.cursor()\n cursor.execute('''\n CREATE TABLE IF NOT EXISTS chat_history (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n user_message TEXT NOT NULL,\n bot_response TEXT NOT NULL,\n timestamp DATETIME DEFAULT CURRENT_TIMESTAMP\n )\n ''')\n conn.commit()\n conn.close()\n\ninit_db()\n\napi_key = 'sk-' \nendpoint = 'https://api.deepseek.com/chat/completions' \n\ndef call_deepseek_api(question):\n headers = {\n 'Content-Type': 'application/json',\n 'Authorization': f'Bearer {api_key}'\n }\n data = {\n \"model\": \"deepseek-chat\", \n \"messages\": [\n {\"role\": \"system\", \"content\": \"你是一袋猫粮.\"},\n {\"role\": \"user\", \"content\": question}\n ],\n \"stream\": False\n }\n\n try:\n response = requests.post(endpoint, headers=headers, json=data)\n response.raise_for_status()\n bot_response = response.json()['choices'][0]['message']['content']\n print(f\"API 响应: {bot_response}\") \n return bot_response\n except requests.exceptions.RequestException as e:\n print(f\"API 调用失败: {str(e)}\") \n raise\n\n@app.route('/')\ndef index():\n return render_template('index.html')\n\n@app.route('/ask', methods=['POST'])\ndef ask():\n print(\"收到请求\") \n user_message = request.json.get('message')\n if not user_message:\n print(\"未提供消息\") \n return jsonify({'error': 'No message provided'}), 400\n\n print(f\"用户输入: {user_message}\") \n\n try:\n bot_response = call_deepseek_api(user_message)\n print(f\"Bot response: {bot_response}\") \n save_chat_history(user_message, bot_response)\n return jsonify({'response': bot_response})\n except Exception as e:\n return jsonify({'error': str(e)}), 500\n\ndef save_chat_history(user_message, bot_response):\n conn = sqlite3.connect('chat_history.db')\n cursor = conn.cursor()\n cursor.execute('''\n INSERT INTO chat_history (user_message, bot_response)\n VALUES (?, ?)\n ''', (user_message, bot_response))\n conn.commit()\n conn.close()\n\nif __name__ == '__main__':\n app.run(debug=True)"}, "c5f6d51161fdfcc6d3586aaa4b76e6b8c411ccc4": {"t": 1785773566.9551058, "n": 2341, "h": "b04c0dd7211b4dba", "c": "import requests\nimport json\nfrom flask import Flask, request, jsonify, render_template\nimport sqlite3\n\napp = Flask(__name__)\n\n# 初始化数据库\ndef init_db():\n conn = sqlite3.connect('chat_history.db')\n cursor = conn.cursor()\n cursor.execute('''\n CREATE TABLE IF NOT EXISTS chat_history (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n user_message TEXT NOT NULL,\n bot_response TEXT NOT NULL,\n timestamp DATETIME DEFAULT CURRENT_TIMESTAMP\n )\n ''')\n conn.commit()\n conn.close()\n\ninit_db()\n\napi_key = 'sk-' \nendpoint = 'https://api.deepseek.com/chat/completions' \n\ndef call_deepseek_api(question):\n headers = {\n 'Content-Type': 'application/json',\n 'Authorization': f'Bearer {api_key}'\n }\n data = {\n \"model\": \"deepseek-chat\", \n \"messages\": [\n {\"role\": \"system\", \"content\": \"你是一袋猫粮.\"},\n {\"role\": \"user\", \"content\": question}\n ],\n \"stream\": False\n }\n\n try:\n response = requests.post(endpoint, headers=headers, json=data)\n response.raise_for_status()\n bot_response = response.json()['choices'][0]['message']['content']\n print(f\"API 响应: {bot_response}\") \n return bot_response\n except requests.exceptions.RequestException as e:\n print(f\"API 调用失败: {str(e)}\") \n raise\n\n@app.route('/')\ndef index():\n return render_template('index.html')\n\n@app.route('/ask', methods=['POST'])\ndef ask():\n print(\"收到请求\") \n user_message = request.json.get('message')\n if not user_message:\n print(\"未提供消息\") \n return jsonify({'error': 'No message provided'}), 400\n\n print(f\"用户输入: {user_message}\") \n\n try:\n bot_response = call_deepseek_api(user_message)\n print(f\"Bot response: {bot_response}\") \n save_chat_history(user_message, bot_response)\n return jsonify({'response': bot_response})\n except Exception as e:\n return jsonify({'error': str(e)}), 500\n\ndef save_chat_history(user_message, bot_response):\n conn = sqlite3.connect('chat_history.db')\n cursor = conn.cursor()\n cursor.execute('''\n INSERT INTO chat_history (user_message, bot_response)\n VALUES (?, ?)\n ''', (user_message, bot_response))\n conn.commit()\n conn.close()\n\nif __name__ == '__main__':\n app.run(debug=True)"}}}}