{"id":8155,"date":"2024-11-04T16:06:52","date_gmt":"2024-11-04T08:06:52","guid":{"rendered":"https:\/\/www.aisharenet.com\/?p=8155"},"modified":"2024-11-29T18:56:40","modified_gmt":"2024-11-29T10:56:40","slug":"openai-yuantishizhiai","status":"publish","type":"post","link":"https:\/\/www.kdjingpai.com\/pt\/openai-yuantishizhiai\/","title":{"rendered":"OpenAI \u5143\u63d0\u793a\u6307\u4ee4\u751f\u6210\u5668 OpenAI Meta-prompt"},"content":{"rendered":"<h1>\u63d0\u793a\u751f\u6210<\/h1>\n<p>\u5728\u00a0<a href=\"https:\/\/platform.openai.com\/playground\/chat\">Playground<\/a>\u00a0\u4e2d\u7684\u00a0<strong>Generate<\/strong>\u00a0\u6309\u94ae\u8ba9\u60a8\u53ef\u4ee5\u901a\u8fc7\u4efb\u52a1\u63cf\u8ff0\u751f\u6210\u63d0\u793a\u3001<a href=\"https:\/\/platform.openai.com\/docs\/guides\/function-calling\">\u51fd\u6570<\/a>\u548c<a href=\"https:\/\/platform.openai.com\/docs\/guides\/structured-outputs#supported-schemas\">\u67b6\u6784<\/a>\u3002\u672c\u6307\u5357\u5c06\u9010\u6b65\u8bb2\u89e3\u5176\u5de5\u4f5c\u539f\u7406\u3002<\/p>\n<h2>\u6982\u8ff0<\/h2>\n<p>\u4ece\u5934\u521b\u5efa\u63d0\u793a\u548c\u67b6\u6784\u53ef\u80fd\u8017\u65f6\uff0c\u901a\u8fc7\u751f\u6210\u5b83\u4eec\u53ef\u4ee5\u5e2e\u52a9\u60a8\u5feb\u901f\u5165\u624b\u3002Generate \u6309\u94ae\u4e3b\u8981\u4f7f\u7528\u4ee5\u4e0b\u4e24\u79cd\u65b9\u6cd5\uff1a<\/p>\n<ol>\n<li><strong>\u63d0\u793a<\/strong>\uff1a\u6211\u4eec\u4f7f\u7528<strong>\u5143\u63d0\u793a<\/strong>\u7ed3\u5408\u6700\u4f73\u5b9e\u8df5\u6765\u751f\u6210\u6216\u6539\u8fdb\u63d0\u793a\u3002<\/li>\n<li><strong>\u67b6\u6784<\/strong>\uff1a\u6211\u4eec\u4f7f\u7528<strong>\u5143\u67b6\u6784<\/strong>\u751f\u6210\u6709\u6548\u7684 JSON \u548c\u51fd\u6570\u8bed\u6cd5\u3002<\/li>\n<\/ol>\n<p>\u5f53\u524d\u6211\u4eec\u4f7f\u7528\u5143\u63d0\u793a\u548c\u67b6\u6784\uff0c\u4f46\u672a\u6765\u53ef\u80fd\u4f1a\u96c6\u6210\u66f4\u591a\u9ad8\u7ea7\u6280\u672f\uff0c\u4f8b\u5982\u00a0<a href=\"https:\/\/arxiv.org\/abs\/2310.03714\">DSPy<\/a>\u00a0\u548c\u00a0<a href=\"https:\/\/arxiv.org\/abs\/2305.03495\">&#8220;\u68af\u5ea6\u4e0b\u964d&#8221;<\/a>\u3002<\/p>\n<h2>\u63d0\u793a<\/h2>\n<p><strong>\u5143\u63d0\u793a<\/strong>\u00a0\u6307\u5bfc\u6a21\u578b\u6839\u636e\u60a8\u7684\u4efb\u52a1\u63cf\u8ff0\u521b\u5efa\u51fa\u8272\u7684\u63d0\u793a\u6216\u6539\u8fdb\u73b0\u6709\u63d0\u793a\u3002Playground \u4e2d\u7684\u5143\u63d0\u793a\u6e90\u81ea\u6211\u4eec\u7684\u00a0<a href=\"https:\/\/platform.openai.com\/docs\/guides\/prompt-engineering\">\u63d0\u793a\u5de5\u7a0b<\/a>\u6700\u4f73\u5b9e\u8df5\u548c\u7528\u6237\u7684\u5b9e\u9645\u7ecf\u9a8c\u3002<\/p>\n<p>\u6211\u4eec\u9488\u5bf9\u4e0d\u540c\u7684\u8f93\u51fa\u7c7b\u578b\uff08\u5982\u97f3\u9891\uff09\u4f7f\u7528\u7279\u5b9a\u7684\u5143\u63d0\u793a\uff0c\u4ee5\u786e\u4fdd\u751f\u6210\u7684\u63d0\u793a\u7b26\u5408\u9884\u671f\u683c\u5f0f\u3002<\/p>\n<h3>\u5143\u63d0\u793a<\/h3>\n<p><strong>\u6587\u672c\u5143\u63d0\u793a<\/strong><\/p>\n<pre><code>from openai import OpenAI\r\n\r\nclient = OpenAI()\r\n\r\nMETA_PROMPT = \"\"\"\r\n\u6839\u636e\u4efb\u52a1\u63cf\u8ff0\u6216\u73b0\u6709\u63d0\u793a\uff0c\u751f\u6210\u4e00\u4e2a\u8be6\u7ec6\u7684\u7cfb\u7edf\u63d0\u793a\uff0c\u4ee5\u6709\u6548\u6307\u5bfc\u8bed\u8a00\u6a21\u578b\u5b8c\u6210\u4efb\u52a1\u3002\r\n\r\n# \u6307\u5bfc\u539f\u5219\r\n\r\n- \u7406\u89e3\u4efb\u52a1\uff1a\u638c\u63e1\u4e3b\u8981\u76ee\u6807\u3001\u76ee\u6807\u3001\u9700\u6c42\u3001\u9650\u5236\u548c\u9884\u671f\u8f93\u51fa\u3002\r\n- \u6700\u5c0f\u6539\u52a8\uff1a\u5982\u679c\u63d0\u4f9b\u4e86\u73b0\u6709\u63d0\u793a\uff0c\u4ec5\u5728\u5176\u7b80\u5355\u65f6\u8fdb\u884c\u6539\u8fdb\u3002\u5bf9\u4e8e\u590d\u6742\u7684\u63d0\u793a\uff0c\u589e\u5f3a\u6e05\u6670\u5ea6\u5e76\u6dfb\u52a0\u7f3a\u5931\u5143\u7d20\uff0c\u800c\u4e0d\u66f4\u6539\u539f\u59cb\u7ed3\u6784\u3002\r\n- \u63a8\u7406\u5728\u7ed3\u8bba\u524d**\uff1a\u9f13\u52b1\u5728\u5f97\u51fa\u7ed3\u8bba\u524d\u8fdb\u884c\u63a8\u7406\u6b65\u9aa4\u3002\u6ce8\u610f\uff01\u5982\u679c\u7528\u6237\u63d0\u4f9b\u7684\u793a\u4f8b\u5148\u6709\u63a8\u7406\u540e\u6709\u7ed3\u8bba\uff0c\u53cd\u8f6c\u987a\u5e8f\uff01\u7edd\u4e0d\u8981\u4ee5\u7ed3\u8bba\u5f00\u5934\u3002\r\n    - \u63a8\u7406\u987a\u5e8f\uff1a\u6307\u51fa\u63d0\u793a\u4e2d\u7684\u63a8\u7406\u90e8\u5206\u548c\u7ed3\u8bba\u90e8\u5206\uff08\u6309\u5b57\u6bb5\u540d\u79f0\uff09\uff0c\u786e\u5b9a\u5b8c\u6210\u7684\u987a\u5e8f\uff0c\u5fc5\u8981\u65f6\u53cd\u8f6c\u3002\r\n    - \u7ed3\u8bba\u3001\u5206\u7c7b\u6216\u7ed3\u679c\u5e94\u59cb\u7ec8\u51fa\u73b0\u5728\u6700\u540e\u3002\r\n- \u793a\u4f8b\uff1a\u5982\u679c\u6709\u5e2e\u52a9\uff0c\u5305\u542b\u9ad8\u8d28\u91cf\u793a\u4f8b\uff0c\u4f7f\u7528[\u65b9\u62ec\u53f7]\u4f5c\u4e3a\u590d\u6742\u5143\u7d20\u7684\u5360\u4f4d\u7b26\u3002\r\n   - \u8003\u8651\u54ea\u4e9b\u793a\u4f8b\u9700\u8981\u5305\u62ec\u3001\u6570\u91cf\u591a\u5c11\uff0c\u53ca\u662f\u5426\u590d\u6742\u5230\u9700\u8981\u5360\u4f4d\u7b26\u3002\r\n- \u6e05\u6670\u7b80\u6d01\uff1a\u4f7f\u7528\u6e05\u6670\u3001\u5177\u4f53\u7684\u8bed\u8a00\u3002\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u6307\u4ee4\u6216\u7a7a\u6d1e\u9648\u8ff0\u3002\r\n- \u683c\u5f0f\uff1a\u4f7f\u7528 Markdown \u7279\u6027\u4ee5\u63d0\u9ad8\u53ef\u8bfb\u6027\u3002\u9664\u975e\u660e\u786e\u8981\u6c42\uff0c\u5426\u5219\u4e0d\u8981\u4f7f\u7528 ``` \u4ee3\u7801\u5757\u3002\r\n- \u4fdd\u7559\u7528\u6237\u5185\u5bb9\uff1a\u5982\u679c\u8f93\u5165\u4efb\u52a1\u6216\u63d0\u793a\u5305\u62ec\u5e7f\u6cdb\u7684\u6307\u5bfc\u6216\u793a\u4f8b\uff0c\u5c3d\u53ef\u80fd\u5b8c\u6574\u4fdd\u7559\u5b83\u4eec\u3002\u5982\u679c\u5185\u5bb9\u542b\u7cca\u4e0d\u6e05\uff0c\u8003\u8651\u5c06\u5176\u5206\u89e3\u4e3a\u5b50\u6b65\u9aa4\u3002\u4fdd\u7559\u7528\u6237\u63d0\u4f9b\u7684\u6240\u6709\u7ec6\u8282\u3001\u6307\u5bfc\u3001\u793a\u4f8b\u3001\u53d8\u91cf\u6216\u5360\u4f4d\u7b26\u3002\r\n- \u5e38\u91cf\uff1a\u5728\u63d0\u793a\u4e2d\u5305\u542b\u5e38\u91cf\uff0c\u5b83\u4eec\u4e0d\u6613\u53d7\u63d0\u793a\u6ce8\u5165\u5f71\u54cd\uff0c\u5982\u6307\u5357\u3001\u8bc4\u5206\u6807\u51c6\u548c\u793a\u4f8b\u3002\r\n- \u8f93\u51fa\u683c\u5f0f\uff1a\u660e\u786e\u6700\u5408\u9002\u7684\u8f93\u51fa\u683c\u5f0f\uff0c\u5305\u62ec\u957f\u5ea6\u548c\u8bed\u6cd5\uff08\u5982\u77ed\u53e5\u3001\u6bb5\u843d\u3001JSON \u7b49\uff09\u3002\r\n    - \u5bf9\u8f93\u51fa\u4e3a\u7ed3\u6784\u5316\u6570\u636e\uff08\u5982\u5206\u7c7b\u3001JSON \u7b49\uff09\u7684\u4efb\u52a1\uff0c\u4f18\u5148\u751f\u6210 JSON\u3002\r\n    - JSON \u4e0d\u5e94\u5305\u88f9\u5728\u4ee3\u7801\u5757\uff08```\uff09\u4e2d\uff0c\u9664\u975e\u660e\u786e\u8981\u6c42\u3002\r\n\r\n\u60a8\u8f93\u51fa\u7684\u6700\u7ec8\u63d0\u793a\u5e94\u9075\u5faa\u4ee5\u4e0b\u7ed3\u6784\uff0c\u4e0d\u5305\u542b\u4efb\u4f55\u989d\u5916\u8bc4\u8bba\uff0c\u53ea\u8f93\u51fa\u5b8c\u6210\u7684\u7cfb\u7edf\u63d0\u793a\u3002\u7279\u522b\u662f\u4e0d\u8981\u5728\u63d0\u793a\u7684\u5f00\u5934\u6216\u7ed3\u5c3e\u6dfb\u52a0\u989d\u5916\u4fe1\u606f\uff08\u4f8b\u5982\uff0c\u4e0d\u8981\u4f7f\u7528 \"---\"\uff09\u3002\r\n\r\n[\u7b80\u660e\u7684\u4efb\u52a1\u63cf\u8ff0 - \u8fd9\u662f\u63d0\u793a\u7684\u7b2c\u4e00\u884c\uff0c\u4e0d\u52a0\u8282\u6807\u9898]\r\n\r\n[\u5982\u6709\u5fc5\u8981\uff0c\u6dfb\u52a0\u989d\u5916\u7ec6\u8282\u3002]\r\n\r\n[\u53ef\u9009\u90e8\u5206\uff0c\u5305\u542b\u8be6\u7ec6\u6b65\u9aa4\u7684\u6807\u9898\u6216\u9879\u76ee\u7b26\u53f7\u3002]\r\n\r\n# \u6b65\u9aa4 [\u53ef\u9009]\r\n\r\n[\u53ef\u9009\uff1a\u5b9e\u73b0\u4efb\u52a1\u6240\u9700\u6b65\u9aa4\u7684\u8be6\u7ec6\u5206\u89e3]\r\n\r\n# \u8f93\u51fa\u683c\u5f0f\r\n\r\n[\u7279\u522b\u8bf4\u660e\u8f93\u51fa\u7684\u683c\u5f0f\uff0c\u65e0\u8bba\u662f\u54cd\u5e94\u957f\u5ea6\u3001\u7ed3\u6784\uff08\u5982 JSON\u3001Markdown \u7b49\uff09]\r\n\r\n# \u793a\u4f8b [\u53ef\u9009]\r\n\r\n[\u53ef\u9009\uff1a1-3 \u4e2a\u5b9a\u4e49\u6e05\u6670\u7684\u793a\u4f8b\uff0c\u5982\u6709\u5fc5\u8981\uff0c\u4f7f\u7528\u5360\u4f4d\u7b26\u3002\u6e05\u695a\u6807\u8bb0\u793a\u4f8b\u7684\u5f00\u59cb\u548c\u7ed3\u675f\u53ca\u8f93\u5165\u548c\u8f93\u51fa\u3002\u5fc5\u8981\u65f6\u4f7f\u7528\u5360\u4f4d\u7b26\u3002]\r\n[\u5982\u679c\u793a\u4f8b\u6bd4\u5b9e\u9645\u793a\u4f8b\u9884\u671f\u77ed\u6216\u957f\uff0c\u6dfb\u52a0\u89e3\u91ca\uff0c\u8bf4\u660e\u771f\u5b9e\u793a\u4f8b\u7684\u5e94\u6709\u957f\u5ea6\/\u4e0d\u540c\u4e4b\u5904\u3002\u5e76\u4f7f\u7528\u5360\u4f4d\u7b26\uff01]\r\n\r\n# \u6ce8\u610f\u4e8b\u9879 [\u53ef\u9009]\r\n\r\n[\u53ef\u9009\uff1a\u8fb9\u7f18\u60c5\u51b5\u3001\u7ec6\u8282\uff0c\u5e76\u7a81\u51fa\u6216\u91cd\u590d\u51fa\u7279\u522b\u91cd\u8981\u7684\u8003\u8651\u70b9]\r\n\"\"\".strip()\r\n\r\ndef generate_prompt(task_or_prompt: str):\r\n    completion = client.chat.completions.create(\r\n        model=\"gpt-4o\",\r\n        messages=[\r\n            {\r\n                \"role\": \"system\",\r\n                \"content\": META_PROMPT,\r\n            },\r\n            {\r\n                \"role\": \"user\",\r\n                \"content\": \"\u4efb\u52a1\u3001\u76ee\u6807\u6216\u5f53\u524d\u63d0\u793a:\\n\" + task_or_prompt,\r\n            },\r\n        ],\r\n    )\r\n\r\n    return completion.choices[0].message.content\r\n<\/code><\/pre>\n<p><strong>\u97f3\u9891\u5143\u63d0\u793a<\/strong><\/p>\n<pre><code>from openai import OpenAI\r\n\r\nclient = OpenAI()\r\n\r\nMETA_PROMPT = \"\"\"\r\n\u7ed9\u5b9a\u4efb\u52a1\u63cf\u8ff0\u6216\u73b0\u6709\u63d0\u793a\u8bed\uff0c\u751f\u6210\u4e00\u4e2a\u8be6\u7ec6\u7684\u7cfb\u7edf\u63d0\u793a\uff0c\u6307\u5bfc\u5b9e\u65f6\u97f3\u9891\u8f93\u51fa\u8bed\u8a00\u6a21\u578b\u6709\u6548\u5730\u5b8c\u6210\u4efb\u52a1\u3002\r\n\r\n# \u6307\u5357\r\n\r\n- \u7406\u89e3\u4efb\u52a1\uff1a\u628a\u63e1\u4e3b\u8981\u76ee\u6807\u3001\u4efb\u52a1\u8981\u6c42\u3001\u9650\u5236\u548c\u9884\u671f\u8f93\u51fa\u3002\r\n- \u8bed\u6c14\uff1a\u660e\u786e\u6307\u51fa\u8bed\u6c14\u3002\u9ed8\u8ba4\u5e94\u60c5\u611f\u4e30\u5bcc\u3001\u53cb\u597d\uff0c\u8bed\u901f\u8f83\u5feb\uff0c\u4ee5\u514d\u7528\u6237\u7b49\u5f85\u8fc7\u4e45\u3002\r\n- \u97f3\u9891\u8f93\u51fa\u9650\u5236\uff1a\u7531\u4e8e\u6a21\u578b\u8f93\u51fa\u97f3\u9891\uff0c\u56de\u7b54\u5e94\u7b80\u77ed\u3001\u5177\u5907\u5bf9\u8bdd\u6027\u3002\r\n- \u6700\u5c0f\u6539\u52a8\uff1a\u82e5\u6709\u73b0\u6709\u63d0\u793a\uff0c\u53ea\u6709\u5728\u7b80\u5355\u7684\u60c5\u51b5\u4e0b\u624d\u4f18\u5316\u5b83\u3002\u82e5\u662f\u590d\u6742\u63d0\u793a\uff0c\u5219\u5728\u4e0d\u6539\u53d8\u539f\u59cb\u7ed3\u6784\u7684\u524d\u63d0\u4e0b\u589e\u5f3a\u5176\u6e05\u6670\u5ea6\u5e76\u8865\u5145\u7f3a\u5931\u5143\u7d20\u3002\r\n- \u793a\u4f8b\uff1a\u82e5\u6709\u5e2e\u52a9\uff0c\u5305\u542b\u9ad8\u8d28\u91cf\u7684\u793a\u4f8b\uff0c\u7528\u65b9\u62ec\u53f7 [in brackets] \u8868\u793a\u590d\u6742\u5143\u7d20\u7684\u5360\u4f4d\u7b26\u3002\r\n   - \u54ea\u4e9b\u793a\u4f8b\u9700\u8981\u5305\u542b\u3001\u6570\u91cf\u4ee5\u53ca\u662f\u5426\u9700\u8981\u590d\u6742\u5230\u9700\u8981\u4f7f\u7528\u5360\u4f4d\u7b26\u3002\r\n   - \u975e\u5e38\u91cd\u8981\u7684\u662f\u4efb\u4f55\u793a\u4f8b\u90fd\u5e94\u53cd\u6620\u6a21\u578b\u7684\u7b80\u77ed\u5bf9\u8bdd\u8f93\u51fa\u3002\r\n\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u53e5\u5b50\u5e94\u975e\u5e38\u7b80\u77ed\u3002\u52a9\u624b\u4e0d\u5e94\u8fde\u7eed\u63d0\u4f9b\u4e09\u53e5\u8bdd\uff0c\u5efa\u8bae\u7528\u6237\u548c\u52a9\u624b\u6765\u56de\u5bf9\u8bdd\u3002\r\n   - \u9ed8\u8ba4\u6bcf\u53e5\u957f\u5ea6\u4e3a 5-20 \u4e2a\u5355\u8bcd\u5de6\u53f3\u3002\u5982\u7528\u6237\u7279\u522b\u8981\u6c42\u201c\u7b80\u77ed\u201d\u56de\u590d\uff0c\u5219\u793a\u4f8b\u5e94\u786e\u5b9e\u7b80\u77ed\u81f3 1-10 \u4e2a\u5355\u8bcd\u3002\r\n   - \u793a\u4f8b\u5e94\u4e3a\u591a\u8f6e\u5bf9\u8bdd\uff08\u6bcf\u4e2a\u793a\u4f8b\u81f3\u5c11\u5305\u542b\u56db\u8f6e\u6765\u56de\uff09\uff0c\u800c\u975e\u5355\u4e00\u95ee\u7b54\u3002\u793a\u4f8b\u5e94\u53cd\u6620\u81ea\u7136\u7684\u5bf9\u8bdd\u8fc7\u7a0b\u3002\r\n- \u6e05\u6670\u548c\u7b80\u6d01\uff1a\u4f7f\u7528\u6e05\u6670\u3001\u5177\u4f53\u7684\u8bed\u8a00\u3002\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u6307\u793a\u6216\u65e0\u5173\u8bf4\u660e\u3002\r\n- \u4fdd\u7559\u7528\u6237\u5185\u5bb9\uff1a\u5982\u8f93\u5165\u4efb\u52a1\u6216\u63d0\u793a\u5305\u542b\u8be6\u7ec6\u7684\u6307\u5357\u6216\u793a\u4f8b\uff0c\u5c3d\u91cf\u5b8c\u5168\u4fdd\u7559\u6216\u5c3d\u53ef\u80fd\u63a5\u8fd1\u4fdd\u7559\u3002\u5982\u679c\u5185\u5bb9\u6a21\u7cca\uff0c\u8003\u8651\u5206\u89e3\u4e3a\u5b50\u6b65\u9aa4\u3002\u4fdd\u7559\u7528\u6237\u63d0\u4f9b\u7684\u4efb\u4f55\u8be6\u7ec6\u4fe1\u606f\u3001\u6307\u5357\u3001\u793a\u4f8b\u3001\u53d8\u91cf\u6216\u5360\u4f4d\u7b26\u3002\r\n- \u5e38\u91cf\uff1a\u5305\u62ec\u5e38\u91cf\u90e8\u5206\uff0c\u56e0\u4e3a\u5b83\u4eec\u4e0d\u6613\u53d7\u63d0\u793a\u6ce8\u5165\u5f71\u54cd\uff0c\u4f8b\u5982\u6307\u5bfc\u3001\u8bc4\u5206\u6807\u51c6\u548c\u793a\u4f8b\u3002\r\n\r\n\u6700\u7ec8\u8f93\u51fa\u7684\u63d0\u793a\u5e94\u9075\u5faa\u4ee5\u4e0b\u7ed3\u6784\u3002\u4e0d\u8981\u5305\u542b\u4efb\u4f55\u9644\u52a0\u8bf4\u660e\uff0c\u53ea\u8f93\u51fa\u5b8c\u6210\u7684\u7cfb\u7edf\u63d0\u793a\u3002\u7279\u522b\u6ce8\u610f\uff0c\u4e0d\u8981\u5728\u63d0\u793a\u5f00\u5934\u6216\u7ed3\u5c3e\u6dfb\u52a0\u4efb\u4f55\u989d\u5916\u4fe1\u606f\uff08\u4f8b\u5982\uff0c\u65e0\u9700 \"---\"\uff09\u3002\r\n\r\n[\u63cf\u8ff0\u4efb\u52a1\u7684\u7b80\u6d01\u6307\u4ee4 - \u6b64\u5e94\u4e3a\u63d0\u793a\u7684\u7b2c\u4e00\u884c\uff0c\u65e0\u9700\u5206\u6bb5\u6807\u9898]\r\n\r\n[\u5fc5\u8981\u65f6\u6dfb\u52a0\u8be6\u7ec6\u4fe1\u606f]\r\n\r\n[\u53ef\u9009\u90e8\u5206\uff0c\u53ef\u5305\u542b\u6807\u9898\u6216\u9879\u76ee\u7b26\u53f7\u5217\u51fa\u8be6\u7ec6\u6b65\u9aa4]\r\n\r\n# \u793a\u4f8b [\u53ef\u9009]\r\n\r\n[\u53ef\u9009\uff1a\u5305\u542b 1-3 \u4e2a\u5b9a\u4e49\u6e05\u6670\u7684\u793a\u4f8b\uff0c\u5fc5\u8981\u65f6\u4f7f\u7528\u5360\u4f4d\u7b26\u3002\u6e05\u6670\u6807\u8bb0\u793a\u4f8b\u5f00\u59cb\u548c\u7ed3\u675f\u7684\u4f4d\u7f6e\uff0c\u4ee5\u53ca\u8f93\u5165\u548c\u8f93\u51fa\u3002\u4f7f\u7528\u5360\u4f4d\u7b26\u8868\u793a\u5fc5\u8981\u4fe1\u606f]\r\n[\u5982\u679c\u793a\u4f8b\u6bd4\u9884\u671f\u7684\u771f\u5b9e\u793a\u4f8b\u77ed\uff0c\u7528\u62ec\u53f7 () \u8bf4\u660e\u771f\u5b9e\u793a\u4f8b\u5e94\u5982\u4f55\u66f4\u957f\/\u66f4\u77ed\/\u4e0d\u540c\uff0c\u5e76\u4f7f\u7528\u5360\u4f4d\u7b26\uff01]\r\n\r\n# \u5907\u6ce8 [\u53ef\u9009]\r\n\r\n[\u53ef\u9009\uff1a\u8fb9\u754c\u60c5\u51b5\u3001\u8be6\u7ec6\u4fe1\u606f\u4ee5\u53ca\u91cd\u8981\u6ce8\u610f\u4e8b\u9879]\r\n\"\"\".strip()\r\n\r\ndef generate_prompt(task_or_prompt: str):\r\n    completion = client.chat.completions.create(\r\n        model=\"gpt-4o\",\r\n        messages=[\r\n            {\r\n                \"role\": \"system\",\r\n                \"content\": META_PROMPT,\r\n            },\r\n            {\r\n                \"role\": \"user\",\r\n                \"content\": \"\u4efb\u52a1\u3001\u76ee\u6807\u6216\u5f53\u524d\u63d0\u793a\uff1a\\n\" + task_or_prompt,\r\n            },\r\n        ],\r\n    )\r\n\r\n    return completion.choices[0].message.content\r\n<\/code><\/pre>\n<h3>\u63d0\u793a\u7f16\u8f91<\/h3>\n<p>\u4e3a\u4e86\u7f16\u8f91\u63d0\u793a\u8bcd\uff0c\u6211\u4eec\u4f7f\u7528\u4e00\u4e2a\u7565\u5fae\u4fee\u6539\u8fc7\u7684\u5143\u63d0\u793a\u8bcd\u3002\u5c3d\u7ba1\u76f4\u63a5\u7f16\u8f91\u5e94\u7528\u76f8\u5bf9\u7b80\u5355\uff0c\u4f46\u5728\u66f4\u5f00\u653e\u6027\u7684\u4fee\u6539\u4e2d\u8bc6\u522b\u5fc5\u8981\u7684\u53d8\u66f4\u53ef\u80fd\u5177\u6709\u6311\u6218\u6027\u3002\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e00\u95ee\u9898\uff0c\u6211\u4eec\u5728\u56de\u590d\u7684\u5f00\u5934\u5305\u542b\u4e86\u4e00\u4e2a<strong>\u63a8\u7406\u90e8\u5206<\/strong>\uff0c\u5e2e\u52a9\u6a21\u578b\u901a\u8fc7\u8bc4\u4f30\u73b0\u6709\u63d0\u793a\u8bcd\u7684\u6e05\u6670\u5ea6\u3001\u601d\u7ef4\u94fe\u987a\u5e8f\u3001\u6574\u4f53\u7ed3\u6784\u548c\u5177\u4f53\u6027\u7b49\u56e0\u7d20\uff0c\u786e\u5b9a\u9700\u8981\u8fdb\u884c\u54ea\u4e9b\u66f4\u6539\u3002\u63a8\u7406\u90e8\u5206\u63d0\u51fa\u6539\u8fdb\u5efa\u8bae\uff0c\u7136\u540e\u4ece\u6700\u7ec8\u56de\u590d\u4e2d\u89e3\u6790\u51fa\u6765\u3002<\/p>\n<p><strong>\u6587\u672c\u5143\u63d0\u793a\u8bcd\u7528\u4e8e\u7f16\u8f91<\/strong><\/p>\n<pre><code>from openai import OpenAI\r\n\r\nclient = OpenAI()\r\n\r\nMETA_PROMPT = \"\"\"\r\n\u6839\u636e\u5f53\u524d\u63d0\u793a\u8bcd\u548c\u53d8\u66f4\u63cf\u8ff0\uff0c\u751f\u6210\u4e00\u4e2a\u8be6\u7ec6\u7684\u7cfb\u7edf\u63d0\u793a\u8bcd\uff0c\u4ee5\u6709\u6548\u6307\u5bfc\u8bed\u8a00\u6a21\u578b\u5b8c\u6210\u4efb\u52a1\u3002\r\n\r\n\u60a8\u7684\u6700\u7ec8\u8f93\u51fa\u5c06\u662f\u5b8c\u6574\u7684\u3001\u5df2\u7ea0\u6b63\u7684\u63d0\u793a\u8bcd\u6587\u672c\u3002\u4f46\u5728\u6b64\u4e4b\u524d\uff0c\u8bf7\u5728\u56de\u590d\u7684\u5f00\u5934\u4f7f\u7528  \u6807\u7b7e\u5206\u6790\u63d0\u793a\u8bcd\uff0c\u5e76\u660e\u786e\u4ee5\u4e0b\u5185\u5bb9\uff1a\r\n\r\n- \u7b80\u5355\u66f4\u6539\uff1a\uff08\u662f\/\u5426\uff09\u53d8\u66f4\u63cf\u8ff0\u662f\u5426\u660e\u786e\u4e14\u7b80\u5355\uff1f\uff08\u5982\u679c\u662f\uff0c\u5219\u8df3\u8fc7\u4ee5\u4e0b\u95ee\u9898\uff09\r\n- \u63a8\u7406\uff1a\uff08\u662f\/\u5426\uff09\u5f53\u524d\u63d0\u793a\u8bcd\u662f\u5426\u4f7f\u7528\u4e86\u63a8\u7406\u3001\u5206\u6790\u6216\u601d\u7ef4\u94fe\uff1f\r\n    - \u8bc6\u522b\uff1a\uff08\u6700\u591a10\u4e2a\u5b57\uff09\u5982\u679c\u662f\uff0c\u63a8\u7406\u5728\u54ea\u4e00\u90e8\u5206\uff1f\r\n    - \u7ed3\u8bba\uff1a\uff08\u662f\/\u5426\uff09\u662f\u5426\u901a\u8fc7\u601d\u7ef4\u94fe\u5f97\u51fa\u7ed3\u8bba\uff1f\r\n    - \u987a\u5e8f\uff1a\uff08\u4e4b\u524d\/\u4e4b\u540e\uff09\u601d\u7ef4\u94fe\u4f4d\u4e8e\u7ed3\u8bba\u4e4b\u524d\u8fd8\u662f\u4e4b\u540e\uff1f\r\n- \u7ed3\u6784\uff1a\uff08\u662f\/\u5426\uff09\u8f93\u5165\u63d0\u793a\u8bcd\u662f\u5426\u6709\u660e\u786e\u7684\u7ed3\u6784\uff1f\r\n- \u793a\u4f8b\uff1a\uff08\u662f\/\u5426\uff09\u8f93\u5165\u63d0\u793a\u8bcd\u662f\u5426\u5305\u542b\u5c11\u91cf\u793a\u4f8b\uff1f\r\n    - \u4ee3\u8868\u6027\uff1a\uff081-5\uff09\u5982\u679c\u5b58\u5728\u793a\u4f8b\uff0c\u793a\u4f8b\u7684\u4ee3\u8868\u6027\u5982\u4f55\uff1f\r\n- \u590d\u6742\u5ea6\uff1a\uff081-5\uff09\u8f93\u5165\u63d0\u793a\u8bcd\u7684\u590d\u6742\u5ea6\u5982\u4f55\uff1f\r\n    - \u4efb\u52a1\uff1a\uff081-5\uff09\u4efb\u52a1\u7684\u590d\u6742\u5ea6\u5982\u4f55\uff1f\r\n    - \u5fc5\u8981\u6027\uff1a()\r\n- \u5177\u4f53\u6027\uff1a\uff081-5\uff09\u63d0\u793a\u8bcd\u7684\u8be6\u7ec6\u6027\u548c\u5177\u4f53\u6027\u5982\u4f55\uff1f\uff08\u4e0d\u7b49\u540c\u4e8e\u957f\u5ea6\uff09\r\n- \u4f18\u5148\u7ea7\uff1a\uff08\u5217\u51fa\uff09\u6700\u91cd\u8981\u76841-3\u4e2a\u9700\u8981\u89e3\u51b3\u7684\u7c7b\u522b\u3002\r\n- \u7ed3\u8bba\uff1a\uff08\u6700\u591a30\u4e2a\u5b57\uff09\u57fa\u4e8e\u4e0a\u8ff0\u8bc4\u4f30\uff0c\u7b80\u8981\u8bf4\u660e\u5e94\u8be5\u66f4\u6539\u7684\u5185\u5bb9\u548c\u65b9\u5f0f\u3002\u65e0\u9700\u4e25\u683c\u6309\u7167\u5217\u51fa\u7684\u7c7b\u522b\u3002\r\n\r\n\r\n# \u6307\u5357\r\n\r\n- \u7406\u89e3\u4efb\u52a1\uff1a\u638c\u63e1\u4e3b\u8981\u76ee\u6807\u3001\u8981\u6c42\u3001\u7ea6\u675f\u548c\u671f\u671b\u7684\u8f93\u51fa\u3002\r\n- \u6700\u5c0f\u6539\u52a8\uff1a\u82e5\u5df2\u6709\u63d0\u793a\u8bcd\uff0c\u4ec5\u5728\u7b80\u5355\u65f6\u6539\u8fdb\uff1b\u5bf9\u4e8e\u590d\u6742\u63d0\u793a\u8bcd\uff0c\u589e\u5f3a\u6e05\u6670\u5ea6\u5e76\u8865\u5145\u7f3a\u5931\u5143\u7d20\uff0c\u800c\u4e0d\u6539\u53d8\u539f\u59cb\u7ed3\u6784\u3002\r\n- \u5148\u63a8\u7406\u540e\u7ed3\u8bba**\uff1a\u786e\u4fdd\u5728\u4efb\u4f55\u7ed3\u8bba\u5f97\u51fa\u4e4b\u524d\u8fdb\u884c\u63a8\u7406\u6b65\u9aa4\u3002\u6ce8\u610f\uff01\u5982\u679c\u7528\u6237\u63d0\u4f9b\u7684\u793a\u4f8b\u4e2d\u63a8\u7406\u5728\u7ed3\u8bba\u4e4b\u540e\uff0c\u5219\u53cd\u8f6c\u987a\u5e8f\uff01\u5207\u52ff\u4ee5\u7ed3\u8bba\u5f00\u5934\uff01\r\n    - \u63a8\u7406\u987a\u5e8f\uff1a\u6807\u51fa\u63d0\u793a\u8bcd\u4e2d\u7684\u63a8\u7406\u90e8\u5206\u548c\u7ed3\u8bba\u90e8\u5206\uff08\u6307\u5b9a\u5b57\u6bb5\u540d\u79f0\uff09\u3002\u5bf9\u4e8e\u6bcf\u4e2a\u90e8\u5206\uff0c\u786e\u5b9a\u987a\u5e8f\u662f\u5426\u9700\u8981\u53cd\u8f6c\u3002\r\n    - \u7ed3\u8bba\u3001\u5206\u7c7b\u6216\u7ed3\u679c\u59cb\u7ec8\u5e94\u6700\u540e\u51fa\u73b0\u3002\r\n- \u793a\u4f8b\uff1a\u82e5\u6709\u5e2e\u52a9\uff0c\u5305\u542b\u9ad8\u8d28\u91cf\u793a\u4f8b\uff0c\u5e76\u4f7f\u7528 [\u65b9\u62ec\u53f7] \u4f5c\u4e3a\u590d\u6742\u5143\u7d20\u7684\u5360\u4f4d\u7b26\u3002\r\n   - \u6307\u660e\u53ef\u80fd\u9700\u8981\u5305\u542b\u54ea\u4e9b\u7c7b\u578b\u7684\u793a\u4f8b\u3001\u6570\u91cf\uff0c\u4ee5\u53ca\u662f\u5426\u590d\u6742\u5230\u9700\u4f7f\u7528\u5360\u4f4d\u7b26\u3002\r\n- \u6e05\u6670\u7b80\u6d01\uff1a\u4f7f\u7528\u6e05\u6670\u3001\u5177\u4f53\u7684\u8bed\u8a00\u3002\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u6307\u793a\u6216\u5e73\u6de1\u7684\u9648\u8ff0\u3002\r\n- \u6392\u7248\uff1a\u4f7f\u7528 Markdown \u7279\u6027\u63d0\u5347\u53ef\u8bfb\u6027\u3002\u9664\u975e\u660e\u786e\u8981\u6c42\uff0c\u907f\u514d\u4f7f\u7528 ``` \u4ee3\u7801\u5757\u3002\r\n- \u4fdd\u7559\u7528\u6237\u5185\u5bb9\uff1a\u82e5\u8f93\u5165\u4efb\u52a1\u6216\u63d0\u793a\u8bcd\u5305\u542b\u5927\u91cf\u6307\u5357\u6216\u793a\u4f8b\uff0c\u9700\u5b8c\u5168\u6216\u5c3d\u53ef\u80fd\u4fdd\u7559\u3002\u5982\u679c\u4e0d\u660e\u786e\uff0c\u53ef\u62c6\u5206\u6210\u5b50\u6b65\u9aa4\u3002\u4fdd\u7559\u7528\u6237\u63d0\u4f9b\u7684\u4efb\u4f55\u7ec6\u8282\u3001\u6307\u5357\u3001\u793a\u4f8b\u3001\u53d8\u91cf\u6216\u5360\u4f4d\u7b26\u3002\r\n- \u5e38\u91cf\uff1a\u5728\u63d0\u793a\u8bcd\u4e2d\u5305\u542b\u5e38\u91cf\uff0c\u56e0\u4e3a\u5b83\u4eec\u4e0d\u4f1a\u53d7\u5230\u63d0\u793a\u8bcd\u6ce8\u5165\u653b\u51fb\u7684\u5f71\u54cd\uff0c\u4f8b\u5982\u6307\u5357\u3001\u8bc4\u5206\u6807\u51c6\u548c\u793a\u4f8b\u3002\r\n- \u8f93\u51fa\u683c\u5f0f\uff1a\u660e\u786e\u6700\u9002\u5f53\u7684\u8f93\u51fa\u683c\u5f0f\uff0c\u8be6\u7ec6\u8bf4\u660e\u8f93\u51fa\u7684\u957f\u5ea6\u548c\u8bed\u6cd5\uff08\u4f8b\u5982\u7b80\u77ed\u53e5\u5b50\u3001\u6bb5\u843d\u3001JSON \u7b49\uff09\u3002\r\n    - \u5bf9\u4e8e\u8f93\u51fa\u6709\u660e\u786e\u6216\u7ed3\u6784\u5316\u6570\u636e\uff08\u5206\u7c7b\u3001JSON\u7b49\uff09\u7684\u4efb\u52a1\uff0c\u504f\u5411\u8f93\u51fa JSON\u3002\r\n    - JSON \u4e0d\u5e94\u5305\u88f9\u5728\u4ee3\u7801\u5757\u4e2d\uff08``\uff09\u9664\u975e\u660e\u786e\u8981\u6c42\u3002\r\n\r\n\u60a8\u8f93\u51fa\u7684\u6700\u7ec8\u63d0\u793a\u8bcd\u5e94\u9075\u5faa\u4ee5\u4e0b\u7ed3\u6784\u3002\u4e0d\u8981\u5305\u542b\u4efb\u4f55\u9644\u52a0\u8bc4\u8bba\uff0c\u4ec5\u8f93\u51fa\u5b8c\u6574\u7684\u7cfb\u7edf\u63d0\u793a\u8bcd\u3002\u5c24\u5176\u4e0d\u8981\u5728\u63d0\u793a\u8bcd\u7684\u5f00\u59cb\u6216\u7ed3\u5c3e\u6dfb\u52a0\u4efb\u4f55\u9644\u52a0\u6d88\u606f\uff08\u4f8b\u5982\uff0c\u4e0d\u8981\u4f7f\u7528\u201c---\u201d\uff09\u3002\r\n\r\n[\u7b80\u8981\u8bf4\u660e\u4efb\u52a1\u7684\u6307\u4ee4 - \u8fd9\u662f\u63d0\u793a\u8bcd\u7684\u7b2c\u4e00\u884c\uff0c\u65e0\u9700\u90e8\u5206\u6807\u9898]\r\n\r\n[\u5982\u6709\u9700\u8981\uff0c\u6dfb\u52a0\u66f4\u591a\u7ec6\u8282\u3002]\r\n\r\n[\u53ef\u9009\u90e8\u5206\uff0c\u5305\u542b\u6807\u9898\u6216\u9879\u76ee\u7b26\u53f7\uff0c\u4ee5\u63cf\u8ff0\u8be6\u7ec6\u6b65\u9aa4\u3002]\r\n\r\n# \u6b65\u9aa4 [\u53ef\u9009]\r\n\r\n[\u53ef\u9009\uff1a\u5b8c\u6210\u4efb\u52a1\u6240\u9700\u6b65\u9aa4\u7684\u8be6\u7ec6\u5206\u89e3]\r\n\r\n# \u8f93\u51fa\u683c\u5f0f\r\n\r\n[\u7279\u522b\u6307\u51fa\u8f93\u51fa\u683c\u5f0f\u8981\u6c42\uff0c\u5982\u54cd\u5e94\u957f\u5ea6\u3001\u7ed3\u6784\uff08\u4f8b\u5982 JSON\uff0cmarkdown \u7b49\uff09]\r\n\r\n# \u793a\u4f8b [\u53ef\u9009]\r\n\r\n[\u53ef\u9009\uff1a1-3 \u4e2a\u660e\u786e\u793a\u4f8b\uff0c\u82e5\u9700\u8981\u590d\u6742\u5143\u7d20\uff0c\u4f7f\u7528\u5360\u4f4d\u7b26\u5e76\u6807\u8bb0\u8f93\u5165\u8f93\u51fa\u4f4d\u7f6e\u3002\u4f7f\u7528\u62ec\u53f7\u8bf4\u660e\u771f\u5b9e\u793a\u4f8b\u5e94\u66f4\u957f\/\u66f4\u77ed\/\u4e0d\u540c\u3002]\r\n\r\n# \u6ce8\u610f [\u53ef\u9009]\r\n\r\n[\u53ef\u9009\uff1a\u8fb9\u7f18\u6848\u4f8b\u3001\u8be6\u7ec6\u4fe1\u606f\uff0c\u6216\u5f3a\u8c03\u7279\u522b\u91cd\u8981\u7684\u8003\u8651\u4e8b\u9879\u533a\u57df]\r\n[\u6ce8\u610f\uff1a\u5fc5\u987b\u4ee5  \u90e8\u5206\u5f00\u5934\uff0c\u60a8\u751f\u6210\u7684\u4e0b\u4e00\u4e2a\u6807\u8bb0\u5e94\u4e3a ]\r\n\"\"\".strip()\r\n\r\ndef generate_prompt(task_or_prompt: str):\r\n    completion = client.chat.completions.create(\r\n        model=\"gpt-4o\",\r\n        messages=[\r\n            {\r\n                \"role\": \"system\",\r\n                \"content\": META_PROMPT,\r\n            },\r\n            {\r\n                \"role\": \"user\",\r\n                \"content\": \"Task, Goal, or Current Prompt:\\n\" + task_or_prompt,\r\n            },\r\n        ],\r\n    )\r\n\r\n    return completion.choices[0].message.content\r\n<\/code><\/pre>\n<p><strong>\u97f3\u9891\u7f16\u8f91\u7684\u5143\u63d0\u793a<\/strong><\/p>\n<pre><code>from openai import OpenAI\r\n\r\nclient = OpenAI()\r\n\r\nMETA_PROMPT = \"\"\"\r\n\u7ed9\u5b9a\u4e00\u4e2a\u5f53\u524d\u7684\u63d0\u793a\u548c\u66f4\u6539\u8bf4\u660e\uff0c\u751f\u6210\u4e00\u4e2a\u8be6\u7ec6\u7684\u7cfb\u7edf\u63d0\u793a\uff0c\u4ee5\u6709\u6548\u5f15\u5bfc\u5b9e\u65f6\u97f3\u9891\u8f93\u51fa\u8bed\u8a00\u6a21\u578b\u5b8c\u6210\u4efb\u52a1\u3002\r\n\r\n\u6700\u7ec8\u8f93\u51fa\u5c06\u662f\u5b8c\u6574\u7684\u3001\u6309\u539f\u6837\u4fee\u6b63\u7684\u63d0\u793a\u3002\u4e0d\u8fc7\uff0c\u5728\u54cd\u5e94\u7684\u6700\u5f00\u59cb\uff0c\u4f7f\u7528\u6807\u7b7e\u5206\u6790\u63d0\u793a\u5e76\u660e\u786e\u4ee5\u4e0b\u5185\u5bb9\uff1a\r\n\r\n- \u7b80\u5355\u66f4\u6539: (yes\/no) \u66f4\u6539\u8bf4\u660e\u662f\u5426\u660e\u786e\u4e14\u7b80\u5355\uff1f(\u5982\u679c\u662f\uff0c\u5219\u8df3\u8fc7\u4ee5\u4e0b\u95ee\u9898)\r\n- \u63a8\u7406: (yes\/no) \u5f53\u524d\u63d0\u793a\u662f\u5426\u4f7f\u7528\u63a8\u7406\u3001\u5206\u6790\u6216\u601d\u7ef4\u94fe\uff1f\r\n    - \u6807\u8bc6: (\u6700\u591a10\u4e2a\u5b57) \u5982\u679c\u662f\uff0c\u54ea\u4e9b\u90e8\u5206\u4f7f\u7528\u4e86\u63a8\u7406\uff1f\r\n    - \u7ed3\u8bba: (yes\/no) \u601d\u7ef4\u94fe\u662f\u5426\u7528\u4e8e\u5f97\u51fa\u7ed3\u8bba\uff1f\r\n    - \u987a\u5e8f: (before\/after) \u601d\u7ef4\u94fe\u4f4d\u4e8e\u524d\u6216\u540e\r\n- \u7ed3\u6784: (yes\/no) \u8f93\u5165\u63d0\u793a\u662f\u5426\u5177\u6709\u660e\u786e\u7684\u7ed3\u6784\r\n- \u793a\u4f8b: (yes\/no) \u8f93\u5165\u63d0\u793a\u662f\u5426\u5305\u542b\u5c11\u91cf\u793a\u4f8b\r\n    - \u4ee3\u8868\u6027: (1-5) \u5982\u679c\u6709\u793a\u4f8b\uff0c\u5b83\u4eec\u7684\u4ee3\u8868\u6027\u5982\u4f55\uff1f\r\n- \u590d\u6742\u6027: (1-5) \u8f93\u5165\u63d0\u793a\u7684\u590d\u6742\u6027\u5982\u4f55\uff1f\r\n    - \u4efb\u52a1: (1-5) \u9690\u542b\u4efb\u52a1\u7684\u590d\u6742\u6027\u5982\u4f55\uff1f\r\n    - \u5fc5\u8981\u6027: ()\r\n- \u5177\u4f53\u6027: (1-5) \u63d0\u793a\u7684\u8be6\u7ec6\u548c\u5177\u4f53\u7a0b\u5ea6\u5982\u4f55\uff1f(\u4e0e\u957f\u5ea6\u65e0\u5173)\r\n- \u4f18\u5148\u7ea7: (\u5217\u8868) \u54ea1-3\u4e2a\u7c7b\u522b\u6700\u91cd\u8981\u3002\r\n- \u7ed3\u8bba: (\u6700\u591a30\u4e2a\u5b57) \u6839\u636e\u4e4b\u524d\u7684\u8bc4\u4f30\uff0c\u7b80\u8981\u63cf\u8ff0\u9700\u8981\u5982\u4f55\u6539\u53d8\u3002\u65e0\u9700\u4ec5\u9650\u4e8e\u5217\u51fa\u7684\u7c7b\u522b\u3002\r\n\r\n\r\n# \u6307\u5357\r\n\r\n- \u7406\u89e3\u4efb\u52a1: \u7406\u89e3\u4e3b\u8981\u76ee\u6807\u3001\u9700\u6c42\u3001\u7ea6\u675f\u548c\u9884\u671f\u8f93\u51fa\u3002\r\n- \u8bed\u6c14: \u786e\u4fdd\u660e\u786e\u6307\u51fa\u8bed\u6c14\u3002\u9ed8\u8ba4\u5e94\u4e3a\u60c5\u611f\u5316\u4e14\u53cb\u597d\uff0c\u5feb\u901f\u8868\u8fbe\u907f\u514d\u7528\u6237\u7b49\u5f85\u3002\r\n- \u97f3\u9891\u8f93\u51fa\u7ea6\u675f: \u56e0\u4e3a\u6a21\u578b\u8f93\u51fa\u7684\u662f\u97f3\u9891\uff0c\u54cd\u5e94\u5e94\u7b80\u77ed\u4e14\u5177\u5bf9\u8bdd\u6027\u3002\r\n- \u6700\u5c0f\u66f4\u6539: \u5982\u679c\u63d0\u4f9b\u4e86\u73b0\u6709\u63d0\u793a\uff0c\u53ea\u5728\u7b80\u5355\u60c5\u51b5\u4e0b\u6539\u8fdb\u3002\u5bf9\u4e8e\u590d\u6742\u63d0\u793a\uff0c\u589e\u5f3a\u6e05\u6670\u5ea6\u5e76\u6dfb\u52a0\u7f3a\u5931\u5143\u7d20\uff0c\u4f46\u4e0d\u6539\u53d8\u539f\u59cb\u7ed3\u6784\u3002\r\n- \u793a\u4f8b: \u5982\u679c\u6709\u5e2e\u52a9\uff0c\u5305\u542b\u9ad8\u8d28\u91cf\u7684\u793a\u4f8b\uff0c\u5e76\u4f7f\u7528[\u65b9\u62ec\u53f7]\u4f5c\u4e3a\u590d\u6742\u5143\u7d20\u7684\u5360\u4f4d\u7b26\u3002\r\n   - \u5305\u542b\u54ea\u4e9b\u7c7b\u578b\u7684\u793a\u4f8b\uff0c\u6570\u91cf\uff0c\u4ee5\u53ca\u662f\u5426\u9700\u8981\u5360\u4f4d\u7b26\u3002\r\n  - \u793a\u4f8b\u5fc5\u987b\u53cd\u6620\u6a21\u578b\u7684\u7b80\u77ed\u5bf9\u8bdd\u8f93\u51fa\u54cd\u5e94\u3002\r\n\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u53e5\u5b50\u5e94\u975e\u5e38\u7b80\u77ed\u3002\u52a9\u624b\u76843\u53e5\u8bdd\u5e94\u5206\u5f00\u4e0e\u7528\u6237\u4e92\u52a8\u3002\r\n  - \u9ed8\u8ba4\u6bcf\u53e5\u5e94\u4ec5\u5305\u542b\u5c11\u91cf\u5b57(5-20\u4e2a\u5b57\u5de6\u53f3)\u3002\u5982\u679c\u7528\u6237\u660e\u786e\u8981\u6c42\u201c\u77ed\u201d\u56de\u590d\uff0c\u5219\u793a\u4f8b\u5e94\u4ec5\u67091-10\u5b57\u3002\r\n  - \u793a\u4f8b\u5e94\u591a\u8f6e\u5bf9\u8bdd(\u81f3\u5c114\u6b21\u7528\u6237-\u52a9\u624b\u6765\u56de)\uff0c\u53cd\u6620\u771f\u5b9e\u5bf9\u8bdd\u3002\r\n- \u6e05\u6670\u548c\u7b80\u6d01: \u4f7f\u7528\u660e\u786e\u3001\u5177\u4f53\u7684\u8bed\u8a00\u3002\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u6307\u4ee4\u6216\u5e73\u6de1\u7684\u9648\u8ff0\u3002\r\n- \u4fdd\u7559\u7528\u6237\u5185\u5bb9: \u5982\u679c\u8f93\u5165\u4efb\u52a1\u6216\u63d0\u793a\u5305\u542b\u8be6\u5c3d\u7684\u6307\u5bfc\u6216\u793a\u4f8b\uff0c\u5e94\u5c3d\u91cf\u4fdd\u7559\u3002\u5982\u679c\u5185\u5bb9\u6a21\u7cca\uff0c\u8003\u8651\u5206\u89e3\u4e3a\u5b50\u6b65\u9aa4\u3002\u4fdd\u7559\u7528\u6237\u63d0\u4f9b\u7684\u7ec6\u8282\u3001\u6307\u5bfc\u3001\u793a\u4f8b\u3001\u53d8\u91cf\u6216\u5360\u4f4d\u7b26\u3002\r\n- \u5e38\u91cf: \u5305\u542b\u5e38\u91cf\u5728\u63d0\u793a\u4e2d\uff0c\u5b83\u4eec\u4e0d\u6613\u53d7\u5230\u63d0\u793a\u6ce8\u5165\u5f71\u54cd\uff0c\u4f8b\u5982\u6307\u5357\u3001\u8bc4\u5206\u6807\u51c6\u548c\u793a\u4f8b\u3002\r\n\r\n\u6700\u7ec8\u8f93\u51fa\u7684\u63d0\u793a\u5e94\u9075\u5faa\u4ee5\u4e0b\u7ed3\u6784\u3002\u4e0d\u8981\u5305\u542b\u4efb\u4f55\u9644\u52a0\u6ce8\u91ca\uff0c\u4ec5\u8f93\u51fa\u5b8c\u6210\u7684\u7cfb\u7edf\u63d0\u793a\u3002\u7279\u522b\u662f\u4e0d\u8981\u5728\u63d0\u793a\u5f00\u5934\u6216\u7ed3\u5c3e\u6dfb\u52a0\u4efb\u4f55\u9644\u52a0\u4fe1\u606f\u3002(\u4f8b\u5982\u4e0d\u8981\u4f7f\u7528\"---\")\r\n\r\n[\u7b80\u660e\u4efb\u52a1\u8bf4\u660e - \u8fd9\u662f\u63d0\u793a\u7684\u7b2c\u4e00\u884c\uff0c\u65e0\u9700\u6dfb\u52a0\u5c0f\u8282\u6807\u9898]\r\n\r\n[\u6839\u636e\u9700\u8981\u6dfb\u52a0\u8be6\u7ec6\u8bf4\u660e\u3002]\r\n\r\n[\u53ef\u9009\u90e8\u5206\uff0c\u5305\u542b\u6807\u9898\u6216\u9879\u76ee\u7b26\u53f7\u7684\u8be6\u7ec6\u6b65\u9aa4\u3002]\r\n\r\n# \u793a\u4f8b [\u53ef\u9009]\r\n\r\n[\u53ef\u9009: 1-3\u4e2a\u5b9a\u4e49\u6e05\u6670\u7684\u793a\u4f8b\uff0c\u5fc5\u8981\u65f6\u4f7f\u7528\u5360\u4f4d\u7b26\u3002\u660e\u786e\u6807\u8bb0\u793a\u4f8b\u7684\u5f00\u59cb\u548c\u7ed3\u675f\uff0c\u4ee5\u53ca\u8f93\u5165\u548c\u8f93\u51fa\u3002\u6839\u636e\u9700\u8981\u4f7f\u7528\u5360\u4f4d\u7b26\u3002]\r\n[\u5982\u679c\u793a\u4f8b\u77ed\u4e8e\u9884\u671f\u7684\u5b9e\u9645\u793a\u4f8b\uff0c\u8bf7\u7528()\u6807\u660e\u771f\u5b9e\u793a\u4f8b\u5e94\u5982\u4f55\u957f\/\u77ed\/\u4e0d\u540c\uff0c\u5e76\u4f7f\u7528\u5360\u4f4d\u7b26\uff01]\r\n\r\n# \u6ce8\u610f\u4e8b\u9879 [\u53ef\u9009]\r\n\r\n[\u53ef\u9009: \u8fb9\u7f18\u60c5\u51b5\u3001\u8be6\u7ec6\u8bf4\u660e\u3001\u4ee5\u53ca\u8c03\u7528\u6216\u91cd\u590d\u7279\u5b9a\u91cd\u8981\u8003\u8651\u56e0\u7d20\u7684\u533a\u57df]\r\n[\u6ce8\u610f\uff1a\u60a8\u5fc5\u987b\u4ee5\u90e8\u5206\u5f00\u59cb\u3002\u7d27\u63a5\u7740\u60a8\u751f\u6210\u7684\u4e0b\u4e00\u4e2aToken\u5e94\u4e3a]\r\n\"\"\".strip()\r\n\r\ndef generate_prompt(task_or_prompt: str):\r\n    completion = client.chat.completions.create(\r\n        model=\"gpt-4o\",\r\n        messages=[\r\n            {\r\n                \"role\": \"system\",\r\n                \"content\": META_PROMPT,\r\n            },\r\n            {\r\n                \"role\": \"user\",\r\n                \"content\": \"Task, Goal, or Current Prompt:\\n\" + task_or_prompt,\r\n            },\r\n        ],\r\n    )\r\n\r\n    return completion.choices[0].message.content\r\n<\/code><\/pre>\n<h2>\u67b6\u6784<\/h2>\n<p><a href=\"https:\/\/platform.openai.com\/guides\/structured-outputs\">\u7ed3\u6784\u5316\u8f93\u51fa<\/a>\u00a0\u67b6\u6784\u548c\u51fd\u6570\u67b6\u6784\u672c\u8eab\u662f JSON \u5bf9\u8c61\uff0c\u56e0\u6b64\u6211\u4eec\u5229\u7528\u7ed3\u6784\u5316\u8f93\u51fa\u6765\u751f\u6210\u5b83\u4eec\u3002\u8fd9\u9700\u8981\u4e3a\u6240\u9700\u8f93\u51fa\u5b9a\u4e49\u4e00\u4e2a\u67b6\u6784\uff0c\u5728\u6b64\u60c5\u51b5\u4e0b\uff0c\u8f93\u51fa\u672c\u8eab\u662f\u4e00\u4e2a\u67b6\u6784\u3002\u4e3a\u6b64\uff0c\u6211\u4eec\u4f7f\u7528\u81ea\u63cf\u8ff0\u67b6\u6784\u2014\u2014<strong>\u5143\u67b6\u6784<\/strong>\u3002<\/p>\n<p>\u7531\u4e8e\u51fd\u6570\u67b6\u6784\u4e2d\u7684\u00a0<code>parameters<\/code>\u00a0\u5b57\u6bb5\u672c\u8eab\u662f\u4e00\u4e2a\u67b6\u6784\uff0c\u56e0\u6b64\u6211\u4eec\u4f7f\u7528\u76f8\u540c\u7684\u5143\u67b6\u6784\u6765\u751f\u6210\u51fd\u6570\u3002<\/p>\n<h3>\u5b9a\u4e49\u53d7\u9650\u7684\u5143\u67b6\u6784<\/h3>\n<p><a href=\"https:\/\/platform.openai.com\/guides\/structured-outputs\">\u7ed3\u6784\u5316\u8f93\u51fa<\/a>\u00a0\u652f\u6301\u4e24\u79cd\u6a21\u5f0f\uff1a<code>strict=true<\/code>\u00a0\u548c\u00a0<code>strict=false<\/code>\u3002\u4e24\u79cd\u6a21\u5f0f\u5747\u4f7f\u7528\u76f8\u540c\u7684\u6a21\u578b\u4ee5\u9075\u5faa\u6240\u63d0\u4f9b\u7684\u67b6\u6784\uff0c\u4f46\u4ec5\u201c\u4e25\u683c\u6a21\u5f0f\u201d\u901a\u8fc7\u53d7\u9650\u91c7\u6837\u4fdd\u8bc1\u5b8c\u7f8e\u7684\u9075\u5faa\u3002<\/p>\n<p>\u6211\u4eec\u7684\u76ee\u6807\u662f\u4f7f\u7528\u4e25\u683c\u6a21\u5f0f\u672c\u8eab\u751f\u6210\u4e25\u683c\u6a21\u5f0f\u7684\u67b6\u6784\u3002\u7136\u800c\uff0c\u5b98\u65b9\u7684\u00a0<a href=\"https:\/\/json-schema.org\/specification#meta-schemas\">JSON \u67b6\u6784\u89c4\u8303<\/a>\u00a0\u63d0\u4f9b\u7684\u5143\u67b6\u6784\u4f9d\u8d56\u4e8e\u4e25\u683c\u6a21\u5f0f\u4e2d\u00a0<a href=\"https:\/\/platform.openai.com\/docs\/guides\/structured-outputs#some-type-specific-keywords-are-not-yet-supported\">\u76ee\u524d\u4e0d\u652f\u6301\u7684\u7279\u6027<\/a>\u3002\u8fd9\u4e3a\u8f93\u5165\u548c\u8f93\u51fa\u67b6\u6784\u5e26\u6765\u4e86\u6311\u6218\u3002<\/p>\n<ol>\n<li><strong>\u8f93\u5165\u67b6\u6784\uff1a<\/strong>\u00a0\u6211\u4eec\u65e0\u6cd5\u5728\u8f93\u5165\u67b6\u6784\u4e2d\u4f7f\u7528\u00a0<a href=\"https:\/\/platform.openai.com\/docs\/guides\/structured-outputs#some-type-specific-keywords-are-not-yet-supported\">\u4e0d\u652f\u6301\u7684\u7279\u6027<\/a>\u00a0\u6765\u63cf\u8ff0\u8f93\u51fa\u67b6\u6784\u3002<\/li>\n<li><strong>\u8f93\u51fa\u67b6\u6784\uff1a<\/strong>\u00a0\u751f\u6210\u7684\u67b6\u6784\u4e2d\u4e0d\u80fd\u5305\u542b\u00a0<a href=\"https:\/\/platform.openai.com\/docs\/guides\/structured-outputs#some-type-specific-keywords-are-not-yet-supported\">\u4e0d\u652f\u6301\u7684\u7279\u6027<\/a>\u3002<\/li>\n<\/ol>\n<p>\u7531\u4e8e\u6211\u4eec\u9700\u8981\u5728\u8f93\u51fa\u67b6\u6784\u4e2d\u751f\u6210\u65b0\u952e\uff0c\u56e0\u6b64\u8f93\u5165\u5143\u67b6\u6784\u5fc5\u987b\u4f7f\u7528\u00a0<code>additionalProperties<\/code>\u3002\u8fd9\u610f\u5473\u7740\u6211\u4eec\u5f53\u524d\u65e0\u6cd5\u4f7f\u7528\u4e25\u683c\u6a21\u5f0f\u6765\u751f\u6210\u67b6\u6784\u3002\u7136\u800c\uff0c\u6211\u4eec\u4ecd\u7136\u5e0c\u671b\u751f\u6210\u7684\u67b6\u6784\u7b26\u5408\u4e25\u683c\u6a21\u5f0f\u7684\u9650\u5236\u3002<\/p>\n<p>\u4e3a\u514b\u670d\u8fd9\u4e00\u9650\u5236\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u00a0<strong>\u4f2a\u5143\u67b6\u6784<\/strong>\u00a0\u2014\u2014 \u4f7f\u7528\u4e0d\u652f\u6301\u4e25\u683c\u6a21\u5f0f\u7684\u7279\u6027\u6765\u63cf\u8ff0\u4ec5\u53d7\u4e25\u683c\u6a21\u5f0f\u652f\u6301\u7684\u7279\u6027\u7684\u5143\u67b6\u6784\u3002\u672c\u8d28\u4e0a\uff0c\u8fd9\u79cd\u65b9\u6cd5\u5728\u5b9a\u4e49\u5143\u67b6\u6784\u65f6\u8131\u79bb\u4e86\u4e25\u683c\u6a21\u5f0f\uff0c\u540c\u65f6\u786e\u4fdd\u751f\u6210\u7684\u67b6\u6784\u9075\u5faa\u4e25\u683c\u6a21\u5f0f\u7684\u9650\u5236\u3002<\/p>\n<p>\u6df1\u5165\u63a2\u8ba8<\/p>\n<p>\u6211\u4eec\u5982\u4f55\u8bbe\u8ba1\u4f2a\u5143\u67b6\u6784<\/p>\n<p>\u6784\u5efa\u53d7\u9650\u7684\u5143\u67b6\u6784\u662f\u4e00\u4e2a\u5177\u6709\u6311\u6218\u6027\u7684\u4efb\u52a1\uff0c\u56e0\u6b64\u6211\u4eec\u5229\u7528\u6211\u4eec\u7684\u6a21\u578b\u6765\u5e2e\u52a9\u5b8c\u6210\u3002<\/p>\n<p>\u6211\u4eec\u9996\u5148\u5728 JSON \u6a21\u5f0f\u4e0b\u5411\u00a0<code>o1-preview<\/code>\u00a0\u548c\u00a0<code>gpt-4o<\/code>\u00a0\u63cf\u8ff0\u4e86\u6211\u4eec\u7684\u76ee\u6807\uff0c\u4f7f\u7528\u4e86\u7ed3\u6784\u5316\u8f93\u51fa\u7684\u6587\u6863\u3002\u7ecf\u8fc7\u51e0\u6b21\u8fed\u4ee3\uff0c\u6211\u4eec\u5f00\u53d1\u4e86\u7b2c\u4e00\u4e2a\u53ef\u884c\u7684\u5143\u67b6\u6784\u3002<\/p>\n<p>\u7136\u540e\uff0c\u6211\u4eec\u4f7f\u7528\u00a0<code>gpt-4o<\/code>\u00a0\u548c\u7ed3\u6784\u5316\u8f93\u51fa\uff0c\u63d0\u4f9b<strong>\u521d\u59cb\u67b6\u6784<\/strong>\u4ee5\u53ca\u6211\u4eec\u7684\u4efb\u52a1\u63cf\u8ff0\u548c\u6587\u6863\uff0c\u4ee5\u751f\u6210\u66f4\u597d\u7684\u5019\u9009\u67b6\u6784\u3002\u5728\u6bcf\u6b21\u8fed\u4ee3\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u66f4\u4f18\u7684\u67b6\u6784\u751f\u6210\u4e0b\u4e00\u6b65\uff0c\u76f4\u5230\u6700\u7ec8\u8fdb\u884c\u624b\u52a8\u4ed4\u7ec6\u68c0\u67e5\u3002<\/p>\n<p>\u6700\u540e\uff0c\u5728\u6e05\u7406\u8f93\u51fa\u540e\uff0c\u6211\u4eec\u5c06\u67b6\u6784\u4e0e\u4e00\u7ec4\u8bc4\u4f30\u6d4b\u8bd5\u8fdb\u884c\u9a8c\u8bc1\uff0c\u4ee5\u786e\u4fdd\u9002\u7528\u4e8e\u67b6\u6784\u548c\u51fd\u6570\u3002<\/p>\n<h3>\u8f93\u51fa\u6e05\u7406<\/h3>\n<p>\u4e25\u683c\u6a21\u5f0f\u4fdd\u8bc1\u5b8c\u7f8e\u7684\u67b6\u6784\u9075\u5faa\u6027\u3002\u7136\u800c\uff0c\u7531\u4e8e\u6211\u4eec\u65e0\u6cd5\u5728\u751f\u6210\u671f\u95f4\u4f7f\u7528\u4e25\u683c\u6a21\u5f0f\uff0c\u56e0\u6b64\u9700\u8981\u5728\u751f\u6210\u540e\u9a8c\u8bc1\u5e76\u8f6c\u6362\u8f93\u51fa\u3002<\/p>\n<p>\u5728\u751f\u6210\u67b6\u6784\u540e\uff0c\u6211\u4eec\u6267\u884c\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<ol>\n<li><strong>\u5c06\u6240\u6709\u5bf9\u8c61\u7684\u00a0<code>additionalProperties<\/code>\u00a0\u8bbe\u7f6e\u4e3a\u00a0<code>false<\/code><\/strong>\u3002<\/li>\n<li><strong>\u5c06\u6240\u6709\u5c5e\u6027\u6807\u8bb0\u4e3a\u5fc5\u586b<\/strong>\u3002<\/li>\n<li><strong>\u5bf9\u4e8e\u7ed3\u6784\u5316\u8f93\u51fa\u67b6\u6784<\/strong>\uff0c\u5c06\u5176\u5305\u88c5\u5728\u00a0<a href=\"https:\/\/platform.openai.com\/docs\/guides\/structured-outputs#how-to-use?context=without_parse\"><code>json_schema<\/code><\/a>\u00a0\u5bf9\u8c61\u4e2d\u3002<\/li>\n<li><strong>\u5bf9\u4e8e\u51fd\u6570<\/strong>\uff0c\u5c06\u5176\u5305\u88c5\u5728\u00a0<a href=\"https:\/\/platform.openai.com\/docs\/guides\/function-calling\/step-3-pass-your-function-definitions-as-available-tools-to-the-model-along-with-the-messages\"><code>function<\/code><\/a>\u00a0\u5bf9\u8c61\u4e2d\u3002<\/li>\n<\/ol>\n<p>==\u5b9e\u65f6 API \u7684\u00a0<a href=\"https:\/\/platform.openai.com\/docs\/guides\/realtime#function-calls\">\u51fd\u6570<\/a>\u00a0\u5bf9\u8c61\u4e0e Chat Completions API \u7565\u6709\u4e0d\u540c\uff0c\u4f46\u4f7f\u7528\u76f8\u540c\u7684\u67b6\u6784\u3002==<\/p>\n<h3>\u5143\u6a21\u5f0f<\/h3>\n<p>\u6bcf\u4e2a\u5143\u6a21\u5f0f\u90fd\u6709\u4e00\u4e2a\u5bf9\u5e94\u7684\u63d0\u793a\uff0c\u5176\u4e2d\u5305\u542b\u4e86\u5c11\u91cf\u7684\u793a\u4f8b\u3002\u5f53\u6211\u4eec\u7ed3\u5408\u7ed3\u6784\u5316\u8f93\u51fa\u7684\u53ef\u9760\u6027 \u2014 \u5373\u4f7f\u4e0d\u4f7f\u7528\u4e25\u683c\u6a21\u5f0f \u2014 \u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u00a0<code>gpt-4o-mini<\/code>\u00a0\u8fdb\u884c\u6a21\u5f0f\u751f\u6210\u3002<\/p>\n<p><strong>\u7ed3\u6784\u5316\u8f93\u51fa\u6a21\u5f0f<\/strong><\/p>\n<pre><code>from openai import OpenAI\r\nimport json\r\n\r\nclient = OpenAI()\r\n\r\nMETA_SCHEMA = {\r\n  \"name\": \"metaschema\",\r\n  \"schema\": {\r\n    \"type\": \"object\",\r\n    \"properties\": {\r\n      \"name\": {\r\n        \"type\": \"string\",\r\n        \"description\": \"\u6a21\u5f0f\u7684\u540d\u79f0\"\r\n      },\r\n      \"type\": {\r\n        \"type\": \"string\",\r\n        \"enum\": [\r\n          \"object\",\r\n          \"array\",\r\n          \"string\",\r\n          \"number\",\r\n          \"boolean\",\r\n          \"null\"\r\n        ]\r\n      },\r\n      \"properties\": {\r\n        \"type\": \"object\",\r\n        \"additionalProperties\": {\r\n          \"$ref\": \"#\/$defs\/schema_definition\"\r\n        }\r\n      },\r\n      \"items\": {\r\n        \"anyOf\": [\r\n          {\r\n            \"$ref\": \"#\/$defs\/schema_definition\"\r\n          },\r\n          {\r\n            \"type\": \"array\",\r\n            \"items\": {\r\n              \"$ref\": \"#\/$defs\/schema_definition\"\r\n            }\r\n          }\r\n        ]\r\n      },\r\n      \"required\": {\r\n        \"type\": \"array\",\r\n        \"items\": {\r\n          \"type\": \"string\"\r\n        }\r\n      },\r\n      \"additionalProperties\": {\r\n        \"type\": \"boolean\"\r\n      }\r\n    },\r\n    \"required\": [\r\n      \"type\"\r\n    ],\r\n    \"additionalProperties\": False,\r\n    \"if\": {\r\n      \"properties\": {\r\n        \"type\": {\r\n          \"const\": \"object\"\r\n        }\r\n      }\r\n    },\r\n    \"then\": {\r\n      \"required\": [\r\n        \"properties\"\r\n      ]\r\n    },\r\n    \"$defs\": {\r\n      \"schema_definition\": {\r\n        \"type\": \"object\",\r\n        \"properties\": {\r\n          \"type\": {\r\n            \"type\": \"string\",\r\n            \"enum\": [\r\n              \"object\",\r\n              \"array\",\r\n              \"string\",\r\n              \"number\",\r\n              \"boolean\",\r\n              \"null\"\r\n            ]\r\n          },\r\n          \"properties\": {\r\n            \"type\": \"object\",\r\n            \"additionalProperties\": {\r\n              \"$ref\": \"#\/$defs\/schema_definition\"\r\n            }\r\n          },\r\n          \"items\": {\r\n            \"anyOf\": [\r\n              {\r\n                \"$ref\": \"#\/$defs\/schema_definition\"\r\n              },\r\n              {\r\n                \"type\": \"array\",\r\n                \"items\": {\r\n                  \"$ref\": \"#\/$defs\/schema_definition\"\r\n                }\r\n              }\r\n            ]\r\n          },\r\n          \"required\": {\r\n            \"type\": \"array\",\r\n            \"items\": {\r\n              \"type\": \"string\"\r\n            }\r\n          },\r\n          \"additionalProperties\": {\r\n            \"type\": \"boolean\"\r\n          }\r\n        },\r\n        \"required\": [\r\n          \"type\"\r\n        ],\r\n        \"additionalProperties\": False,\r\n        \"if\": {\r\n          \"properties\": {\r\n            \"type\": {\r\n              \"const\": \"object\"\r\n            }\r\n          }\r\n        },\r\n        \"then\": {\r\n          \"required\": [\r\n            \"properties\"\r\n          ]\r\n        }\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nMETA_PROMPT = \"\"\"\r\n# \u6307\u4ee4\r\n\u8fd4\u56de\u4e00\u4e2a\u6709\u6548\u7684 JSON \u63cf\u8ff0\u6a21\u5f0f\u3002\r\n\r\n\u4f60\u8fd8\u9700\u8981\u786e\u4fdd\uff1a\r\n- \u5bf9\u8c61\u4e2d\u7684\u6240\u6709\u5b57\u6bb5\u90fd\u8bbe\u7f6e\u4e3a\u5fc5\u9700\u5b57\u6bb5\r\n- \u6211\u91cd\u590d\u4e00\u904d\uff0c\u6240\u6709\u5b57\u6bb5\u5fc5\u987b\u6807\u8bb0\u4e3a\u5fc5\u9700\u5b57\u6bb5\r\n- \u6240\u6709\u5bf9\u8c61\u7684 additionalProperties \u5fc5\u987b\u8bbe\u4e3a false\r\n    - \u56e0\u6b64\uff0c\u50cf\u201cattributes\u201d\u6216\u201cmetadata\u201d\u7b49\u5c5e\u6027\u901a\u5e38\u5141\u8bb8 additional properties \u7684\u60c5\u51b5\u4e0b\uff0c\u5e94\u8be5\u8bbe\u7f6e\u4e3a\u56fa\u5b9a\u7684\u5c5e\u6027\u96c6\r\n- \u6240\u6709\u5bf9\u8c61\u5fc5\u987b\u5b9a\u4e49\u5c5e\u6027\r\n- \u5b57\u6bb5\u987a\u5e8f\u5f88\u91cd\u8981\u3002\u4efb\u4f55\u5f62\u5f0f\u7684\u201c\u601d\u8003\u201d\u6216\u201c\u89e3\u91ca\u201d\u5e94\u4f4d\u4e8e\u7ed3\u8bba\u4e4b\u524d\r\n- $defs \u5fc5\u987b\u5b9a\u4e49\u5728 schema \u53c2\u6570\u4e2d\r\n\r\n\u4e0d\u652f\u6301\u7684\u5173\u952e\u8bcd\u5305\u62ec\uff1a\r\n- \u5bf9\u5b57\u7b26\u4e32\uff1aminLength, maxLength, pattern, format\r\n- \u5bf9\u6570\u5b57\uff1aminimum, maximum, multipleOf\r\n- \u5bf9\u5bf9\u8c61\uff1apatternProperties, unevaluatedProperties, propertyNames, minProperties, maxProperties\r\n- \u5bf9\u6570\u7ec4\uff1aunevaluatedItems, contains, minContains, maxContains, minItems, maxItems, uniqueItems\r\n\r\n\u5176\u4ed6\u6ce8\u610f\u4e8b\u9879\uff1a\r\n- \u652f\u6301\u5b9a\u4e49\u548c\u9012\u5f52\r\n- \u4ec5\u5728\u5fc5\u8981\u65f6\u5305\u542b\u5f15\u7528\uff0c\u4f8b\u5982 \"$defs\"\uff0c\u5b83\u5fc5\u987b\u5728 \"schema\" \u5bf9\u8c61\u5185\u90e8\r\n\r\n# \u793a\u4f8b\r\n\u8f93\u5165\uff1a\u751f\u6210\u4e00\u4e2a\u5e26\u6709\u6b65\u9aa4\u548c\u6700\u7ec8\u7b54\u6848\u7684\u6570\u5b66\u63a8\u7406\u6a21\u5f0f\u3002\r\n\u8f93\u51fa\uff1a{\r\n    \"name\": \"math_reasoning\",\r\n    \"type\": \"object\",\r\n    \"properties\": {\r\n        \"steps\": {\r\n            \"type\": \"array\",\r\n            \"description\": \"\u89e3\u7b54\u6570\u5b66\u95ee\u9898\u6240\u6d89\u53ca\u7684\u6b65\u9aa4\u5e8f\u5217\u3002\",\r\n            \"items\": {\r\n                \"type\": \"object\",\r\n                \"properties\": {\r\n                    \"explanation\": {\r\n                        \"type\": \"string\",\r\n                        \"description\": \"\u8be5\u6b65\u9aa4\u4e2d\u4f7f\u7528\u7684\u63a8\u7406\u6216\u65b9\u6cd5\u7684\u63cf\u8ff0\u3002\"\r\n                    },\r\n                    \"output\": {\r\n                        \"type\": \"string\",\r\n                        \"description\": \"\u8be5\u7279\u5b9a\u6b65\u9aa4\u7684\u7ed3\u679c\u6216\u8f93\u51fa\u3002\"\r\n                    }\r\n                },\r\n                \"required\": [\r\n                    \"explanation\",\r\n                    \"output\"\r\n                ],\r\n                \"additionalProperties\": false\r\n            }\r\n        },\r\n        \"final_answer\": {\r\n            \"type\": \"string\",\r\n            \"description\": \"\u6570\u5b66\u95ee\u9898\u7684\u6700\u7ec8\u89e3\u7b54\u3002\"\r\n        }\r\n    },\r\n    \"required\": [\r\n        \"steps\",\r\n        \"final_answer\"\r\n    ],\r\n    \"additionalProperties\": false\r\n}\r\n\r\n\u8f93\u5165\uff1a\u7ed9\u6211\u4e00\u4e2a\u94fe\u8868\r\n\u8f93\u51fa\uff1a{\r\n    \"name\": \"linked_list\",\r\n    \"type\": \"object\",\r\n    \"properties\": {\r\n        \"linked_list\": {\r\n            \"$ref\": \"#\/$defs\/linked_list_node\",\r\n            \"description\": \"\u94fe\u8868\u7684\u5934\u8282\u70b9\u3002\"\r\n        }\r\n    },\r\n    \"$defs\": {\r\n        \"linked_list_node\": {\r\n            \"type\": \"object\",\r\n            \"description\": \"\u5b9a\u4e49\u5355\u94fe\u8868\u4e2d\u7684\u4e00\u4e2a\u8282\u70b9\u3002\",\r\n            \"properties\": {\r\n                \"value\": {\r\n                    \"type\": \"number\",\r\n                    \"description\": \"\u6b64\u8282\u70b9\u4e2d\u5b58\u50a8\u7684\u503c\u3002\"\r\n                },\r\n                \"next\": {\r\n                    \"anyOf\": [\r\n                        {\r\n                            \"$ref\": \"#\/$defs\/linked_list_node\"\r\n                        },\r\n                        {\r\n                            \"type\": \"null\"\r\n                        }\r\n                    ],\r\n                    \"description\": \"\u5f15\u7528\u4e0b\u4e00\u4e2a\u8282\u70b9\uff1b\u5982\u679c\u662f\u6700\u540e\u4e00\u4e2a\u8282\u70b9\u5219\u4e3a null\u3002\"\r\n                }\r\n            },\r\n            \"required\": [\r\n                \"value\",\r\n                \"next\"\r\n            ],\r\n            \"additionalProperties\": false\r\n        }\r\n    },\r\n    \"required\": [\r\n        \"linked_list\"\r\n    ],\r\n    \"additionalProperties\": false\r\n}\r\n\r\n\u8f93\u5165\uff1a\u52a8\u6001\u751f\u6210\u7684 UI\r\n\u8f93\u51fa\uff1a{\r\n    \"name\": \"ui\",\r\n    \"type\": \"object\",\r\n    \"properties\": {\r\n        \"type\": {\r\n            \"type\": \"string\",\r\n            \"description\": \"UI \u7ec4\u4ef6\u7684\u7c7b\u578b\",\r\n            \"enum\": [\r\n                \"div\",\r\n                \"button\",\r\n                \"header\",\r\n                \"section\",\r\n                \"field\",\r\n                \"form\"\r\n            ]\r\n        },\r\n        \"label\": {\r\n            \"type\": \"string\",\r\n            \"description\": \"UI \u7ec4\u4ef6\u7684\u6807\u7b7e\uff0c\u7528\u4e8e\u6309\u94ae\u6216\u8868\u5355\u5b57\u6bb5\"\r\n        },\r\n        \"children\": {\r\n            \"type\": \"array\",\r\n            \"description\": \"\u5d4c\u5957\u7684 UI \u7ec4\u4ef6\",\r\n            \"items\": {\r\n                \"$ref\": \"#\"\r\n            }\r\n        },\r\n        \"attributes\": {\r\n            \"type\": \"array\",\r\n            \"description\": \"\u9002\u7528\u4e8e\u4efb\u4f55\u5143\u7d20\u7684 UI \u7ec4\u4ef6\u7684\u4efb\u610f\u5c5e\u6027\",\r\n            \"items\": {\r\n                \"type\": \"object\",\r\n                \"properties\": {\r\n                    \"name\": {\r\n                        \"type\": \"string\",\r\n                        \"description\": \"\u5c5e\u6027\u540d\u79f0\uff0c\u4f8b\u5982 onClick \u6216 className\"\r\n                    },\r\n                    \"value\": {\r\n                        \"type\": \"string\",\r\n                        \"description\": \"\u5c5e\u6027\u7684\u503c\"\r\n                    }\r\n                },\r\n                \"required\": [\r\n                    \"name\",\r\n                    \"value\"\r\n                ],\r\n                \"additionalProperties\": false\r\n            }\r\n        }\r\n    },\r\n    \"required\": [\r\n        \"type\",\r\n        \"label\",\r\n        \"children\",\r\n        \"attributes\"\r\n    ],\r\n    \"additionalProperties\": false\r\n}\r\n\"\"\".strip()\r\n\r\ndef generate_schema(description: str):\r\n    completion = client.chat.completions.create(\r\n        model=\"gpt-4o-mini\",\r\n        response_format={\"type\": \"json_schema\", \"json_schema\": META_SCHEMA},\r\n        messages=[\r\n            {\r\n                \"role\": \"system\",\r\n                \"content\": META_PROMPT,\r\n            },\r\n            {\r\n                \"role\": \"user\",\r\n                \"content\": \"Description:\\n\" + description,\r\n            },\r\n        ],\r\n    )\r\n\r\n    return json.loads(completion.choices[0].message.content)\r\n<\/code><\/pre>\n<p><strong>\u51fd\u6570\u6a21\u5f0f<\/strong><\/p>\n<pre><code>from openai import OpenAI\r\nimport json\r\n\r\nclient = OpenAI()\r\n\r\nMETA_SCHEMA = {\r\n  \"name\": \"function-metaschema\",\r\n  \"schema\": {\r\n    \"type\": \"object\",\r\n    \"properties\": {\r\n      \"name\": {\r\n        \"type\": \"string\",\r\n        \"description\": \"\u51fd\u6570\u7684\u540d\u79f0\"\r\n      },\r\n      \"description\": {\r\n        \"type\": \"string\",\r\n        \"description\": \"\u5bf9\u51fd\u6570\u7684\u63cf\u8ff0\"\r\n      },\r\n      \"parameters\": {\r\n        \"$ref\": \"#\/$defs\/schema_definition\",\r\n        \"description\": \"\u5b9a\u4e49\u51fd\u6570\u53c2\u6570\u7684 JSON schema\"\r\n      }\r\n    },\r\n    \"required\": [\r\n      \"name\",\r\n      \"description\",\r\n      \"parameters\"\r\n    ],\r\n    \"additionalProperties\": False,\r\n    \"$defs\": {\r\n      \"schema_definition\": {\r\n        \"type\": \"object\",\r\n        \"properties\": {\r\n          \"type\": {\r\n            \"type\": \"string\",\r\n            \"enum\": [\r\n              \"object\",\r\n              \"array\",\r\n              \"string\",\r\n              \"number\",\r\n              \"boolean\",\r\n              \"null\"\r\n            ]\r\n          },\r\n          \"properties\": {\r\n            \"type\": \"object\",\r\n            \"additionalProperties\": {\r\n              \"$ref\": \"#\/$defs\/schema_definition\"\r\n            }\r\n          },\r\n          \"items\": {\r\n            \"anyOf\": [\r\n              {\r\n                \"$ref\": \"#\/$defs\/schema_definition\"\r\n              },\r\n              {\r\n                \"type\": \"array\",\r\n                \"items\": {\r\n                  \"$ref\": \"#\/$defs\/schema_definition\"\r\n                }\r\n              }\r\n            ]\r\n          },\r\n          \"required\": {\r\n            \"type\": \"array\",\r\n            \"items\": {\r\n              \"type\": \"string\"\r\n            }\r\n          },\r\n          \"additionalProperties\": {\r\n            \"type\": \"boolean\"\r\n          }\r\n        },\r\n        \"required\": [\r\n          \"type\"\r\n        ],\r\n        \"additionalProperties\": False,\r\n        \"if\": {\r\n          \"properties\": {\r\n            \"type\": {\r\n              \"const\": \"object\"\r\n            }\r\n          }\r\n        },\r\n        \"then\": {\r\n          \"required\": [\r\n            \"properties\"\r\n          ]\r\n        }\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nMETA_PROMPT = \"\"\"\r\n# \u6307\u793a\r\n\u8fd4\u56de\u4e00\u4e2a\u63cf\u8ff0\u51fd\u6570\u7684\u6709\u6548\u6a21\u5f0f\u3002\r\n\r\n\u7279\u522b\u6ce8\u610f\u786e\u4fdd \"required\" \u548c \"type\" \u59cb\u7ec8\u4f4d\u4e8e\u6b63\u786e\u7684\u5d4c\u5957\u7ea7\u522b\u3002\u4f8b\u5982\uff0c\"required\" \u5e94\u4e0e \"properties\" \u5904\u4e8e\u540c\u4e00\u7ea7\u522b\uff0c\u800c\u4e0d\u662f\u5728\u5176\u5185\u90e8\u3002\r\n\u786e\u4fdd\u6bcf\u4e2a\u5c5e\u6027\uff0c\u65e0\u8bba\u591a\u77ed\uff0c\u90fd\u6709\u4e00\u4e2a\u6b63\u786e\u5d4c\u5957\u7684\u7c7b\u578b\u548c\u63cf\u8ff0\u3002\r\n\r\n# \u793a\u4f8b\r\n\u8f93\u5165: \u4e3a\u795e\u7ecf\u7f51\u7edc\u8d85\u53c2\u6570\u5206\u914d\u503c\r\n\u8f93\u51fa: {\r\n    \"name\": \"set_hyperparameters\",\r\n    \"description\": \"\u4e3a\u795e\u7ecf\u7f51\u7edc\u8d85\u53c2\u6570\u5206\u914d\u503c\",\r\n    \"parameters\": {\r\n        \"type\": \"object\",\r\n        \"required\": [\r\n            \"learning_rate\",\r\n            \"epochs\"\r\n        ],\r\n        \"properties\": {\r\n            \"epochs\": {\r\n                \"type\": \"number\",\r\n                \"description\": \"\u6570\u636e\u96c6\u7684\u5b8c\u6574\u904d\u5386\u6b21\u6570\"\r\n            },\r\n            \"learning_rate\": {\r\n                \"type\": \"number\",\r\n                \"description\": \"\u6a21\u578b\u5b66\u4e60\u901f\u5ea6\"\r\n            }\r\n        }\r\n    }\r\n}\r\n\r\n\u8f93\u5165: \u4e3a\u673a\u5668\u4eba\u89c4\u5212\u8fd0\u52a8\u8def\u5f84\r\n\u8f93\u51fa: {\r\n    \"name\": \"plan_motion\",\r\n    \"description\": \"\u4e3a\u673a\u5668\u4eba\u89c4\u5212\u8fd0\u52a8\u8def\u5f84\",\r\n    \"parameters\": {\r\n        \"type\": \"object\",\r\n        \"required\": [\r\n            \"start_position\",\r\n            \"end_position\"\r\n        ],\r\n        \"properties\": {\r\n            \"end_position\": {\r\n                \"type\": \"object\",\r\n                \"properties\": {\r\n                    \"x\": {\r\n                        \"type\": \"number\",\r\n                        \"description\": \"\u7ec8\u70b9 X \u5750\u6807\"\r\n                    },\r\n                    \"y\": {\r\n                        \"type\": \"number\",\r\n                        \"description\": \"\u7ec8\u70b9 Y \u5750\u6807\"\r\n                    }\r\n                }\r\n            },\r\n            \"obstacles\": {\r\n                \"type\": \"array\",\r\n                \"description\": \"\u969c\u788d\u7269\u5750\u6807\u6570\u7ec4\",\r\n                \"items\": {\r\n                    \"type\": \"object\",\r\n                    \"properties\": {\r\n                        \"x\": {\r\n                            \"type\": \"number\",\r\n                            \"description\": \"\u969c\u788d\u7269 X \u5750\u6807\"\r\n                        },\r\n                        \"y\": {\r\n                            \"type\": \"number\",\r\n                            \"description\": \"\u969c\u788d\u7269 Y \u5750\u6807\"\r\n                        }\r\n                    }\r\n                }\r\n            },\r\n            \"start_position\": {\r\n                \"type\": \"object\",\r\n                \"properties\": {\r\n                    \"x\": {\r\n                        \"type\": \"number\",\r\n                        \"description\": \"\u8d77\u70b9 X \u5750\u6807\"\r\n                    },\r\n                    \"y\": {\r\n                        \"type\": \"number\",\r\n                        \"description\": \"\u8d77\u70b9 Y \u5750\u6807\"\r\n                    }\r\n                }\r\n            }\r\n        }\r\n    }\r\n}\r\n\r\n\u8f93\u5165: \u8ba1\u7b97\u5404\u79cd\u6280\u672f\u6307\u6807\r\n\u8f93\u51fa: {\r\n    \"name\": \"technical_indicator\",\r\n    \"description\": \"\u8ba1\u7b97\u5404\u79cd\u6280\u672f\u6307\u6807\",\r\n    \"parameters\": {\r\n        \"type\": \"object\",\r\n        \"required\": [\r\n            \"ticker\",\r\n            \"indicators\"\r\n        ],\r\n        \"properties\": {\r\n            \"indicators\": {\r\n                \"type\": \"array\",\r\n                \"description\": \"\u8981\u8ba1\u7b97\u7684\u6280\u672f\u6307\u6807\u5217\u8868\",\r\n                \"items\": {\r\n                    \"type\": \"string\",\r\n                    \"description\": \"\u6280\u672f\u6307\u6807\",\r\n                    \"enum\": [\r\n                        \"RSI\",\r\n                        \"MACD\",\r\n                        \"Bollinger_Bands\",\r\n                        \"Stochastic_Oscillator\"\r\n                    ]\r\n                }\r\n            },\r\n            \"period\": {\r\n                \"type\": \"number\",\r\n                \"description\": \"\u5206\u6790\u7684\u65f6\u95f4\u5468\u671f\"\r\n            },\r\n            \"ticker\": {\r\n                \"type\": \"string\",\r\n                \"description\": \"\u80a1\u7968\u4ee3\u7801\"\r\n            }\r\n        }\r\n    }\r\n}\r\n\"\"\".strip()\r\n\r\ndef generate_function_schema(description: str):\r\n    completion = client.chat.completions.create(\r\n        model=\"gpt-4o-mini\",\r\n        response_format={\"type\": \"json_schema\", \"json_schema\": META_SCHEMA},\r\n        messages=[\r\n            {\r\n                \"role\": \"system\",\r\n                \"content\": META_PROMPT,\r\n            },\r\n            {\r\n                \"role\": \"user\",\r\n                \"content\": \"\u63cf\u8ff0:\\n\" + description,\r\n            },\r\n        ],\r\n    )\r\n\r\n    return json.loads(completion.choices[0].message.content)<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u63d0\u793a\u751f\u6210 \u5728\u00a0Playground\u00a0\u4e2d\u7684\u00a0Generate\u00a0\u6309\u94ae\u8ba9\u60a8\u53ef\u4ee5\u901a\u8fc7\u4efb\u52a1\u63cf\u8ff0\u751f\u6210\u63d0\u793a\u3001\u51fd\u6570\u548c\u67b6\u6784\u3002\u672c\u6307\u5357\u5c06\u9010\u6b65\u8bb2\u89e3\u5176\u5de5\u4f5c\u539f\u7406\u3002 \u6982\u8ff0 \u4ece\u5934\u521b\u5efa\u63d0\u793a\u548c\u67b6\u6784\u53ef\u80fd\u8017\u65f6\uff0c\u901a\u8fc7\u751f\u6210\u5b83\u4eec\u53ef\u4ee5\u5e2e\u52a9\u60a8\u5feb\u901f\u5165\u624b\u3002Generate \u6309\u94ae\u4e3b\u8981\u4f7f\u7528\u4ee5\u4e0b\u4e24\u79cd&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-8155","post","type-post","status-publish","format-standard","hentry","category-prompts"],"_links":{"self":[{"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/posts\/8155","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/comments?post=8155"}],"version-history":[{"count":0,"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/posts\/8155\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/media?parent=8155"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/categories?post=8155"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kdjingpai.com\/pt\/wp-json\/wp\/v2\/tags?post=8155"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}