{"id":53737,"date":"2025-02-16T11:33:35","date_gmt":"2025-02-16T03:33:35","guid":{"rendered":"https:\/\/fwq.ai\/blog\/53737\/"},"modified":"2025-02-16T11:33:35","modified_gmt":"2025-02-16T03:33:35","slug":"ai%e5%bc%80%e5%8f%91%e5%bf%85%e5%a4%87%e7%9a%843%e4%b8%aadspy%e6%8a%80%e5%b7%a7","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/53737\/","title":{"rendered":"AI\u5f00\u53d1\u5fc5\u5907\u76843\u4e2aDSPy\u6280\u5de7"},"content":{"rendered":"<p>DSPy \u662f\u6211\u7684\u9996\u9009\u6846\u67b6\uff0c\u56e0\u4e3a\u5b83\u7b80\u5355\u4e14\u8bbe\u8ba1\u5468\u5230\u3002\u6211\u4f7f\u7528\u5b83\u505a\u4e86\u5f88\u591a\u4e8b\u60c5\uff0c\u4ece\u6784\u5efa MVP \u5230\u6269\u5c55\u7cfb\u7edf\u4ee5\u5904\u7406\u6570\u767e\u4e07\u4e2a\u8bf7\u6c42\u3002\u867d\u7136 DSPy \u548c AI \u7f16\u7a0b\u4ecd\u5728\u4e0d\u65ad\u53d1\u5c55\uff0c\u4f46\u627e\u5230\u6e05\u6670\u3001\u53ef\u7528\u4e8e\u751f\u4ea7\u7684\u6307\u5bfc\u53ef\u80fd\u5f88\u56f0\u96be\u3002<\/p>\n<p>\u5728\u8fd9\u7bc7\u535a\u5ba2\u4e2d\uff0c\u6211\u5206\u4eab\u4e86\u6211\u6240\u5b66\u5230\u7684\u4e1c\u897f\u2014\u2014\u4ece\u5b9e\u8df5\u7ecf\u9a8c\u5230\u6587\u6863\u548c GitHub \u8ba8\u8bba\u4e2d\u7684\u89c1\u89e3\u3002\u8fd9\u662f\u4e00\u672c\u5b9e\u7528\u6307\u5357\uff0c\u91cc\u9762\u5145\u6ee1\u4e86\u4f7f\u7528 DSPy \u7684\u53ef\u884c\u6280\u5de7\u3002<\/p>\n<h2>1\u3001\u53ef\u9760\u7684\u8f93\u51fa<\/h2>\n<p>\u5bf9\u4e8e\u4f7f\u7528 LLM \u7684\u5f00\u53d1\u4eba\u5458\u6765\u8bf4\uff0c\u6700\u5927\u7684\u6311\u6218\u662f\u5b9e\u73b0\u7ed3\u6784\u5316\u548c\u4e00\u81f4\u7684\u8f93\u51fa\u3002\u8ba9\u4f60\u7684\u4ee3\u7406\u5de5\u4f5c\u662f\u4e00\u56de\u4e8b\uff0c\u4f46\u786e\u4fdd 95% \u4ee5\u4e0a\u7684\u53ef\u9760\u6027\u662f\u53e6\u4e00\u56de\u4e8b\u3002\u6700\u7ec8\u7528\u6237\u6bcf\u6b21\u90fd\u5e0c\u671b\u83b7\u5f97\u826f\u597d\u7684\u7ed3\u679c \u2014 \u4ed6\u4eec\u4e0d\u5728\u4e4e LLM \u662f\u5426\u5bb9\u6613\u51fa\u73b0\u5e7b\u89c9\u3001\u4e0d\u4e00\u81f4\u6216\u5076\u5c14\u51fa\u73b0\u4e0d\u7a33\u5b9a\u884c\u4e3a\u3002<\/p>\n<p>\u867d\u7136\u6709\u4e9b\u95ee\u9898\uff08\u5982 API \u63d0\u4f9b\u5546\u4e2d\u65ad\uff09\u8d85\u51fa\u4e86\u4f60\u7684\u63a7\u5236\u8303\u56f4\uff0c\u4f46\u4f60\u53ef\u4ee5\u5728\u81ea\u5df1\u8fd9\u8fb9\u89e3\u51b3\u8bb8\u591a\u95ee\u9898\u3002\u4f7f\u7528 DSPy\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u65ad\u8a00\u548c\u5efa\u8bae\u6765\u6307\u5bfc\u4f60\u7684\u7a0b\u5e8f\u83b7\u5f97\u66f4\u597d\u7684\u8f93\u51fa\u5e76\u63d0\u9ad8\u53ef\u9760\u6027\u3002\u8fd9\u4e9b\u5de5\u5177\u8fd8\u6709\u52a9\u4e8e\u6355\u83b7\u4e0d\u826f\u7ed3\u679c\u5e76\u5b9e\u65bd\u81ea\u52a8\u91cd\u8bd5\u673a\u5236\u4ee5\u786e\u4fdd\u9ad8\u8d28\u91cf\u7684\u54cd\u5e94\u3002<\/p>\n<p>\u5982\u4f55\u4f7f\u7528 <code>dspy.Assert<\/code> \u548c <code>dspy.Suggest<\/code> \uff1f<\/p>\n<p>\u8981\u5728 DSPy \u4e2d\u4f7f\u7528 <code>dspy.Assert<\/code> \u548c <code>dspy.Suggest<\/code>\uff0c \u4f60\u9700\u8981\u4f7f\u7528\u5e03\u5c14\u9a8c\u8bc1\u68c0\u67e5\u5728\u7a0b\u5e8f\u4e2d\u5b9a\u4e49\u7ea6\u675f\u4ee5\u83b7\u5f97\u6240\u9700\u7684\u7ed3\u679c\u3002\u8fd9\u4e9b\u7ea6\u675f\u88ab\u5b9e\u73b0\u4e3a\u9a8c\u8bc1\u6a21\u578b\u8f93\u51fa\u7684\u7b80\u5355 Python \u51fd\u6570\u3002<\/p>\n<p>\u4e3b\u8981\u533a\u522b\u5728\u4e8e\u5b83\u4eec\u7684\u4e25\u683c\u6027\uff1a<\/p>\n<ul>\n<li><code>Assert<\/code> \u5f3a\u5236\u6267\u884c\u7a0b\u5e8f\u5fc5\u987b\u6ee1\u8db3\u7684\u4e25\u683c\u6761\u4ef6\uff1b\u5426\u5219\uff0c\u5b83\u5c06\u5931\u8d25\u3002<\/li>\n<li><code>Suggest<\/code> \u63d0\u4f9b\u975e\u5f3a\u5236\u6027\u5efa\u8bae\u4ee5\u63d0\u9ad8\u6027\u80fd\u6216\u8f93\u51fa\u8d28\u91cf\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0b\u662f\u5982\u4f55\u9a8c\u8bc1\u7b80\u5355 DSPy \u6a21\u5757\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>from dspy.primitives.assertions import assert_transform_module, backtrack_handler\n# Define a validation function\n# You can define you our validation function that is specific to your program\n\n# Overly simplistic validation function\ndef your_validation_fn(model_outputs):\n    return model_outputs.one_word_answer == \"Islamabad\"\n\n# A simple DSPy program that gives a one-word answer to question\nyour_module = dspy.ChainOfThought(\"question-&gt;one_word_answer\")\n\nmodel_outputs = my_module(question=\"What is the capital of Pakistan?\")\n\n# Add assertions to your program\n\ndspy.Assert(your_validation_fn(model_outputs), \"Validation failed\", target_module=your_module)\ndspy.Suggest(your_validation_fn(model_outputs), \"Consider revising output\", target_module=your_module)\n<\/code><\/pre>\n<p>\u4f60\u751a\u81f3\u53ef\u4ee5\u5c06\u65ad\u8a00\u6dfb\u52a0\u5230\u81ea\u5b9a\u4e49\u7a0b\u5e8f\u7684 forward \u51fd\u6570\u4e2d\u3002\u5b9a\u4e49\u8fd9\u4e9b\u7ea6\u675f\u540e\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528 <code>assert_transform_module<\/code> \u51fd\u6570\u548c <code>backtrack_handler<\/code> \u5c06 DSPy \u6a21\u5757\u4e0e\u65ad\u8a00\u5305\u88c5\u5728\u4e00\u8d77\uff0c\u5c06\u5b83\u4eec\u96c6\u6210\u5230\u7a0b\u5e8f\u4e2d\u3002\u6b64\u51fd\u6570\u4f1a\u8f6c\u6362\u4f60\u7684\u7a0b\u5e8f\u4ee5\u5305\u542b\u5185\u90e8\u65ad\u8a00\u56de\u6eaf\u548c\u91cd\u8bd5\u903b\u8f91\u3002<\/p>\n<pre><code>class one_word_answer(dspy.Module):\n    def __init__(self):\n        self.one_word_program = dspy.ChainOfThought(\"question-&gt;one_word_answer\")\n\n    def forward(self, question):\n        # send the question to the one_word_program\n        response = self.one_word_program(question=question)\n        # Assertion checks if the output is a single word\n        dspy.Assert(response.one_word_answer.count(\" \") == 0, \"Validation failed, not one word\", target_module=self.one_word_program)\n        return response\n\nmy_module = one_word_answer()\n\n# 1. way to activate assertions in the module, so whenever assertion fails, it will throw error\nprogram_with_assertions = assert_transform_module(my_module(), backtrack_handler)\n\n# 2. way to activate assertions\n\nprogram_with_assertions = my_module().activate_assertions()\n\n# Whenever the output is not a one word, or has space, then program will throw\n# an error.<\/code><\/pre>\n<p>  \u5982\u679c\u8f93\u51fa\u9a8c\u8bc1\u5931\u8d25\uff0c\u4f60\u5c06\u6536\u5230\u9519\u8bef\uff0c\u4f60\u53ef\u4ee5\u6355\u83b7\u6b64\u9519\u8bef\u5e76\u5b9e\u65bd\u89e3\u51b3\u65b9\u6848 <\/p>\n<h2>2\u3001\u4f7f\u7528\u591a\u4e2a\u5927\u578b\u8bed\u8a00\u6a21\u578b<\/h2>\n<p>\u5927\u578b\u7a0b\u5e8f\u901a\u5e38\u9700\u8981\u591a\u4e2a LLM\u3002\u539f\u56e0\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li>\u6210\u672c\uff1a\u5f53\u4f60\u4f7f\u7528\u9876\u7ea7\u6a21\u578b\u5904\u7406 1000 \u4e2a\u8bf7\u6c42\u65f6\uff0c\u4f1a\u5bfc\u81f4\u9ad8\u6602\u7684\u6210\u672c\uff0c\u56e0\u4e3a\u5176\u4e2d\u8bb8\u591a\u8bf7\u6c42\u53ef\u4ee5\u7528\u4f4e\u7aef\u6a21\u578b\u6765\u5904\u7406\u3002<\/li>\n<li>\u901f\u5ea6\uff1a\u6240\u6709 LLM API \u63d0\u4f9b\u5546\u90fd\u6709\u57fa\u4e8e\u5c42\u7ea7\u7684\u8bf7\u6c42\u9650\u5236\uff0c\u4f46\u4f60\u7684\u7528\u6237\u8bf7\u6c42\u9700\u8981\u53ca\u65f6\u5f97\u5230\u5904\u7406\u3002\u4f60\u53ef\u4ee5\u5c06\u8bf7\u6c42\u53d1\u9001\u5230\u4e0d\u540c\u7684 API \u6216\u6a21\u578b\u3002<\/li>\n<li>\u8f93\u51fa\u8d28\u91cf\uff1a\u4f60\u53ef\u4ee5\u67e5\u770b LLM \u57fa\u51c6\uff0c\u770b\u770b\u54ea\u4e2a\u6a21\u578b\u5728\u5904\u7406\u67d0\u4e9b\u8bf7\u6c42\u65b9\u9762\u505a\u5f97\u66f4\u597d\u3002\u6709\u4e9b\u6a21\u578b\u5728\u4ee3\u7801\u751f\u6210\u65b9\u9762\u8868\u73b0\u66f4\u597d\uff08\u5c24\u5176\u662f\u5728\u8c03\u6574\u6210\u672c\u540e\uff09\u3002<\/li>\n<li>\u7cfb\u7edf\u8fc7\u8f7d\uff1a\u8bb8\u591a\u4f01\u4e1a\u7528\u4f8b\u66f4\u559c\u6b22\u672c\u5730\u6258\u7ba1\u7684 LLM\uff0c\u5c06\u6240\u6709\u8bf7\u6c42\u53d1\u9001\u5230\u4e00\u4e2a LLM\u5bb9\u6613\u5bfc\u81f4\u7cfb\u7edf\u8fc7\u8f7d\u3002<\/li>\n<\/ul>\n<p>\u5728 DSPy \u4e2d\uff0c\u4f60\u53ef\u4ee5\u5b9a\u4e49\u4e00\u4e2a\u5168\u5c40 LLM\uff0c\u8fd9\u662f\u7cfb\u7edf\u5728\u4f60\u53d1\u51fa\u8bf7\u6c42\u65f6\u4f7f\u7528\u7684\u9ed8\u8ba4 LLM\u3002\u4f60\u53ef\u4ee5\u50cf\u8fd9\u6837\u5b9a\u4e49\u5b83\uff1a<\/p>\n<pre><code>lm = dspy.LM('openai\/gpt-4o', model_type='chat', max_tokens =1000, api_key = '&lt;&gt;')\ndspy.configure(lm=lm)<\/code><\/pre>\n<p>\u4f60\u53ef\u4ee5\u50cf\u8fd9\u6837\u5207\u6362 LM\uff0c\u4f46\u6bcf\u6b21\u66f4\u6539\u5168\u5c40\u8bbe\u7f6e\u90fd\u4f1a\u5bfc\u81f4\u95ee\u9898\uff0c\u5c24\u5176\u662f\u5728\u4f60\u53d1\u51fa\u5e76\u53d1\u8bf7\u6c42\u65f6\uff08\u5927\u578b\u7cfb\u7edf\u5f88\u5e38\u89c1\uff09\u3002<\/p>\n<p>\u5e78\u8fd0\u7684\u662f\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4e0a\u4e0b\u6587\u7ba1\u7406\u5668\u50cf\u8fd9\u6837\u5207\u6362 LLM\u3002\u5b83\u4e5f\u662f\u7ebf\u7a0b\u5b89\u5168\u7684\uff0c\u53ef\u4ee5\u5f02\u6b65\u5de5\u4f5c\u3002<\/p>\n<pre><code># Define LLMs \nlm1 = dspy.LM()\nlm2 - dspy.LM()\nlm3 = dspy.LM()\n\n# you can define these conditions inside your DSPy Module\n# The system switches based on any defined condition\nif condition1:\n  with dspy.settings.context(lm=lm1):\n    response = dspy.Predict(..) \nif condition2:\n  with dspy.settings.context(lm=lm2):\n    response = dspy.Predict(..)\nif condition3:\n  with dspy.settings.context(lm=lm3):\n    response = dspy.Predict(..)<\/code><\/pre>\n<p>\u591a\u4e2a LLM \u5f88\u597d\uff0c\u5982\u679c\u8981\u670d\u52a1\u7528\u6237\u7684\u591a\u4e2a\u8bf7\u6c42\u600e\u4e48\u529e\uff1f\u4e0b\u4e00\u7ae0\u5c06\u6559\u4f60\u5982\u4f55\u4f7f\u7528 DSPy \u8fdb\u884c\u5f02\u6b65\u6216\u5e76\u884c\u8bf7\u6c42\u3002<\/p>\n<h2>3\u3001\u5e76\u53d1\u6216\u5f02\u6b65\u8bf7\u6c42<\/h2>\n<p>\u6784\u5efa\u6700\u5c0f\u53ef\u884c\u539f\u578b\u5f88\u7b80\u5355\uff0c\u56e0\u4e3a\u5b83\u4eec\u901a\u5e38\u4e00\u6b21\u53ea\u670d\u52a1\u4e00\u4e2a\u7528\u6237\u3002\u4f46\u662f\u5f53\u4f60\u9700\u8981\u6269\u5c55\u4ee5\u5904\u7406\u6570\u4e07\u751a\u81f3\u6570\u767e\u4e07\u4e2a\u8bf7\u6c42\u65f6\u4f1a\u53d1\u751f\u4ec0\u4e48\uff1f\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u4f60\u53ef\u4ee5\u5229\u7528\u7ebf\u7a0b\u6216\u5f02\u6b65\u8bf7\u6c42\u6765\u6709\u6548\u5730\u7ba1\u7406\u8d1f\u8f7d\u3002\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<h3>3.1 \u4f7f\u7528 DSPy \u8fdb\u884c\u201c\u5f02\u6b65\u5316\u201d<\/h3>\n<p>\u6b64\u4ee3\u7801\u7247\u6bb5\u5c06\u5e2e\u52a9\u4f60\u5728\u7a0b\u5e8f\u4e2d\u53d1\u51fa\u5f02\u6b65\u8bf7\u6c42\uff1a<\/p>\n<pre><code>import asyncio\n\n# set the maximum number of async workers\ndspy.settings.configure(async_max_workers=4) # default is 8\n\n# define async version of your module\n# The system was defined previously but can be any dspy.Module\nasync_system = dspy.asyncify(one_word_answer())\n\n# a simple async program\nasync def get_all_responses(questions):\n# Creates couroutines to be awaited later\n  tasks = [async_system(question=q) for q in questions]\n# You can also asyncio.wait, as_completed, wait for etc\n  responses = await asyncio.gather(*tasks)\n  return responses\n\n\n\nquestions = [\n    \"What is your name?\",\n    \"How old are you?\",\n    \"Where are you from?\",\n    \"What is your favorite hobby?\",\n    \"What do you do for a living?\",\n    \"What is your favorite programming language?\",\n    \"What are your goals for the next year?\",\n    \"What is your favorite book or movie?\",\n    \"Have you ever traveled abroad?\",\n    \"What motivates you to learn new skills?\"\n]\n\n# run the async program\nall_responses = asyncio.run(get_all_responses(questions))<\/code><\/pre>\n<p>\u4e0a\u9762\u7684\u4ee3\u7801\u7247\u6bb5\u5141\u8bb8\u4f60\u5f02\u6b65\u7b49\u5f85\u54cd\u5e94\u3002\u4f60\u53ef\u4ee5\u66f4\u6539 <code>async_max_worker<\/code> \u53c2\u6570\u4ee5\u540c\u65f6\u6269\u5c55\u5230 1000 \u4e2a\u5de5\u4f5c\u7ebf\u7a0b\u3002<\/p>\n<h3>3.2 \u4f7f\u7528 DSPy \u8fdb\u884c\u7ebf\u7a0b\u5904\u7406<\/h3>\n<p>\u5728\u6700\u65b0\u7248\u672c\u7684 dspy \u4e2d\uff0c\u6bcf\u4e2a\u6a21\u5757\u90fd\u6709\u4e00\u4e2a\u5185\u7f6e\u65b9\u6cd5 batch\uff0c\u5141\u8bb8\u4f60\u5e76\u884c\u5904\u7406\u8bf7\u6c42\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u8be5\u65b9\u6cd5\u7684\u8f93\u5165\uff1a<\/p>\n<p>  \u663e\u793a\u6279\u5904\u7406\u65b9\u6cd5\u7684\u6587\u6863 <\/p>\n<p>\u4ee3\u7801\u7247\u6bb5\uff1a<\/p>\n<pre><code>import dspy\n\n# Create questions for analysis\nquestions = [\n    \"What is the relationship between customer lifetime value and transaction frequency?\",\n    \"How does the average transaction value impact customer retention?\",\n    \"Which customer segments show the highest predicted CLV and why?\",\n    \"What are the key factors influencing the accuracy of our CLV predictions?\",\n    \"How can we improve our CLV prediction model based on the current results?\"\n]\n\n\n# Create a small DSPy Module, which gives one word answers\nsystem = dspy.ChainOfThought(\"question-&gt;one_word_answer\")\n\n# Creating examples, which can be sent to module.batch\nquestions = [dspy.Example(question=q).with_inputs('question') for q in questions]\n\n# Sends all the 5 questions in parallel, with certain settings\nresponses = system.batch(questions, num_threads = 3,return_failed_examples=True,max_errors=3)<\/code><\/pre>\n<p>  \u6279\u5904\u7406\u4e2d\u7684\u54cd\u5e94 <\/p>\n<p>\u4f7f\u7528\u7ebf\u7a0b\u6216\u5f02\u6b65\uff0c\u4f60\u53ef\u4ee5\u540c\u65f6\u4e3a\u6570\u767e\u4e07\u7528\u6237\u63d0\u4f9b\u670d\u52a1\u3002<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>DSPy \u662f\u6211\u7684\u9996\u9009\u6846\u67b6\uff0c\u56e0\u4e3a\u5b83\u7b80\u5355\u4e14\u8bbe\u8ba1\u5468\u5230\u3002\u6211\u4f7f\u7528\u5b83\u505a\u4e86\u5f88\u591a\u4e8b\u60c5\uff0c\u4ece\u6784\u5efa MVP \u5230\u6269\u5c55\u7cfb\u7edf\u4ee5\u5904\u7406\u6570\u767e\u4e07\u4e2a\u8bf7\u6c42\u3002\u867d\u7136 DSPy \u548c AI \u7f16\u7a0b\u4ecd\u5728\u4e0d\u65ad\u53d1\u5c55\uff0c\u4f46\u627e\u5230\u6e05\u6670\u3001\u53ef\u7528\u4e8e\u751f\u4ea7\u7684\u6307\u5bfc\u53ef\u80fd\u5f88\u56f0\u96be\u3002 \u5728\u8fd9\u7bc7\u535a\u5ba2\u4e2d\uff0c\u6211\u5206\u4eab\u4e86\u6211\u6240\u5b66\u5230\u7684\u4e1c\u897f\u2014\u2014\u4ece\u5b9e\u8df5\u7ecf\u9a8c\u5230\u6587\u6863\u548c GitHub \u8ba8\u8bba\u4e2d\u7684\u89c1\u89e3\u3002\u8fd9\u662f\u4e00\u672c\u5b9e\u7528\u6307\u5357\uff0c\u91cc\u9762\u5145\u6ee1\u4e86\u4f7f\u7528 DSPy \u7684\u53ef\u884c\u6280\u5de7\u3002 1\u3001\u53ef\u9760\u7684\u8f93\u51fa \u5bf9\u4e8e\u4f7f\u7528 LLM \u7684\u5f00\u53d1\u4eba\u5458\u6765\u8bf4\uff0c\u6700\u5927\u7684\u6311\u6218\u662f\u5b9e\u73b0\u7ed3\u6784\u5316\u548c\u4e00\u81f4\u7684\u8f93\u51fa\u3002\u8ba9\u4f60\u7684\u4ee3\u7406\u5de5\u4f5c\u662f\u4e00\u56de\u4e8b\uff0c\u4f46\u786e\u4fdd 95% \u4ee5\u4e0a\u7684\u53ef\u9760\u6027\u662f\u53e6\u4e00\u56de\u4e8b\u3002\u6700\u7ec8\u7528\u6237\u6bcf\u6b21\u90fd\u5e0c\u671b\u83b7\u5f97\u826f\u597d\u7684\u7ed3\u679c \u2014 \u4ed6\u4eec\u4e0d\u5728\u4e4e LLM \u662f\u5426\u5bb9\u6613\u51fa\u73b0\u5e7b\u89c9\u3001\u4e0d\u4e00\u81f4\u6216\u5076\u5c14\u51fa\u73b0\u4e0d\u7a33\u5b9a\u884c\u4e3a\u3002 \u867d\u7136\u6709\u4e9b\u95ee\u9898\uff08\u5982 API \u63d0\u4f9b\u5546\u4e2d\u65ad\uff09\u8d85\u51fa\u4e86\u4f60\u7684\u63a7\u5236\u8303\u56f4\uff0c\u4f46\u4f60\u53ef\u4ee5\u5728\u81ea\u5df1\u8fd9\u8fb9\u89e3\u51b3\u8bb8\u591a\u95ee\u9898\u3002\u4f7f\u7528 DSPy\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u65ad\u8a00\u548c\u5efa\u8bae\u6765\u6307\u5bfc\u4f60\u7684\u7a0b\u5e8f\u83b7\u5f97\u66f4\u597d\u7684\u8f93\u51fa\u5e76\u63d0\u9ad8\u53ef\u9760\u6027\u3002\u8fd9\u4e9b\u5de5\u5177\u8fd8\u6709\u52a9\u4e8e\u6355\u83b7\u4e0d\u826f\u7ed3\u679c\u5e76\u5b9e\u65bd\u81ea\u52a8\u91cd\u8bd5\u673a\u5236\u4ee5\u786e\u4fdd\u9ad8\u8d28\u91cf\u7684\u54cd\u5e94\u3002 \u5982\u4f55\u4f7f\u7528 dspy.Assert \u548c dspy.Suggest \uff1f \u8981\u5728 DSPy \u4e2d\u4f7f\u7528 dspy.Assert \u548c dspy.Suggest\uff0c \u4f60\u9700\u8981\u4f7f\u7528\u5e03\u5c14\u9a8c\u8bc1\u68c0\u67e5\u5728\u7a0b\u5e8f\u4e2d\u5b9a\u4e49\u7ea6\u675f\u4ee5\u83b7\u5f97\u6240\u9700\u7684\u7ed3\u679c\u3002\u8fd9\u4e9b\u7ea6\u675f\u88ab\u5b9e\u73b0\u4e3a\u9a8c\u8bc1\u6a21\u578b\u8f93\u51fa\u7684\u7b80\u5355 Python \u51fd\u6570\u3002 \u4e3b\u8981\u533a\u522b\u5728\u4e8e\u5b83\u4eec\u7684\u4e25\u683c\u6027\uff1a Assert \u5f3a\u5236\u6267\u884c\u7a0b\u5e8f\u5fc5\u987b\u6ee1\u8db3\u7684\u4e25\u683c\u6761\u4ef6\uff1b\u5426\u5219\uff0c\u5b83\u5c06\u5931\u8d25\u3002 Suggest \u63d0\u4f9b\u975e\u5f3a\u5236\u6027\u5efa\u8bae\u4ee5\u63d0\u9ad8\u6027\u80fd\u6216\u8f93\u51fa\u8d28\u91cf\u3002 \u4ee5\u4e0b\u662f\u5982\u4f55\u9a8c\u8bc1\u7b80\u5355 DSPy \u6a21\u5757\u7684\u793a\u4f8b\uff1a from dspy.primitives.assertions import assert_transform_module, backtrack_handler # [&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-53737","post","type-post","status-publish","format-standard","hentry","category-ai"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/53737","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=53737"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/53737\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=53737"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=53737"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=53737"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}