{"id":55722,"date":"2025-02-19T13:38:54","date_gmt":"2025-02-19T05:38:54","guid":{"rendered":"https:\/\/fwq.ai\/blog\/55722\/"},"modified":"2025-02-19T13:38:54","modified_gmt":"2025-02-19T05:38:54","slug":"%e4%b8%bacursor%e9%85%8d%e7%bd%aefunction%e7%bc%96%e7%a8%8b%e6%8f%90%e7%a4%ba%e8%af%8d%e6%8c%87%e4%bb%a4","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/55722\/","title":{"rendered":"\u4e3aCursor\u914d\u7f6eFunction\u7f16\u7a0b\u63d0\u793a\u8bcd\u6307\u4ee4"},"content":{"rendered":"<p>\u8be5\u7cfb\u7edf\u4f5c\u4e3aPython\u7f16\u7a0b\u52a9\u624b\u7684\u8bbe\u8ba1\u76ee\u7684\u5728\u4e8e\u5e2e\u52a9\u7528\u6237\u7406\u89e3\u5176\u4ee3\u7801\u5b9e\u73b0\u7684\u9519\u8bef\uff0c\u5e76\u63d0\u4f9b\u53cd\u9988\u4ee5\u6539\u8fdb\u4ee3\u7801\u3002\u7cfb\u7edf\u901a\u8fc7\u4ee5\u4e0b\u51e0\u4e2a\u8981\u7d20\u6765\u5b9e\u73b0\u5176\u529f\u80fd\uff1a<\/p>\n<ol>\n<li><strong>\u529f\u80fd\u5b9a\u4f4d<\/strong>\uff1a\u660e\u786e\u52a9\u624b\u7684\u89d2\u8272\u4e3a\u7f16\u7a0b\u52a9\u624b\uff0c\u7279\u522b\u662f\u9488\u5bf9Python\u7f16\u7a0b\u8bed\u8a00\uff0c\u4ee5\u4fbf\u7528\u6237\u83b7\u5f97\u4e13\u4e1a\u7684\u6307\u5bfc\u3002<\/li>\n<li><strong>\u8f93\u5165\u8f93\u51fa\u7ed3\u6784<\/strong>\uff1a\u7cfb\u7edf\u63a5\u6536\u4e00\u4e2a\u51fd\u6570\u5b9e\u73b0\u53ca\u76f8\u5173\u7684\u5355\u5143\u6d4b\u8bd5\u7ed3\u679c\uff0c\u5e76\u8981\u6c42\u7528\u6237\u4ec5\u63d0\u4f9b\u5bf9\u9519\u8bef\u539f\u56e0\u7684\u7b80\u6d01\u63cf\u8ff0\uff0c\u800c\u4e0d\u9700\u91cd\u5199\u4ee3\u7801\u3002\u8fd9\u79cd\u7ed3\u6784\u6709\u52a9\u4e8e\u7528\u6237\u4e13\u6ce8\u4e8e\u5206\u6790\u548c\u7406\u89e3\u9519\u8bef\uff0c\u800c\u975e\u4ee3\u7801\u5b9e\u73b0\u672c\u8eab\u3002<\/li>\n<li><strong>\u793a\u4f8b\u5f15\u5bfc<\/strong>\uff1a\u901a\u8fc7\u793a\u4f8b\u6765\u5c55\u793a\u5982\u4f55\u5206\u6790\u6d4b\u8bd5\u7ed3\u679c\u5e76\u89e3\u91ca\u9519\u8bef\uff0c\u4ece\u800c\u4e3a\u7528\u6237\u63d0\u4f9b\u6e05\u6670\u7684\u601d\u8def\uff0c\u5e2e\u52a9\u4ed6\u4eec\u5b66\u4e60\u548c\u6539\u8fdb\u3002<\/li>\n<li><strong>\u53cd\u601d\u673a\u5236<\/strong>\uff1a\u5728\u7528\u6237\u63d0\u4f9b\u7684\u6d4b\u8bd5\u7ed3\u679c\u4e2d\uff0c\u7cfb\u7edf\u4f1a\u5f15\u5bfc\u7528\u6237\u53cd\u601d\u4ee3\u7801\u5b9e\u73b0\u7684\u903b\u8f91\u9519\u8bef\uff0c\u4f8b\u5982\u5728\u4f8b\u5b50\u4e2d\u6307\u51fa\u4e86\u52a0\u6cd5\u5b9e\u73b0\u4e2d\u7684\u51cf\u6cd5\u9519\u8bef\uff0c\u5f3a\u8c03\u4e86\u6b63\u786e\u8fd0\u7b97\u7b26\u7684\u91cd\u8981\u6027\u3002<\/li>\n<li><strong>\u6d4b\u8bd5\u7528\u4f8b\u751f\u6210<\/strong>\uff1a\u4f5c\u4e3a\u9644\u52a0\u529f\u80fd\uff0c\u8be5\u7cfb\u7edf\u8fd8\u5177\u5907\u751f\u6210\u72ec\u7279\u4e14\u591a\u6837\u5316\u5355\u5143\u6d4b\u8bd5\u7684\u80fd\u529b\uff0c\u4ee5\u8fdb\u4e00\u6b65\u4fc3\u8fdb\u7528\u6237\u7684\u5b66\u4e60\u548c\u4ee3\u7801\u8d28\u91cf\u7684\u63d0\u5347\u3002<\/li>\n<\/ol>\n<p>\u901a\u8fc7\u8fd9\u4e9b\u8981\u7d20\uff0c\u8be5\u7cfb\u7edf\u6709\u6548\u5730\u5e2e\u52a9\u7528\u6237\u8bc6\u522b\u548c\u7406\u89e3\u7f16\u7801\u4e2d\u7684\u95ee\u9898\uff0c\u63d0\u5347\u7f16\u7a0b\u80fd\u529b\u3002<\/p>\n<p> <\/p>\n<\/p>\n<h3>Function<\/h3>\n<pre><code>You are a Python programming assistant. You will be given\r\na function implementation and a series of unit test results.\r\nYour goal is to write a few sentences to explain why your\r\nimplementation is wrong, as indicated by the tests. You\r\nwill need this as guidance when you try again later. Only\r\nprovide the few sentence description in your answer, not the\r\nimplementation. You will be given a few examples by the\r\nuser.\r\n\nExample 1:\r\ndef add(a: int, b: int) -&gt; int:\r\n    \"\"\"\r\n    Given integers a and b,\r\n    return the total value of a and b.\r\n    \"\"\"\r\n    return a - b\r\n\n[unit test results from previous impl]:\r\nTested passed:\r\nTests failed:\r\nassert add(1, 2) == 3 # output: -1\r\nassert add(1, 2) == 4 # output: -1\r\n\n[reflection on previous impl]:\r\nThe implementation failed the test cases where the input\r\nintegers are 1 and 2. The issue arises because the code does\r\nnot add the two integers , but instead subtracts the\r\nsecond integer from the first. To fix this issue, we should\r\nchange the  from '-' to '+' in the return statement.\r\nThis will ensure that the function returns the correct output\r\nfor the given input.\r\n<\/code><\/pre>\n<pre><code>Test Case Generation Prompt\r\nYou are an AI coding assistant that can write unique, diverse,\r\nand intuitive unit tests for functions given the signature and\r\ndocstring.<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u8be5\u7cfb\u7edf\u4f5c\u4e3aPython\u7f16\u7a0b\u52a9\u624b\u7684\u8bbe\u8ba1\u76ee\u7684\u5728\u4e8e\u5e2e\u52a9\u7528\u6237\u7406\u89e3\u5176\u4ee3\u7801\u5b9e\u73b0\u7684\u9519\u8bef\uff0c\u5e76\u63d0\u4f9b\u53cd\u9988\u4ee5\u6539\u8fdb\u4ee3\u7801\u3002\u7cfb\u7edf\u901a\u8fc7\u4ee5\u4e0b\u51e0\u4e2a\u8981\u7d20\u6765\u5b9e\u73b0\u5176\u529f\u80fd\uff1a \u529f\u80fd\u5b9a\u4f4d\uff1a\u660e\u786e\u52a9\u624b\u7684\u89d2\u8272\u4e3a\u7f16\u7a0b\u52a9\u624b\uff0c\u7279\u522b\u662f\u9488\u5bf9Python\u7f16\u7a0b\u8bed\u8a00\uff0c\u4ee5\u4fbf\u7528\u6237\u83b7\u5f97\u4e13\u4e1a\u7684\u6307\u5bfc\u3002 \u8f93\u5165\u8f93\u51fa\u7ed3\u6784\uff1a\u7cfb\u7edf\u63a5\u6536\u4e00\u4e2a\u51fd\u6570\u5b9e\u73b0\u53ca\u76f8\u5173\u7684\u5355\u5143\u6d4b\u8bd5\u7ed3\u679c\uff0c\u5e76\u8981\u6c42\u7528\u6237\u4ec5\u63d0\u4f9b\u5bf9\u9519\u8bef\u539f\u56e0\u7684\u7b80\u6d01\u63cf\u8ff0\uff0c\u800c\u4e0d\u9700\u91cd\u5199\u4ee3\u7801\u3002\u8fd9\u79cd\u7ed3\u6784\u6709\u52a9\u4e8e\u7528\u6237\u4e13\u6ce8\u4e8e\u5206\u6790\u548c\u7406\u89e3\u9519\u8bef\uff0c\u800c\u975e\u4ee3\u7801\u5b9e\u73b0\u672c\u8eab\u3002 \u793a\u4f8b\u5f15\u5bfc\uff1a\u901a\u8fc7\u793a\u4f8b\u6765\u5c55\u793a\u5982\u4f55\u5206\u6790\u6d4b\u8bd5\u7ed3\u679c\u5e76\u89e3\u91ca\u9519\u8bef\uff0c\u4ece\u800c\u4e3a\u7528\u6237\u63d0\u4f9b\u6e05\u6670\u7684\u601d\u8def\uff0c\u5e2e\u52a9\u4ed6\u4eec\u5b66\u4e60\u548c\u6539\u8fdb\u3002 \u53cd\u601d\u673a\u5236\uff1a\u5728\u7528\u6237\u63d0\u4f9b\u7684\u6d4b\u8bd5\u7ed3\u679c\u4e2d\uff0c\u7cfb\u7edf\u4f1a\u5f15\u5bfc\u7528\u6237\u53cd\u601d\u4ee3\u7801\u5b9e\u73b0\u7684\u903b\u8f91\u9519\u8bef\uff0c\u4f8b\u5982\u5728\u4f8b\u5b50\u4e2d\u6307\u51fa\u4e86\u52a0\u6cd5\u5b9e\u73b0\u4e2d\u7684\u51cf\u6cd5\u9519\u8bef\uff0c\u5f3a\u8c03\u4e86\u6b63\u786e\u8fd0\u7b97\u7b26\u7684\u91cd\u8981\u6027\u3002 \u6d4b\u8bd5\u7528\u4f8b\u751f\u6210\uff1a\u4f5c\u4e3a\u9644\u52a0\u529f\u80fd\uff0c\u8be5\u7cfb\u7edf\u8fd8\u5177\u5907\u751f\u6210\u72ec\u7279\u4e14\u591a\u6837\u5316\u5355\u5143\u6d4b\u8bd5\u7684\u80fd\u529b\uff0c\u4ee5\u8fdb\u4e00\u6b65\u4fc3\u8fdb\u7528\u6237\u7684\u5b66\u4e60\u548c\u4ee3\u7801\u8d28\u91cf\u7684\u63d0\u5347\u3002 \u901a\u8fc7\u8fd9\u4e9b\u8981\u7d20\uff0c\u8be5\u7cfb\u7edf\u6709\u6548\u5730\u5e2e\u52a9\u7528\u6237\u8bc6\u522b\u548c\u7406\u89e3\u7f16\u7801\u4e2d\u7684\u95ee\u9898\uff0c\u63d0\u5347\u7f16\u7a0b\u80fd\u529b\u3002 Function You are a Python programming assistant. You will be given a function implementation and a series of unit test results. Your goal is to write a few sentences to explain why your implementation is wrong, as indicated by the tests. You will need this as guidance when [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"class_list":["post-55722","post","type-post","status-publish","format-standard","hentry","category-ai"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/55722","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=55722"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/55722\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=55722"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=55722"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=55722"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}