{"id":1326,"date":"2025-10-11T14:04:27","date_gmt":"2025-10-11T06:04:27","guid":{"rendered":"http:\/\/zhhovo.top\/?p=1326"},"modified":"2025-10-11T17:06:28","modified_gmt":"2025-10-11T09:06:28","slug":"%e5%85%b3%e4%ba%8e%e4%ba%ba%e5%b7%a5%e6%99%ba%e8%83%bd%e5%85%a8%e7%a8%8b%e6%9c%ac%e5%9c%b0%e6%89%a7%e8%a1%8c%e7%a8%8b%e5%ba%8f%e5%88%a4%e6%96%ad%e5%af%b9%e9%94%99%e7%9a%84%e7%8c%9c%e6%83%b3","status":"publish","type":"post","link":"https:\/\/zhhovo.top\/index.php\/2025\/10\/11\/%e5%85%b3%e4%ba%8e%e4%ba%ba%e5%b7%a5%e6%99%ba%e8%83%bd%e5%85%a8%e7%a8%8b%e6%9c%ac%e5%9c%b0%e6%89%a7%e8%a1%8c%e7%a8%8b%e5%ba%8f%e5%88%a4%e6%96%ad%e5%af%b9%e9%94%99%e7%9a%84%e7%8c%9c%e6%83%b3\/","title":{"rendered":"\u4eba\u5de5\u667a\u80fd\u8bed\u8a00\u6a21\u578b\u8f6c\u5316\u4e3a\u672c\u5730\u6267\u884c\u7a0b\u5e8f\u5e76\u5224\u65ad\u5b89\u5168\u6027"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"519\" src=\"https:\/\/zhhovo.top\/wp-content\/uploads\/2025\/10\/\u5c4f\u5e55\u622a\u56fe-2025-10-11-163936-1024x519.png\" alt=\"\" class=\"wp-image-1336\" srcset=\"https:\/\/zhhovo.top\/wp-content\/uploads\/2025\/10\/\u5c4f\u5e55\u622a\u56fe-2025-10-11-163936-1024x519.png 1024w, https:\/\/zhhovo.top\/wp-content\/uploads\/2025\/10\/\u5c4f\u5e55\u622a\u56fe-2025-10-11-163936-300x152.png 300w, https:\/\/zhhovo.top\/wp-content\/uploads\/2025\/10\/\u5c4f\u5e55\u622a\u56fe-2025-10-11-163936-768x389.png 768w, https:\/\/zhhovo.top\/wp-content\/uploads\/2025\/10\/\u5c4f\u5e55\u622a\u56fe-2025-10-11-163936-1536x778.png 1536w, https:\/\/zhhovo.top\/wp-content\/uploads\/2025\/10\/\u5c4f\u5e55\u622a\u56fe-2025-10-11-163936.png 1876w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">import os<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">import re<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">import subprocess<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">import requests<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">class DeepSeekCodeExecutor:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; def __init__(self):<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; # \u521d\u59cb\u5316\u914d\u7f6e<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; self.api_key = &#8220;sk-7dde69e642e740f081ae143323a01791&#8221; &nbsp;# \u8bf7\u66ff\u6362\u4e3a\u60a8\u7684\u771f\u5b9eAPI\u5bc6\u94a5<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; self.api_url = &#8220;https:\/\/api.deepseek.com\/v1\/chat\/completions&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; self.python_version = &#8220;3.13.7&#8221; &nbsp;# \u6307\u5b9a\u672c\u5730Python\u7248\u672c<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; def call_deepseek_api(self, prompt, is_safety_check=False):<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &#8220;&#8221;&#8221;\u8c03\u7528DeepSeek API\u5e76\u8fd4\u56de\u54cd\u5e94\u5185\u5bb9[1](@ref)&#8221;&#8221;&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; headers = {<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8220;Content-Type&#8221;: &#8220;application\/json&#8221;,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8220;Authorization&#8221;: f&#8221;Bearer {self.api_key}&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; }<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; data = {<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8220;model&#8221;: &#8220;deepseek-chat&#8221;,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8220;messages&#8221;: [{&#8220;role&#8221;: &#8220;user&#8221;, &#8220;content&#8221;: prompt}],<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8220;temperature&#8221;: 0.1 if is_safety_check else 0.7,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8220;max_tokens&#8221;: 50 if is_safety_check else 2000,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8220;stream&#8221;: False<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; }<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; try:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; response = requests.post(self.api_url, headers=headers, json=data, timeout=60)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if response.status_code == 200:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return response.json()[&#8220;choices&#8221;][0][&#8220;message&#8221;][&#8220;content&#8221;]<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(f&#8221; &nbsp; \u274c API\u8bf7\u6c42\u5931\u8d25\uff0c\u72b6\u6001\u7801: {response.status_code}&#8221;)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return None<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; except Exception as e:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(f&#8221; &nbsp; \u274c \u8c03\u7528API\u65f6\u53d1\u751f\u9519\u8bef: {str(e)}&#8221;)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return None<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; def extract_and_clean_code(self, raw_api_response):<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &#8220;&#8221;&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; \u6838\u5fc3\u4ee3\u7801\u6e05\u6d17\u51fd\u6570\uff1a\u5f7b\u5e95\u53bb\u9664Markdown\u4ee3\u7801\u5757\u6807\u8bb0[1,6,7](@ref)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; \u8fd9\u662f\u89e3\u51b3SyntaxError\u95ee\u9898\u7684\u5173\u952e\u6b65\u9aa4<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &#8220;&#8221;&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; if not raw_api_response:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return &#8220;&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; text = raw_api_response.strip()<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; print(&#8221; &nbsp; \ud83d\udd0d \u539f\u59cbAPI\u54cd\u5e94:&#8221;, text[:150] + &#8220;&#8230;&#8221; if len(text) &gt; 150 else text)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; # \u65b9\u6cd51\uff1a\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u7cbe\u786e\u63d0\u53d6 &#8220;`python &#8230; &#8220;` \u6216 &#8220;` &#8230; &#8220;` \u683c\u5f0f\u7684\u4ee3\u7801\u5757[1](@ref)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; code_block_pattern = r&#8217;&#8220;`(?:python)?\\s*(.*?)\\s*&#8220;`&#8217;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; matches = re.findall(code_block_pattern, text, re.DOTALL)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; if matches:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # \u6210\u529f\u63d0\u53d6\u4ee3\u7801\u5757\u5185\u5bb9<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cleaned_code = matches[0].strip()<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(&#8221; &nbsp; \u2705 \u5df2\u4ece\u4ee3\u7801\u5757\u4e2d\u63d0\u53d6\u7eaf\u51c0\u4ee3\u7801&#8221;)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; else:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # \u65b9\u6cd52\uff1a\u5982\u679c\u6b63\u5219\u5339\u914d\u5931\u8d25\uff0c\u8fdb\u884c\u6df1\u5ea6\u6e05\u7406[6](@ref)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(&#8221; &nbsp; \u26a0\ufe0f \u672a\u68c0\u6d4b\u5230\u6807\u51c6\u4ee3\u7801\u5757\u6807\u8bb0\uff0c\u8fdb\u884c\u6df1\u5ea6\u6e05\u7406&#8230;&#8221;)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cleaned_code = text<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # \u53bb\u9664\u884c\u9996\u548c\u884c\u5c3e\u7684\u5b64\u7acb\u7684 ` \u7b26\u53f7<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cleaned_code = re.sub(r&#8217;^`+|`+$&#8217;, &#8221;, cleaned_code, flags=re.MULTILINE)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # \u53bb\u9664\u53ef\u80fd\u88ab\u8bef\u5199\u4e3a\u6807\u8bb0\u7684\u884c<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cleaned_code = re.sub(r&#8217;^\\s*&#8220;`\\s*$&#8217;, &#8221;, cleaned_code, flags=re.MULTILINE)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; # \u901a\u7528\u6e05\u7406\u6b65\u9aa4\uff1a\u53bb\u9664\u591a\u4f59\u7a7a\u767d\u884c\u548c\u6b8b\u7559\u6807\u8bb0[7](@ref)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; cleaned_code = re.sub(r&#8217;^\\s*\\n&#8217;, &#8221;, cleaned_code) &nbsp;# \u5f00\u5934\u7684\u7a7a\u884c<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; cleaned_code = re.sub(r&#8217;\\n\\s*$&#8217;, &#8221;, cleaned_code) &nbsp;# \u7ed3\u5c3e\u7684\u7a7a\u884c<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; cleaned_code = re.sub(r&#8217;\\n\\s*\\n&#8217;, &#8216;\\n\\n&#8217;, cleaned_code) &nbsp;# \u5408\u5e76\u591a\u4e2a\u8fde\u7eed\u7a7a\u884c<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; return cleaned_code.strip()<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; def generate_code_prompt(self, user_input):<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &#8220;&#8221;&#8221;\u6784\u5efa\u4ee3\u7801\u751f\u6210\u8bf7\u6c42\u7684Prompt[1](@ref)&#8221;&#8221;&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; prompt = f&#8221;&#8221;&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8bf7\u5c06\u4ee5\u4e0b\u7528\u6237\u6307\u4ee4\u8f6c\u6362\u4e3a\u53ef\u6267\u884c\u7684Python {self.python_version} \u4ee3\u7801\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u91cd\u8981\u8981\u6c42\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1. \u53ea\u8f93\u51fa\u7eafPython\u4ee3\u7801\uff0c\u4e0d\u8981\u4efb\u4f55\u89e3\u91ca\u3001\u6ce8\u91ca\u6216Markdown\u4ee3\u7801\u5757\u6807\u8bb0\uff08\u5982&#8220;`python\uff09<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2. \u4ee3\u7801\u5fc5\u987b\u80fd\u591f\u76f4\u63a5\u6267\u884c<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">3. \u7528\u6237\u6307\u4ee4\uff1a{user_input}<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">4.\u5c3d\u91cf\u4e0d\u8981\u5f15\u7528\u4ec0\u4e48\u9700\u8981\u989d\u5916\u914d\u7f6e\u7684\u5e93\uff0c\u5982\u679c\u6709\uff0c\u8bf7\u5148\u5728\u4ee3\u7801\u91cc\u8fdb\u884c\u4e0b\u8f7d\u518d\u5f15\u7528\u5e93<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">5.\u5982\u679c\u6d89\u53ca\u56fe\u50cf\u5904\u7406\uff0c\u8bf7\u4f7f\u7528\u975e\u963b\u585e\u65b9\u5f0f\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp;&#8211; \u4f7f\u7528 matplotlib.use(&#8216;Agg&#8217;) \u8bbe\u7f6e\u975e\u4ea4\u4e92\u540e\u7aef<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp;&#8211; \u4f7f\u7528 plt.savefig() \u4ee3\u66ff plt.show()<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp;&#8211; \u907f\u514d\u4ea4\u4e92\u5f0f\u56fe\u5f62\u754c\u9762<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">6.\u786e\u4fdd\u4ee3\u7801\u80fd\u591f\u81ea\u52a8\u5904\u7406\u4f9d\u8d56\u5305\u5b89\u88c5<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8bf7\u4e25\u683c\u9075\u5b88\uff1a\u53ea\u8f93\u51faPython\u4ee3\u7801\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&#8220;&#8221;&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; return prompt<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; def safety_check_prompt(self, code):<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &#8220;&#8221;&#8221;\u6784\u5efa\u5b89\u5168\u68c0\u6d4b\u8bf7\u6c42\u7684Prompt&#8221;&#8221;&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; prompt = f&#8221;&#8221;&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8bf7\u4e25\u683c\u68c0\u67e5\u4ee5\u4e0bPython\u4ee3\u7801\u662f\u5426\u5b89\u5168\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5224\u65ad\u6807\u51c6\uff1a\u4ec5\u5f53\u4ee3\u7801\u5305\u542b\u76f4\u63a5\u7684\u7cfb\u7edf\u7834\u574f\u547d\u4ee4\uff08\u5982rm -rf \/\u3001format C:\uff09\u65f6\u56de\u590ddanger\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5141\u8bb8\u6b63\u5e38\u7684\u7cfb\u7edf\u8c03\u7528\u548c\u6587\u4ef6\u64cd\u4f5c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee3\u7801\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">{code}<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f60\u53ea\u9700\u8981\u56de\u590d\u4e00\u4e2a\u5355\u8bcd\uff1asafe \u6216 danger\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&#8220;&#8221;&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; return prompt<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; def execute_python_code(self, file_path):<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &#8220;&#8221;&#8221;\u6267\u884cPython\u4ee3\u7801\u6587\u4ef6\u5e76\u8fd4\u56de\u8f93\u51fa[1](@ref)&#8221;&#8221;&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; try:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result = subprocess.run(<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [&#8216;python&#8217;, file_path],<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; capture_output=True,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text=True,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; timeout=200,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; encoding=&#8217;utf-8&#8242;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; )<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; output = &#8220;&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if result.stdout:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; output += f&#8221;\u8f93\u51fa:\\n{result.stdout}\\n&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if result.stderr:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; output += f&#8221;\u9519\u8bef:\\n{result.stderr}\\n&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return output.strip()<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; except subprocess.TimeoutExpired:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return &#8220;\u9519\u8bef\uff1a\u4ee3\u7801\u6267\u884c\u8d85\u65f6\uff08\u8d85\u8fc7200\u79d2\uff09&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; except Exception as e:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return f&#8221;\u6267\u884c\u8fc7\u7a0b\u51fa\u9519\uff1a{str(e)}&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; def run(self):<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &#8220;&#8221;&#8221;\u4e3b\u7a0b\u5e8f\u6d41\u7a0b &#8211; \u6309\u7167\u7528\u6237\u8981\u6c42\u7684\u6b65\u9aa4\u6267\u884c&#8221;&#8221;&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; print(&#8220;=== DeepSeek \u4ee3\u7801\u6267\u884c\u5668\uff08\u4fee\u590d\u7248\uff09 ===&#8221;)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; print(&#8220;\u6d41\u7a0b\uff1a1.\u751f\u6210\u4ee3\u7801 \u2192 2.\u6e05\u6d17\u4ee3\u7801 \u2192 3.\u5b89\u5168\u68c0\u6d4b \u2192 4.\u6267\u884c&#8221;)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; print(&#8220;\u8bf7\u8f93\u5165\u60a8\u7684\u6307\u4ee4\uff08\u8f93\u5165&#8217;quit&#8217;\u9000\u51fa\u7a0b\u5e8f\uff09\uff1a&#8221;)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; while True:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user_input = input(&#8220;\\n&gt;&gt;&gt; &#8220;).strip()<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if user_input.lower() in [&#8216;quit&#8217;, &#8216;exit&#8217;, &#8216;\u9000\u51fa&#8217;]:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(&#8220;\u7a0b\u5e8f\u7ed3\u675f\u3002&#8221;)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if not user_input:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; continue<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(&#8220;\\n&#8221; + &#8220;=&#8221;*60)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # \u7b2c\u4e00\u6b65\uff1a\u5411DeepSeek\u53d1\u9001\u6307\u4ee4\u751f\u6210\u4ee3\u7801<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(&#8220;\u7b2c\u4e00\u6b65\uff1a\u5411DeepSeek\u53d1\u9001\u6307\u4ee4\u751f\u6210\u4ee3\u7801&#8230;&#8221;)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; code_prompt = self.generate_code_prompt(user_input)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; raw_code_response = self.call_deepseek_api(code_prompt)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if raw_code_response is None:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(&#8221; &nbsp; \u4ee3\u7801\u751f\u6210\u5931\u8d25\uff0c\u8bf7\u68c0\u67e5API\u8fde\u63a5\u3002&#8221;)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; continue<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(&#8221; &nbsp; \u4ee3\u7801\u751f\u6210\u5b8c\u6210&#8221;)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(&#8221; &nbsp; \u751f\u6210\u7684\u4ee3\u7801\uff1a&#8221;)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(&#8221; &nbsp; &#8221; + &#8220;=&#8221;*50)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(f&#8221; &nbsp; {raw_code_response}&#8221;)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(&#8221; &nbsp; &#8221; + &#8220;=&#8221;*50)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # \u7b2c\u4e8c\u6b65\uff1a\u4ee3\u7801\u6e05\u6d17 &#8211; \u8fd9\u662f\u65b0\u589e\u7684\u5173\u952e\u6b65\u9aa4<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(&#8220;\u7b2c\u4e8c\u6b65\uff1a\u8fdb\u884c\u4ee3\u7801\u6e05\u6d17&#8230;&#8221;)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; purified_code = self.extract_and_clean_code(raw_code_response)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # \u663e\u793a\u6e05\u6d17\u540e\u7684\u4ee3\u7801<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(&#8221; &nbsp; \u6e05\u6d17\u540e\u4ee3\u7801\u4e3a\uff1a&#8221;)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(&#8221; &nbsp; &#8221; + &#8220;=&#8221;*50)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(f&#8221; &nbsp; {purified_code}&#8221;)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(&#8221; &nbsp; &#8221; + &#8220;=&#8221;*50)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if not purified_code.strip():<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(&#8221; &nbsp; \u26a0\ufe0f \u8b66\u544a\uff1a\u6e05\u6d17\u540e\u4ee3\u7801\u4e3a\u7a7a\uff0c\u65e0\u6cd5\u7ee7\u7eed\u6267\u884c\u3002&#8221;)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; continue<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # \u7b2c\u4e09\u6b65\uff1a\u5b89\u5168\u68c0\u6d4b<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(&#8220;\u7b2c\u4e09\u6b65\uff1a\u8fdb\u884c\u4ee3\u7801\u5b89\u5168\u68c0\u67e5&#8230;&#8221;)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; safety_prompt = self.safety_check_prompt(purified_code)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; safety_result = self.call_deepseek_api(safety_prompt, is_safety_check=True)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if safety_result is None:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(&#8221; &nbsp; \u5b89\u5168\u68c0\u6d4b\u5931\u8d25\uff0c\u5df2\u4e2d\u6b62\u6267\u884c\u3002&#8221;)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; continue<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; safety_result = safety_result.strip().lower()<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(f&#8221; &nbsp; \u5b89\u5168\u68c0\u67e5\u7ed3\u679c\uff1a{safety_result}&#8221;)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # \u7b80\u5355\u7684\u672c\u5730\u8f85\u52a9\u68c0\u67e5[2](@ref)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; danger_keywords = [&#8216;rm -rf&#8217;, &#8216;format c:&#8217;, &#8216;dd if=\/dev\/zero&#8217;]<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; local_safety = &#8220;safe&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for keyword in danger_keywords:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if keyword in purified_code.lower():<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; local_safety = &#8220;danger&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(f&#8221; &nbsp; \u672c\u5730\u8f85\u52a9\u68c0\u67e5\u7ed3\u679c\uff1a{local_safety}&#8221;)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if safety_result == &#8220;danger&#8221; or local_safety == &#8220;danger&#8221;:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(&#8221; &nbsp; \u274c \u547d\u4ee4\u5a01\u80c1\u7cfb\u7edf\u5b89\u5168\uff0c\u53d7\u5230\u62e6\u622a\u3002&#8221;)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; continue<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # \u7b2c\u56db\u6b65\uff1a\u6267\u884c\u4ee3\u7801<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(&#8220;\u7b2c\u56db\u6b65\uff1a\u6267\u884c\u751f\u6210\u7684\u4ee3\u7801&#8230;&#8221;)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; temp_file = &#8220;start.py&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; try:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; with open(temp_file, &#8216;w&#8217;, encoding=&#8217;utf-8&#8242;) as f:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; f.write(purified_code)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; execution_result = self.execute_python_code(temp_file)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(&#8221; &nbsp; \u6267\u884c\u5b8c\u6210\uff0c\u7ed3\u679c\u5982\u4e0b\uff1a&#8221;)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(&#8221; &nbsp; &#8221; + &#8220;=&#8221;*50)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if execution_result:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(f&#8221; &nbsp; {execution_result}&#8221;)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(&#8221; &nbsp; Python script executed successfully&#8221;)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(&#8221; &nbsp; &#8221; + &#8220;=&#8221;*50)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; except Exception as e:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(f&#8221; &nbsp; \u274c \u6267\u884c\u8fc7\u7a0b\u4e2d\u53d1\u751f\u9519\u8bef\uff1a{e}&#8221;)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; finally:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # \u6e05\u7406\u4e34\u65f6\u6587\u4ef6<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if os.path.exists(temp_file):<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; os.remove(temp_file)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(&#8221; &nbsp; \u4e34\u65f6\u6587\u4ef6\u5df2\u6e05\u7406\u3002&#8221;)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">if __name__ == &#8220;__main__&#8221;:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; executor = DeepSeekCodeExecutor()<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; executor.run()<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5199\u5165py\u6587\u4ef6\u8fd0\u884c\u5373\u53ef\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"523\" src=\"https:\/\/zhhovo.top\/wp-content\/uploads\/2025\/10\/\u5c4f\u5e55\u622a\u56fe-2025-10-11-161816-1024x523.png\" alt=\"\" class=\"wp-image-1330\" srcset=\"https:\/\/zhhovo.top\/wp-content\/uploads\/2025\/10\/\u5c4f\u5e55\u622a\u56fe-2025-10-11-161816-1024x523.png 1024w, https:\/\/zhhovo.top\/wp-content\/uploads\/2025\/10\/\u5c4f\u5e55\u622a\u56fe-2025-10-11-161816-300x153.png 300w, https:\/\/zhhovo.top\/wp-content\/uploads\/2025\/10\/\u5c4f\u5e55\u622a\u56fe-2025-10-11-161816-768x392.png 768w, https:\/\/zhhovo.top\/wp-content\/uploads\/2025\/10\/\u5c4f\u5e55\u622a\u56fe-2025-10-11-161816.png 1501w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b8c\u6574\u6d41\u7a0b\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">PS C:\\Users\\ZHHQZS&gt; &amp; C:\/Users\/ZHHQZS\/AppData\/Local\/Programs\/Python\/Python313\/python.exe c:\/Users\/ZHHQZS\/Desktop\/my_ai\/my_ai_allai\/main.py<br>=== DeepSeek \u4ee3\u7801\u6267\u884c\u5668\uff08\u4fee\u590d\u7248\uff09 ===<br>\u6d41\u7a0b\uff1a1.\u751f\u6210\u4ee3\u7801 \u2192 2.\u6e05\u6d17\u4ee3\u7801 \u2192 3.\u5b89\u5168\u68c0\u6d4b \u2192 4.\u6267\u884c<br>\u8bf7\u8f93\u5165\u60a8\u7684\u6307\u4ee4\uff08\u8f93\u5165&#8217;quit&#8217;\u9000\u51fa\u7a0b\u5e8f\uff09\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\u7528\u672c\u5730windows10\u81ea\u5e26\u7684\u56fe\u7247\u5de5\u5177\u6253\u5f00C:\\Users\\ZHHQZS\\Desktop\\my_ai\\my_ai_allai\u76ee\u5f55\u4e0b\u7684aac.jpg<\/p>\n<\/blockquote>\n<\/blockquote>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">============================================================<br>\u7b2c\u4e00\u6b65\uff1a\u5411DeepSeek\u53d1\u9001\u6307\u4ee4\u751f\u6210\u4ee3\u7801\u2026<br>\u4ee3\u7801\u751f\u6210\u5b8c\u6210<br>\u751f\u6210\u7684\u4ee3\u7801\uff1a<br>==================================================<br>import os<br>import sys<br>import subprocess<br>import importlib.util<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">def install_and_import(package, import_name=None):<br>if import_name is None:<br>import_name = package<br>try:<br>importlib.import_module(import_name)<br>except ImportError:<br>print(f&#8221;\u6b63\u5728\u5b89\u88c5 {package}\u2026&#8221;)<br>subprocess.check_call([sys.executable, &#8220;-m&#8221;, &#8220;pip&#8221;, &#8220;install&#8221;, package])<br>globals()[import_name] = importlib.import_module(import_name)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">def open_image_with_default_viewer(image_path):<br>if os.name == &#8216;nt&#8217;:<br>os.startfile(image_path)<br>elif sys.platform == &#8216;darwin&#8217;:<br>subprocess.call([&#8216;open&#8217;, image_path])<br>else:<br>subprocess.call([&#8216;xdg-open&#8217;, image_path])<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">image_path = r&#8221;C:\\Users\\ZHHQZS\\Desktop\\my_ai\\my_ai_allai\\aac.jpg&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">if os.path.exists(image_path):<br>open_image_with_default_viewer(image_path)<br>else:<br>print(f&#8221;\u6587\u4ef6\u4e0d\u5b58\u5728: {image_path}&#8221;)<br>==================================================<br>\u7b2c\u4e8c\u6b65\uff1a\u8fdb\u884c\u4ee3\u7801\u6e05\u6d17\u2026<br>\ud83d\udd0d \u539f\u59cbAPI\u54cd\u5e94: import os<br>import sys<br>import subprocess<br>import importlib.util<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">def install_and_import(package, import_name=None):<br>if import_name is None:<br>i\u2026<br>\u26a0\ufe0f \u672a\u68c0\u6d4b\u5230\u6807\u51c6\u4ee3\u7801\u5757\u6807\u8bb0\uff0c\u8fdb\u884c\u6df1\u5ea6\u6e05\u7406\u2026<br>\u6e05\u6d17\u540e\u4ee3\u7801\u4e3a\uff1a<br>==================================================<br>import os<br>import sys<br>import subprocess<br>import importlib.util<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">def install_and_import(package, import_name=None):<br>if import_name is None:<br>import_name = package<br>try:<br>importlib.import_module(import_name)<br>except ImportError:<br>print(f&#8221;\u6b63\u5728\u5b89\u88c5 {package}\u2026&#8221;)<br>subprocess.check_call([sys.executable, &#8220;-m&#8221;, &#8220;pip&#8221;, &#8220;install&#8221;, package])<br>globals()[import_name] = importlib.import_module(import_name)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">def open_image_with_default_viewer(image_path):<br>if os.name == &#8216;nt&#8217;:<br>os.startfile(image_path)<br>elif sys.platform == &#8216;darwin&#8217;:<br>subprocess.call([&#8216;open&#8217;, image_path])<br>else:<br>subprocess.call([&#8216;xdg-open&#8217;, image_path])<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">image_path = r&#8221;C:\\Users\\ZHHQZS\\Desktop\\my_ai\\my_ai_allai\\aac.jpg&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">if os.path.exists(image_path):<br>open_image_with_default_viewer(image_path)<br>else:<br>print(f&#8221;\u6587\u4ef6\u4e0d\u5b58\u5728: {image_path}&#8221;)<br>==================================================<br>\u7b2c\u4e09\u6b65\uff1a\u8fdb\u884c\u4ee3\u7801\u5b89\u5168\u68c0\u67e5\u2026<br>\u5b89\u5168\u68c0\u67e5\u7ed3\u679c\uff1asafe<br>\u672c\u5730\u8f85\u52a9\u68c0\u67e5\u7ed3\u679c\uff1asafe<br>\u7b2c\u56db\u6b65\uff1a\u6267\u884c\u751f\u6210\u7684\u4ee3\u7801\u2026<br>\u6267\u884c\u5b8c\u6210\uff0c\u7ed3\u679c\u5982\u4e0b\uff1a<br>==================================================<br>Python script executed successfully<br>==================================================<br>\u4e34\u65f6\u6587\u4ef6\u5df2\u6e05\u7406\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">&gt;<\/p>\n<\/blockquote>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>import os import re import subprocess import requests c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1336,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1326","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/zhhovo.top\/index.php\/wp-json\/wp\/v2\/posts\/1326","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zhhovo.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhhovo.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhhovo.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zhhovo.top\/index.php\/wp-json\/wp\/v2\/comments?post=1326"}],"version-history":[{"count":10,"href":"https:\/\/zhhovo.top\/index.php\/wp-json\/wp\/v2\/posts\/1326\/revisions"}],"predecessor-version":[{"id":1340,"href":"https:\/\/zhhovo.top\/index.php\/wp-json\/wp\/v2\/posts\/1326\/revisions\/1340"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/zhhovo.top\/index.php\/wp-json\/wp\/v2\/media\/1336"}],"wp:attachment":[{"href":"https:\/\/zhhovo.top\/index.php\/wp-json\/wp\/v2\/media?parent=1326"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhhovo.top\/index.php\/wp-json\/wp\/v2\/categories?post=1326"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhhovo.top\/index.php\/wp-json\/wp\/v2\/tags?post=1326"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}