{"id":2171,"date":"2025-06-27T14:55:35","date_gmt":"2025-06-27T06:55:35","guid":{"rendered":"https:\/\/www.madbull.site\/?p=2171"},"modified":"2025-06-27T15:02:33","modified_gmt":"2025-06-27T07:02:33","slug":"ai%e6%8e%a5%e5%8f%a3%e4%bd%bf%e7%94%a8-%e9%98%bf%e9%87%8c%e4%ba%91%e7%99%be%e7%82%bc","status":"publish","type":"post","link":"https:\/\/www.madbull.site\/?p=2171","title":{"rendered":"AI\u63a5\u53e3\u4f7f\u7528&#8211;\u963f\u91cc\u4e91\u767e\u70bc"},"content":{"rendered":"\n<p>\u6700\u8fd1\u5f00\u53d1\u4e86\u4e00\u4e2a\u6296\u97f3AI\u8d77\u540d\u5c0f\u7a0b\u5e8f\uff0c\u5df2\u7ecf\u5728\u6296\u97f3\u4e0a\u7ebf\u4e86\uff0c\u6b22\u8fce\u5927\u5bb6\u6765\u4f7f\u7528\u3002\u5176\u4e2d\u7528\u5230\u4e86 AI\u6587\u672c\u751f\u6210 \u529f\u80fd\uff0c\u6211\u7528\u7684\u662f <strong>\u963f\u91cc\u4e91\u767e\u70bc<\/strong> \u63d0\u4f9b\u7684\u6587\u672c\u6a21\u578b\uff0c\u5206\u4eab\u4e00\u4e0b\u4f7f\u7528\u65b9\u6cd5\u3002<\/p>\n\n\n\n<div style=\"margin-top:var(--wp--preset--spacing--30);margin-bottom:var(--wp--preset--spacing--30);height:0px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>\u6253\u5f00\u6296\u97f3\uff0c\u626b\u4e8c\u7ef4\u7801\u5c31\u53ef\u4ee5\u6253\u5f00\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1125\" height=\"1680\" src=\"https:\/\/www.madbull.site\/wp-content\/uploads\/2025\/06\/111.jpg\" alt=\"\" class=\"wp-image-2174\" style=\"width:311px;height:auto\"\/><\/figure>\n\n\n\n<div style=\"margin-top:var(--wp--preset--spacing--30);margin-bottom:var(--wp--preset--spacing--30);height:0px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-large-font-size\"><strong>\u7b2c\u4e00\u6b65\u3001\u83b7\u53d6API-Key<\/strong><\/p>\n\n\n\n<div style=\"margin-top:var(--wp--preset--spacing--30);margin-bottom:var(--wp--preset--spacing--30);height:0px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-medium-font-size\">\u9700\u8981\u53bb\u963f\u91cc\u4e91\u767e\u70bc\u6ce8\u518c\u4e00\u4e2a\u8d26\u53f7\u3002<\/p>\n\n\n\n<p>\u53ef\u4ee5\u81ea\u884c\u6ce8\u518c\uff0c\u7f51\u5740\uff1a<a href=\"https:\/\/bailian.console.aliyun.com\/?tab=app#\/app-market\/newTemplate\">https:\/\/bailian.console.aliyun.com\/?tab=app#\/app-market\/newTemplate<\/a><\/p>\n\n\n\n<p>\u6ce8\u518c\u540e\uff0c\u627e\u5230 API-Key \u7533\u8bf7\u4e00\u4e2a\u3002\u4e4b\u540e\u548c <strong>\u963f\u91cc\u4e91\u767e\u70bc<\/strong> \u5e73\u53f0\u901a\u8baf\uff0c\u5c31\u662f\u901a\u8fc7\u8fd9\u4e2a API-Key \u6807\u8bc6\u7684\u3002<\/p>\n\n\n\n<div style=\"margin-top:var(--wp--preset--spacing--30);margin-bottom:var(--wp--preset--spacing--30);height:0px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-x-large-font-size\"><strong>\u7b2c\u4e8c\u6b65\u3001\u5b89\u88c5SDK<\/strong><\/p>\n\n\n\n<div style=\"margin-top:var(--wp--preset--spacing--30);margin-bottom:var(--wp--preset--spacing--30);height:0px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>\u5b89\u88c5SDK\u3002\u6211\u4f7f\u7528python\u5f00\u53d1\uff0c\u5b89\u88c5\u4e86 DashScope \u5e93\u5c31\u53ef\u4ee5\u4e86\uff0c\u4f7f\u7528pip\u5373\u53ef\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip install -U dashscope<\/code><\/pre>\n\n\n\n<div style=\"margin-top:var(--wp--preset--spacing--30);margin-bottom:var(--wp--preset--spacing--30);height:0px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>\u53c2\u8003\u5b98\u65b9\u6587\u6863\uff1a<a href=\"https:\/\/bailian.console.aliyun.com\/?tab=api#\/api\/?type=model&amp;url=https%3A%2F%2Fhelp.aliyun.com%2Fdocument_detail%2F2712193.html\">https:\/\/bailian.console.aliyun.com\/?tab=api#\/api\/?type=model&amp;url=https%3A%2F%2Fhelp.aliyun.com%2Fdocument_detail%2F2712193.html<\/a><\/p>\n\n\n\n<div style=\"margin-top:var(--wp--preset--spacing--30);margin-bottom:var(--wp--preset--spacing--30);height:0px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-x-large-font-size\"><strong>\u7b2c\u4e09\u6b65\u3001API\u8c03\u7528<\/strong><\/p>\n\n\n\n<div style=\"margin-top:var(--wp--preset--spacing--30);margin-bottom:var(--wp--preset--spacing--30);height:0px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>\u9009\u5b9a\u4e00\u4e2a\u6587\u672c\u6a21\u578b\uff0c\u6309\u7167\u63a5\u53e3\u683c\u5f0f\u5f00\u53d1\u5373\u53ef\u3002<\/p>\n\n\n\n<p>\u53c2\u8003\u5b98\u65b9\u6587\u6863\uff1a<a href=\"https:\/\/bailian.console.aliyun.com\/?tab=api#\/api\/?type=model&amp;url=https%3A%2F%2Fhelp.aliyun.com%2Fdocument_detail%2F2712576.html\">https:\/\/bailian.console.aliyun.com\/?tab=api#\/api\/?type=model&amp;url=https%3A%2F%2Fhelp.aliyun.com%2Fdocument_detail%2F2712576.html<\/a><\/p>\n\n\n\n<div style=\"margin-top:var(--wp--preset--spacing--30);margin-bottom:var(--wp--preset--spacing--30);height:0px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># -*- coding: utf-8 -*-\n\nimport dashscope\n\n#model=\"qwen-max\"\n#model=\"qwen-plus\"\n#model=\"deepseek-v3\"\n#model=\"qwen3-235b-a22b\"\n#model=\"qwen-plus-latest\"\nmodel=\"qwen-plus-2025-04-28\"      # \u8fd9\u91cc\u7684\u6a21\u578b\u81ea\u5df1\u5728\u5e73\u53f0\u9009\u62e9\napi_key=\"sk-xxxxxxxxxxxxxxxxxxxxxxxx\"  # \u8fd9\u91cc\u66ff\u6362\u4f60\u81ea\u5df1\u7533\u8bf7\u7684API-Key\n\ndef tongyi_ask(sys_content, user_content, temperature=1.2) :\n\n    messages = &#91;\n        {'role': 'system', 'content': sys_content},\n        {'role': 'user', 'content': user_content}\n        ]\n    response = dashscope.Generation.call(\n        api_key = api_key,\n        model=model,\n        messages=messages,\n        result_format='message',\n        enable_thinking=False,\n        temperature=temperature\n        )\n\n    if 'output' in response :\n        if 'choices' in response&#91;'output'] :\n            if len(response&#91;'output']&#91;'choices']) &gt;= 1:\n                if 'message' in response&#91;'output']&#91;'choices']&#91;0] :\n                    if 'content' in response&#91;'output']&#91;'choices']&#91;0]&#91;'message'] :\n                        resp = response&#91;'output']&#91;'choices']&#91;0]&#91;'message']&#91;'content']\n                        # \u53bb\u6389\u524d\u7f00\n                        offset = resp.find(\"```json\")\n                        if offset &gt; 0 :\n                            resp = resp&#91;offset+7:]\n                            # \u53bb\u6389\u540e\u7f00\n                            offset = resp.find(\"```\")\n                            if offset &gt; 0 :\n                                resp = resp&#91;:offset]\n                        return resp\n\n    return None\n\n\nif __name__ == \"__main__\":\n    \n    resp = tongyi_ask(\"\", \"\u4f60\u662f\u8c01\")\n    print(resp)<\/code><\/pre>\n\n\n\n<div style=\"margin-top:var(--wp--preset--spacing--30);margin-bottom:var(--wp--preset--spacing--30);height:0px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-x-large-font-size\"><strong>\u7b2c\u56db\u6b65\u3001\u6d4b\u8bd5<\/strong><\/p>\n\n\n\n<div style=\"margin-top:var(--wp--preset--spacing--30);margin-bottom:var(--wp--preset--spacing--30);height:0px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"681\" height=\"78\" src=\"https:\/\/www.madbull.site\/wp-content\/uploads\/2025\/06\/1-3.png\" alt=\"\" class=\"wp-image-2172\"\/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u7528\u5230\u4e86 AI\u6587\u672c\u751f\u6210 \u529f\u80fd\uff0c\u6211\u7528\u7684\u662f \u963f\u91cc\u4e91\u767e\u70bc \u63d0\u4f9b\u7684\u6587\u672c\u6a21\u578b\uff0c\u672c\u6587\u5206\u4eab\u4e00\u4e0b\u4f7f\u7528\u65b9\u6cd5\u3002<\/p>\n","protected":false},"author":1,"featured_media":1993,"comment_status":"open","ping_status":"open","sticky":false,"template":"single-with-sidebar","format":"standard","meta":{"footnotes":""},"categories":[166,154],"tags":[642,671],"class_list":["post-2171","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tools","category-154","tag-ai","tag-671"],"_links":{"self":[{"href":"https:\/\/www.madbull.site\/index.php?rest_route=\/wp\/v2\/posts\/2171","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.madbull.site\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.madbull.site\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.madbull.site\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.madbull.site\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2171"}],"version-history":[{"count":3,"href":"https:\/\/www.madbull.site\/index.php?rest_route=\/wp\/v2\/posts\/2171\/revisions"}],"predecessor-version":[{"id":2176,"href":"https:\/\/www.madbull.site\/index.php?rest_route=\/wp\/v2\/posts\/2171\/revisions\/2176"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.madbull.site\/index.php?rest_route=\/wp\/v2\/media\/1993"}],"wp:attachment":[{"href":"https:\/\/www.madbull.site\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2171"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.madbull.site\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2171"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.madbull.site\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2171"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}