{"id":98,"date":"2025-02-04T22:12:07","date_gmt":"2025-02-04T14:12:07","guid":{"rendered":"http:\/\/blog.sayoung.xyz\/?p=98"},"modified":"2026-02-10T15:27:55","modified_gmt":"2026-02-10T07:27:55","slug":"%e5%ad%a6%e4%b9%a0%e6%97%a5%e5%bf%97ai%e8%b0%83%e7%94%a82","status":"publish","type":"post","link":"https:\/\/blog.sayoung.wang\/index.php\/2025\/02\/04\/%e5%ad%a6%e4%b9%a0%e6%97%a5%e5%bf%97ai%e8%b0%83%e7%94%a82\/","title":{"rendered":"\u5b66\u4e60\u65e5\u5fd7|AI\u8c03\u7528(2)"},"content":{"rendered":"\n<p>24\u5e74\u5e74\u5e95\uff0c\u56e0\u4e3adeepseekV3\u7684\u7206\u706b\uff0c\u6211\u5f00\u59cb\u6ce8\u610f\u5230\u8fd9\u6837\u4e00\u4e2a\u6765\u8bf4\u6027\u4ef7\u6bd4\u6781\u9ad8\u7684\u5927\u6a21\u578b\uff0c\u4e8e\u662f\u7b2c\u4e00\u65f6\u95f4\u5c06\u5176\u63a5\u5165\u4e86\u6b64\u524d\u7f16\u5199\u7684QQ\u673a\u5668\u4eba\u63d2\u4ef6\u4e2d\u3002\u6700\u8fd1\u51e0\u5468\uff0c\u968f\u7740R1\u7248\u672c\u7684\u53d1\u5e03\uff0c\u6211\u53c8\u6709\u4e86\u5c1d\u8bd5\u672c\u5730\u90e8\u7f72\u84b8\u998f\u7248\u672c\u7684\u60f3\u6cd5\uff08\u4e0d\u8fc7\u4f30\u8ba1\u6700\u591a\u523014B Xp\uff09\u3002\u6b64\u5916\u6211\u4e5f\u6709\u4e00\u4e9b\u8ba9\u5176\u5bf9\u8bdd\u98ce\u683c\u66f4\u52a0\u8fd1\u4f3c\u4e8e\u4eba\u7c7b\u7684\u60f3\u6cd5\uff0c\u5c06\u5728\u8fd1\u671f\u8fdb\u884c\u5c1d\u8bd5\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from openai import OpenAI\nfrom nonebot import on_command,on_message\nfrom nonebot.rule import to_me\nfrom nonebot.adapters import Message\nfrom nonebot.params import CommandArg\nimport json,os\nfrom dotenv import load_dotenv\n\n# \u52a0\u8f7d.env\u6587\u4ef6\u4e2d\u7684\u73af\u5883\u53d8\u91cf\nload_dotenv()\n\napi_key = os.getenv(\"OPENAI_API_KEY\", \"default_key_if_not_set\")\n\njson_list = &#91;]\n#echo = on_command('ds', priority=5)\necho = on_message(rule=to_me(), priority=5)\n# for backward compatibility, you can still use `https:\/\/api.deepseek.com\/v1` as `base_url`.\nclient = OpenAI(api_key=api_key, base_url=\"https:\/\/api.deepseek.com\")\n\n@echo.handle()\nasync def handle_first_receive(args: Message = CommandArg()):\n\n    with open('demo_bot\/plugins\/DeepSeek\/deepseek_result.json', 'r', encoding= 'utf-8') as file:\n        json_list = json.load(file)\n\n    if len(json_list) == 11:\n        del json_list&#91;1]\n        del json_list&#91;1]\n\n    if len(json_list) == 0:\n        json_list = &#91;{\"role\": \"user\",\"content\":f\"{args}\"}]\n    else:\n        json_list.append({\"role\": \"user\",\"content\":f\"{args}\"})\n\n\n    response = client.chat.completions.create(\n        model=\"deepseek-chat\",\n        messages=json_list,\n        max_tokens=1024,\n        temperature=0.7,\n        stream=False\n    )\n\n    json_list.append({\"role\": \"assistant\",\"content\": f\"{response.choices&#91;0].message.content}\"})\n    with open('demo_bot\/plugins\/DeepSeek\/deepseek_result.json', 'w', encoding= 'utf-8') as f:\n        f.write(f\"{json.dumps(json_list,ensure_ascii=False)}\")\n    await echo.finish(response.choices&#91;0].message.content)\n\n\nclean = on_command('cl', priority=5)\n\n@clean.handle()\nasync def handle_first_receive():\n    with open('demo_bot\/plugins\/DeepSeek\/deepseek_result.json', 'r', encoding= 'utf-8') as file:\n        json_list = json.load(file)\n        json_list = json_list&#91;0]  \n    with open('demo_bot\/plugins\/DeepSeek\/deepseek_result.json', 'w', encoding= 'utf-8') as f:\n        f.write(f\"&#91;{json.dumps(json_list,ensure_ascii=False)}]\")\n    await clean.finish(\"\u8bb0\u5fc6\u5df2\u6e05\u9664\u3002\")\n\nrole = on_command('role', priority=5)\n\n@role.handle()\nasync def handle_first_receive(args: Message = CommandArg()):\n    with open('demo_bot\/plugins\/DeepSeek\/deepseek_result.json', 'r', encoding= 'utf-8') as file:\n        json_list = json.load(file)\n        json_list&#91;0] = {\"role\": \"system\", \"content\":f\"{args}\"}\n    with open('demo_bot\/plugins\/DeepSeek\/deepseek_result.json', 'w', encoding= 'utf-8') as f:\n        f.write(f\"{json.dumps(json_list,ensure_ascii=False)}\")\n    await role.finish(\"\u5df2\u91cd\u8bbe\u89d2\u8272\u3002\")<\/code><\/pre>\n\n\n\n<p>\u6b64\u5916\uff0c\u51fa\u4e8e\u5bf9diy\u4e00\u4e2a\u81ea\u52a8\u5bf9\u7126\u955c\u5934\u7684\u6267\u5ff5\uff08\u5f53\u521d\u4e00\u65f6\u51b2\u52a8\u82b1\u4e8650r\u4e70\u4e86\u4e2a\u7403\u673a\u955c\u5934\u56de\u6765\uff0c\u73b0\u5728\u8fd8\u5728\u5403\u7070\uff09\uff0c\u6211\u53c8\u7814\u7a76\u4e86\u81ea\u52a8\u5bf9\u7126\u7b97\u6cd5\uff08\u7136\u800c\u7531\u4e8e\u6781\u5ea6\u7f3a\u4e4f\u4e13\u4e1a\u77e5\u8bc6\uff0c\u5927\u90e8\u5206\u90fd\u662f\u770b\u4e0d\u61c2\u7684\u2026\u2026\uff09\uff0c\u5b66\u4e60\u4e86\u5982\u4f55\u8c03\u7528\u4eba\u8138\u68c0\u6d4b\u6a21\u578b\uff08\u5728deep seek\u7684\u5e2e\u52a9\u4e0b\uff09\uff0c\u672c\u7740Ctrl+C\/V\u7684\u7f16\u7a0b\u7cbe\u795e\uff08\uff09\uff0c\u52c9\u5f3a\u62fc\u51d1\u51fa\u4e86\u4e00\u4e2a\u7406\u8bba\u9a8c\u8bc1\u7248\u672c\uff0c\u7136\u800c\u6548\u679c\u5e76\u4e0d\u5c3d\u5982\u4eba\u610f\u3002\uff08\u8be6\u89c1\u4e0b\u4e00\u6761\u5b66\u4e60\u65e5\u5fd7\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>24\u5e74\u5e74\u5e95\uff0c\u56e0\u4e3adeepseekV3\u7684\u7206\u706b\uff0c\u6211\u5f00\u59cb\u6ce8\u610f\u5230\u8fd9\u6837\u4e00\u4e2a\u6765\u8bf4\u6027\u4ef7\u6bd4\u6781\u9ad8\u7684\u5927\u6a21\u578b\uff0c\u4e8e\u662f\u7b2c\u4e00\u65f6\u95f4\u5c06\u5176\u63a5\u5165\u4e86 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[12,7,6],"class_list":["post-98","post","type-post","status-publish","format-standard","hentry","category-11","tag-ai","tag-python","tag-qq"],"_links":{"self":[{"href":"https:\/\/blog.sayoung.wang\/index.php\/wp-json\/wp\/v2\/posts\/98","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.sayoung.wang\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.sayoung.wang\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.sayoung.wang\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.sayoung.wang\/index.php\/wp-json\/wp\/v2\/comments?post=98"}],"version-history":[{"count":1,"href":"https:\/\/blog.sayoung.wang\/index.php\/wp-json\/wp\/v2\/posts\/98\/revisions"}],"predecessor-version":[{"id":99,"href":"https:\/\/blog.sayoung.wang\/index.php\/wp-json\/wp\/v2\/posts\/98\/revisions\/99"}],"wp:attachment":[{"href":"https:\/\/blog.sayoung.wang\/index.php\/wp-json\/wp\/v2\/media?parent=98"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.sayoung.wang\/index.php\/wp-json\/wp\/v2\/categories?post=98"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.sayoung.wang\/index.php\/wp-json\/wp\/v2\/tags?post=98"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}