mirror of
https://github.com/hwchase17/langchain
synced 2024-11-04 06:00:26 +00:00
424 lines
32 KiB
Plaintext
424 lines
32 KiB
Plaintext
|
{
|
|||
|
"cells": [
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"id": "a38e5d2d-7587-4192-90f2-b58e6c62f08c",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"# Self Discover\n",
|
|||
|
"\n",
|
|||
|
"An implementation of the [Self-Discover paper](https://arxiv.org/pdf/2402.03620.pdf).\n",
|
|||
|
"\n",
|
|||
|
"Based on [this implementation from @catid](https://github.com/catid/self-discover/tree/main?tab=readme-ov-file)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 1,
|
|||
|
"id": "a18d8f24-5d9a-45c5-9739-6f3c4ed6c9c9",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"from langchain_openai import ChatOpenAI"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 2,
|
|||
|
"id": "9f554045-6e79-42d3-be4b-835bbbd0b78c",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"model = ChatOpenAI(temperature=0, model=\"gpt-4-turbo-preview\")"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 3,
|
|||
|
"id": "9e9925aa-638a-4862-823e-9803402b8f82",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"from langchain import hub\n",
|
|||
|
"from langchain_core.prompts import PromptTemplate"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 4,
|
|||
|
"id": "c4cc5c8c-f6a5-42c7-9ed5-780d79b3b29a",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"select_prompt = hub.pull(\"hwchase17/self-discovery-select\")"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 5,
|
|||
|
"id": "a5b53d29-f5b6-4f39-af97-bb6b133e1d18",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"name": "stdout",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"Select several reasoning modules that are crucial to utilize in order to solve the given task:\n",
|
|||
|
"\n",
|
|||
|
"All reasoning module descriptions:\n",
|
|||
|
"\u001b[33;1m\u001b[1;3m{reasoning_modules}\u001b[0m\n",
|
|||
|
"\n",
|
|||
|
"Task: \u001b[33;1m\u001b[1;3m{task_description}\u001b[0m\n",
|
|||
|
"\n",
|
|||
|
"Select several modules are crucial for solving the task above:\n",
|
|||
|
"\n"
|
|||
|
]
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"select_prompt.pretty_print()"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 6,
|
|||
|
"id": "26eaa6bc-5202-4b22-9522-33f227c8eb55",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"adapt_prompt = hub.pull(\"hwchase17/self-discovery-adapt\")"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 7,
|
|||
|
"id": "dc30afb9-180d-417b-9935-f7ef166710b8",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"name": "stdout",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"Rephrase and specify each reasoning module so that it better helps solving the task:\n",
|
|||
|
"\n",
|
|||
|
"SELECTED module descriptions:\n",
|
|||
|
"\u001b[33;1m\u001b[1;3m{selected_modules}\u001b[0m\n",
|
|||
|
"\n",
|
|||
|
"Task: \u001b[33;1m\u001b[1;3m{task_description}\u001b[0m\n",
|
|||
|
"\n",
|
|||
|
"Adapt each reasoning module description to better solve the task:\n",
|
|||
|
"\n"
|
|||
|
]
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"adapt_prompt.pretty_print()"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 8,
|
|||
|
"id": "a93253a9-8f50-49dd-8815-c3927bae1905",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"structured_prompt = hub.pull(\"hwchase17/self-discovery-structure\")"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 9,
|
|||
|
"id": "8ea8dd78-4285-400b-83d2-c4a241903a79",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"name": "stdout",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"Operationalize the reasoning modules into a step-by-step reasoning plan in JSON format:\n",
|
|||
|
"\n",
|
|||
|
"Here's an example:\n",
|
|||
|
"\n",
|
|||
|
"Example task:\n",
|
|||
|
"\n",
|
|||
|
"If you follow these instructions, do you return to the starting point? Always face forward. Take 1 step backward. Take 9 steps left. Take 2 steps backward. Take 6 steps forward. Take 4 steps forward. Take 4 steps backward. Take 3 steps right.\n",
|
|||
|
"\n",
|
|||
|
"Example reasoning structure:\n",
|
|||
|
"\n",
|
|||
|
"{\n",
|
|||
|
" \"Position after instruction 1\":\n",
|
|||
|
" \"Position after instruction 2\":\n",
|
|||
|
" \"Position after instruction n\":\n",
|
|||
|
" \"Is final position the same as starting position\":\n",
|
|||
|
"}\n",
|
|||
|
"\n",
|
|||
|
"Adapted module description:\n",
|
|||
|
"\u001b[33;1m\u001b[1;3m{adapted_modules}\u001b[0m\n",
|
|||
|
"\n",
|
|||
|
"Task: \u001b[33;1m\u001b[1;3m{task_description}\u001b[0m\n",
|
|||
|
"\n",
|
|||
|
"Implement a reasoning structure for solvers to follow step-by-step and arrive at correct answer.\n",
|
|||
|
"\n",
|
|||
|
"Note: do NOT actually arrive at a conclusion in this pass. Your job is to generate a PLAN so that in the future you can fill it out and arrive at the correct conclusion for tasks like this\n"
|
|||
|
]
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"structured_prompt.pretty_print()"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 10,
|
|||
|
"id": "f3d4d79d-f414-4588-b476-4a35b3ba6fbf",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"reasoning_prompt = hub.pull(\"hwchase17/self-discovery-reasoning\")"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 11,
|
|||
|
"id": "23d1e32e-d12e-454a-8484-c08e250e3262",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"name": "stdout",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"Follow the step-by-step reasoning plan in JSON to correctly solve the task. Fill in the values following the keys by reasoning specifically about the task given. Do not simply rephrase the keys.\n",
|
|||
|
" \n",
|
|||
|
"Reasoning Structure:\n",
|
|||
|
"\u001b[33;1m\u001b[1;3m{reasoning_structure}\u001b[0m\n",
|
|||
|
"\n",
|
|||
|
"Task: \u001b[33;1m\u001b[1;3m{task_description}\u001b[0m\n"
|
|||
|
]
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"reasoning_prompt.pretty_print()"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 12,
|
|||
|
"id": "7b9af01d-da28-4785-b069-efea61905cfa",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"PromptTemplate(input_variables=['reasoning_structure', 'task_description'], template='Follow the step-by-step reasoning plan in JSON to correctly solve the task. Fill in the values following the keys by reasoning specifically about the task given. Do not simply rephrase the keys.\\n \\nReasoning Structure:\\n{reasoning_structure}\\n\\nTask: {task_description}')"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 12,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"reasoning_prompt"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 13,
|
|||
|
"id": "399bf160-e257-429f-b27e-66d4063f195f",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"from langchain_core.output_parsers import StrOutputParser\n",
|
|||
|
"from langchain_core.runnables import RunnablePassthrough"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 14,
|
|||
|
"id": "5c3bd203-7dc1-457e-813f-283aaf059ec0",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"select_chain = select_prompt | model | StrOutputParser()"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 15,
|
|||
|
"id": "86420da0-7cc2-4659-853e-9c3ef808e47c",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"adapt_chain = adapt_prompt | model | StrOutputParser()"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 16,
|
|||
|
"id": "270a3905-58a3-4650-96ca-e8254040285f",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"structure_chain = structured_prompt | model | StrOutputParser()"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 17,
|
|||
|
"id": "55b486cc-36be-497e-9eba-9c8dc228f2d1",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"reasoning_chain = reasoning_prompt | model | StrOutputParser()"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 18,
|
|||
|
"id": "92d8d484-055b-48a8-98bc-e7d40c12db2e",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"overall_chain = (\n",
|
|||
|
" RunnablePassthrough.assign(selected_modules=select_chain)\n",
|
|||
|
" .assign(adapted_modules=adapt_chain)\n",
|
|||
|
" .assign(reasoning_structure=structure_chain)\n",
|
|||
|
" .assign(answer=reasoning_chain)\n",
|
|||
|
")"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 19,
|
|||
|
"id": "29fe385b-cf5d-4581-80e7-55462f5628bb",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"reasoning_modules = [\n",
|
|||
|
" \"1. How could I devise an experiment to help solve that problem?\",\n",
|
|||
|
" \"2. Make a list of ideas for solving this problem, and apply them one by one to the problem to see if any progress can be made.\",\n",
|
|||
|
" # \"3. How could I measure progress on this problem?\",\n",
|
|||
|
" \"4. How can I simplify the problem so that it is easier to solve?\",\n",
|
|||
|
" \"5. What are the key assumptions underlying this problem?\",\n",
|
|||
|
" \"6. What are the potential risks and drawbacks of each solution?\",\n",
|
|||
|
" \"7. What are the alternative perspectives or viewpoints on this problem?\",\n",
|
|||
|
" \"8. What are the long-term implications of this problem and its solutions?\",\n",
|
|||
|
" \"9. How can I break down this problem into smaller, more manageable parts?\",\n",
|
|||
|
" \"10. Critical Thinking: This style involves analyzing the problem from different perspectives, questioning assumptions, and evaluating the evidence or information available. It focuses on logical reasoning, evidence-based decision-making, and identifying potential biases or flaws in thinking.\",\n",
|
|||
|
" \"11. Try creative thinking, generate innovative and out-of-the-box ideas to solve the problem. Explore unconventional solutions, thinking beyond traditional boundaries, and encouraging imagination and originality.\",\n",
|
|||
|
" # \"12. Seek input and collaboration from others to solve the problem. Emphasize teamwork, open communication, and leveraging the diverse perspectives and expertise of a group to come up with effective solutions.\",\n",
|
|||
|
" \"13. Use systems thinking: Consider the problem as part of a larger system and understanding the interconnectedness of various elements. Focuses on identifying the underlying causes, feedback loops, and interdependencies that influence the problem, and developing holistic solutions that address the system as a whole.\",\n",
|
|||
|
" \"14. Use Risk Analysis: Evaluate potential risks, uncertainties, and tradeoffs associated with different solutions or approaches to a problem. Emphasize assessing the potential consequences and likelihood of success or failure, and making informed decisions based on a balanced analysis of risks and benefits.\",\n",
|
|||
|
" # \"15. Use Reflective Thinking: Step back from the problem, take the time for introspection and self-reflection. Examine personal biases, assumptions, and mental models that may influence problem-solving, and being open to learning from past experiences to improve future approaches.\",\n",
|
|||
|
" \"16. What is the core issue or problem that needs to be addressed?\",\n",
|
|||
|
" \"17. What are the underlying causes or factors contributing to the problem?\",\n",
|
|||
|
" \"18. Are there any potential solutions or strategies that have been tried before? If yes, what were the outcomes and lessons learned?\",\n",
|
|||
|
" \"19. What are the potential obstacles or challenges that might arise in solving this problem?\",\n",
|
|||
|
" \"20. Are there any relevant data or information that can provide insights into the problem? If yes, what data sources are available, and how can they be analyzed?\",\n",
|
|||
|
" \"21. Are there any stakeholders or individuals who are directly affected by the problem? What are their perspectives and needs?\",\n",
|
|||
|
" \"22. What resources (financial, human, technological, etc.) are needed to tackle the problem effectively?\",\n",
|
|||
|
" \"23. How can progress or success in solving the problem be measured or evaluated?\",\n",
|
|||
|
" \"24. What indicators or metrics can be used?\",\n",
|
|||
|
" \"25. Is the problem a technical or practical one that requires a specific expertise or skill set? Or is it more of a conceptual or theoretical problem?\",\n",
|
|||
|
" \"26. Does the problem involve a physical constraint, such as limited resources, infrastructure, or space?\",\n",
|
|||
|
" \"27. Is the problem related to human behavior, such as a social, cultural, or psychological issue?\",\n",
|
|||
|
" \"28. Does the problem involve decision-making or planning, where choices need to be made under uncertainty or with competing objectives?\",\n",
|
|||
|
" \"29. Is the problem an analytical one that requires data analysis, modeling, or optimization techniques?\",\n",
|
|||
|
" \"30. Is the problem a design challenge that requires creative solutions and innovation?\",\n",
|
|||
|
" \"31. Does the problem require addressing systemic or structural issues rather than just individual instances?\",\n",
|
|||
|
" \"32. Is the problem time-sensitive or urgent, requiring immediate attention and action?\",\n",
|
|||
|
" \"33. What kinds of solution typically are produced for this kind of problem specification?\",\n",
|
|||
|
" \"34. Given the problem specification and the current best solution, have a guess about other possible solutions.\"\n",
|
|||
|
" \"35. Let’s imagine the current best solution is totally wrong, what other ways are there to think about the problem specification?\"\n",
|
|||
|
" \"36. What is the best way to modify this current best solution, given what you know about these kinds of problem specification?\"\n",
|
|||
|
" \"37. Ignoring the current best solution, create an entirely new solution to the problem.\"\n",
|
|||
|
" # \"38. Let’s think step by step.\"\n",
|
|||
|
" \"39. Let’s make a step by step plan and implement it with good notation and explanation.\",\n",
|
|||
|
"]\n",
|
|||
|
"\n",
|
|||
|
"\n",
|
|||
|
"task_example = \"Lisa has 10 apples. She gives 3 apples to her friend and then buys 5 more apples from the store. How many apples does Lisa have now?\"\n",
|
|||
|
"\n",
|
|||
|
"task_example = \"\"\"This SVG path element <path d=\"M 55.57,80.69 L 57.38,65.80 M 57.38,65.80 L 48.90,57.46 M 48.90,57.46 L\n",
|
|||
|
"45.58,47.78 M 45.58,47.78 L 53.25,36.07 L 66.29,48.90 L 78.69,61.09 L 55.57,80.69\"/> draws a:\n",
|
|||
|
"(A) circle (B) heptagon (C) hexagon (D) kite (E) line (F) octagon (G) pentagon(H) rectangle (I) sector (J) triangle\"\"\""
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 20,
|
|||
|
"id": "6cbfbe81-f751-42da-843a-f9003ace663d",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"reasoning_modules_str = \"\\n\".join(reasoning_modules)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 65,
|
|||
|
"id": "d411c7aa-7017-4d67-88b5-43b5d161c34c",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"{'task_description': 'This SVG path element <path d=\"M 55.57,80.69 L 57.38,65.80 M 57.38,65.80 L 48.90,57.46 M 48.90,57.46 L\\n45.58,47.78 M 45.58,47.78 L 53.25,36.07 L 66.29,48.90 L 78.69,61.09 L 55.57,80.69\"/> draws a:\\n(A) circle (B) heptagon (C) hexagon (D) kite (E) line (F) octagon (G) pentagon(H) rectangle (I) sector (J) triangle',\n",
|
|||
|
" 'reasoning_modules': '1. How could I devise an experiment to help solve that problem?\\n2. Make a list of ideas for solving this problem, and apply them one by one to the problem to see if any progress can be made.\\n4. How can I simplify the problem so that it is easier to solve?\\n5. What are the key assumptions underlying this problem?\\n6. What are the potential risks and drawbacks of each solution?\\n7. What are the alternative perspectives or viewpoints on this problem?\\n8. What are the long-term implications of this problem and its solutions?\\n9. How can I break down this problem into smaller, more manageable parts?\\n10. Critical Thinking: This style involves analyzing the problem from different perspectives, questioning assumptions, and evaluating the evidence or information available. It focuses on logical reasoning, evidence-based decision-making, and identifying potential biases or flaws in thinking.\\n11. Try creative thinking, generate innovative and out-of-the-box ideas to solve the problem. Explore unconventional solutions, thinking beyond traditional boundaries, and encouraging imagination and originality.\\n13. Use systems thinking: Consider the problem as part of a larger system and understanding the interconnectedness of various elements. Focuses on identifying the underlying causes, feedback loops, and interdependencies that influence the problem, and developing holistic solutions that address the system as a whole.\\n14. Use Risk Analysis: Evaluate potential risks, uncertainties, and tradeoffs associated with different solutions or approaches to a problem. Emphasize assessing the potential consequences and likelihood of success or failure, and making informed decisions based on a balanced analysis of risks and benefits.\\n16. What is the core issue or problem that needs to be addressed?\\n17. What are the underlying causes or factors contributing to the problem?\\n18. Are there any potential solutions or strategies that have been tried before? If yes, what were the outcomes and lessons learned?\\n19. What are the potential obstacles or challenges that might arise in solving this problem?\\n20. Are there any relevant data or information that can provide insights into the problem? If yes, what data sources are available, and how can they be analyzed?\\n21. Are there any stakeholders or individuals who are directly affected by the problem? What are their perspectives and needs?\\n22. What resources (financial, human, technological, etc.) are needed to tackle the problem effectively?\\n23. How can progress or success in solving the problem be measured or evaluated?\\n24. What indicators or metrics can be used?\\n25. Is the problem a technical or practical one that requires a specific expertise or skill set? Or is it more of a conceptual or theoretical problem?\\n26. Does the problem involve a physical constraint, such as limited resources, infrastructure, or space?\\n27. Is the problem related to human behavior, such as a social, cultural, or psychological issue?\\n28. Does the problem involve decision-making or planning, where choices need to be made under uncertainty or with competing objectives?\\n29. Is the problem an analytical one that requires data analysis, modeling, or optimization techniques?\\n30. Is the problem a design challenge that requires creative solutions and innovation?\\n31. Does the problem require addressing systemic or structural issues rather than just individual instances?\\n32. Is the problem time-sensitive or urgent, requiring immediate attention and action?\\n33. What kinds of solution typically are produced for this kind of problem specification?\\n34. Given the problem specification and the current best solution, have a guess about other possible solutions.35. Let’s imagine the current best solution is totally wrong, what other ways are there to think about the problem specification?36. What is the best way to modify this current best solution, given what you know about these kinds of problem specification?37. Ignoring the current best solution, create an ent
|
|||
|
" 'selected_modules': 'To solve the task of identifying the shape drawn by the given SVG path element, the following reasoning modules are crucial:\\n\\n1. **Critical Thinking (10)**: This involves analyzing the SVG path commands and coordinates logically to understand the shape they form. It requires questioning assumptions (e.g., not assuming the shape based on a quick glance at the coordinates but rather analyzing the path commands and their implications) and evaluating the information provided by the SVG path data.\\n\\n2. **Analytical Problem Solving (29)**: The task requires data analysis skills to interpret the SVG path commands and coordinates. Understanding how the \"M\" (moveto) and \"L\" (lineto) commands work to draw lines between specified points is essential for determining the shape.\\n\\n3. **Creative Thinking (11)**: While the task primarily involves analytical skills, creative thinking can help in visualizing the shape that the path commands are likely to form, especially when the path data doesn\\'t immediately suggest a common shape.\\n\\n4. **Systems Thinking (13)**: Recognizing the SVG path as part of a larger system (in this case, the SVG graphics system) and understanding how individual path commands contribute to the overall shape can be helpful. This involves understanding the interconnectedness of the start and end points of each line segment and how they come together to form a complete shape.\\n\\n5. **Break Down the Problem (9)**: Breaking down the SVG path into its individual commands and analyzing each segment between \"M\" and \"L\" commands can simplify the task. This makes it easier to visualize and understand the shape being drawn step by step.\\n\\n6. **Visualization (not explicitly listed but implied in creative and analytical thinking)**: Visualizing the path that the \"M\" and \"L\" commands create is essential. This isn\\'t a listed module but is a skill that underpins both creative and analytical approaches to solving this problem.\\n\\nGiven the SVG path commands, one would analyze each segment drawn by \"M\" (moveto) and \"L\" (lineto) commands to determine the shape\\'s vertices and sides. This process involves critical thinking to assess the information, analytical skills to interpret the path data, and a degree of creative thinking for visualization. The task does not directly involve assessing risks, long-term implications, or stakeholder perspectives, so modules focused on those aspects (e.g., Risk Analysis (14), Long-term Implications (8)) are less relevant here.',\n",
|
|||
|
" 'adapted_modules': 'To enhance the process of identifying the shape drawn by the given SVG path element, the reasoning modules can be adapted and specified as follows:\\n\\n1. **Detailed Path Analysis (Critical Thinking)**: This module focuses on a meticulous examination of the SVG path commands and coordinates. It involves a deep dive into the syntax and semantics of path commands such as \"M\" (moveto) and \"L\" (lineto), challenging initial perceptions and rigorously interpreting the sequence of commands to deduce the shape accurately. This analysis goes beyond surface-level inspection, requiring a systematic questioning of each command\\'s role in constructing the overall shape.\\n\\n2. **Path Command Interpretation (Analytical Problem Solving)**: Essential for this task is the ability to decode the SVG path\\'s \"M\" and \"L\" commands, translating these instructions into a mental or visual representation of the shape\\'s geometry. This module emphasizes the analytical dissection of the path data, focusing on how each command contributes to the formation of vertices and edges, thereby facilitating the identification of the shape.\\n\\n3. **Shape Visualization (Creative Thinking)**: Leveraging imagination to mentally construct the shape from the path commands is the core of this module. It involves creatively synthesizing the segments drawn by the \"M\" and \"L\" commands into a coherent visual image, even when the path data does not immediately suggest a recognizable shape. This creative process aids in bridging gaps in the analytical interpretation, offering alternative perspectives on the possible shape outcomes.\\n\\n4. **Path-to-Shape Synthesis (Systems Thinking)**: This module entails understanding the SVG path as a component within the broader context of vector graphics, focusing on how individual path commands interlink to form a cohesive shape. It requires an appreciation of the cumulative effect of each command in relation to the others, recognizing the systemic relationship between the starting and ending points of segments and their collective role in shaping the final figure.\\n\\n5. **Sequential Command Analysis (Break Down the Problem)**: By segmenting the SVG path into discrete commands, this approach simplifies the complexity of the task. It advocates for a step-by-step examination of the path, where each \"M\" to \"L\" sequence is analyzed in isolation before synthesizing the findings to understand the overall shape. This methodical breakdown facilitates a clearer visualization and comprehension of the shape being drawn.\\n\\n6. **Command-to-Geometry Mapping (Visualization)**: Central to solving this task is the ability to map the abstract \"M\" and \"L\" commands onto a concrete geometric representation. This implicit module underlies both the analytical and creative thinking processes, focusing on converting the path data into a visual form that can be easily understood and manipulated mentally. It is about constructing a mental image of the shape as each command is processed, enabling a dynamic visualization that evolves with each new piece of path data.\\n\\nBy adapting and specifying these reasoning modules, the task of identifying the shape drawn by the SVG path element becomes a structured process that leverages critical analysis, analytical problem-solving, creative visualization, systemic thinking, and methodical breakdown to accurately determine the shape as a (D) kite.',\n",
|
|||
|
" 'reasoning_structure': '```json\\n{\\n \"Step 1: Detailed Path Analysis\": {\\n \"Description\": \"Examine each SVG path command and its coordinates closely. Understand the syntax and semantics of \\'M\\' (moveto) and \\'L\\' (lineto) commands.\",\\n \"Action\": \"List all path commands and their coordinates.\",\\n \"Expected Outcome\": \"A clear understanding of the sequence and direction of each path command.\"\\n },\\n \"Step 2: Path Command Interpretation\": {\\n \"Description\": \"Decode the \\'M\\' and \\'L\\' commands to translate these instructions into a mental or visual representation of the shape\\'s geometry.\",\\n \"Action\": \"Map each \\'M\\' and \\'L\\' command to its corresponding action (move or draw line) in the context of the shape.\",\\n \"Expected Outcome\": \"A segmented representation of the shape, highlighting vertices and edges.\"\\n },\\n \"Step 3: Shape Visualization\": {\\n \"Description\": \"Use imagination to mentally construct the shape from the path commands, synthesizing the segments into a coherent visual image.\",\\n \"Action\": \"Visualize the shape based on the segmented representation from Step 2.\",\\n \"Expected Outcome\": \"A mental image of the potential shape, considering the sequence and direction of path commands.\"\\n },\\n \"Step 4: Path-to-Shape Synthesis\": {\\n \"Description\": \"Understand the SVG path as a component within the broader context of vector graphics, focusing on how individual path commands interlink to form a cohesive shape.\",\\n \"Action\": \"Analyze the systemic relationship between the starting and ending points of segments and their collective role in shaping the final figure.\",\\n \"Expected Outcome\": \"Identification of the overall shape by recognizing the cumulative effect of each command.\"\\n },\\n \"Step 5: Sequential Command Analysis\": {\\n \"Description\": \"Segment the SVG path into discrete commands for a step-by-step examination, analyzing each \\'M\\' to \\'L\\' sequence in isolation.\",\\n \"Action\": \"Break down the path into individual commands and analyze each separately before synthesizing the findings.\",\\n \"Expected Outcome\": \"A clearer visualization and comprehension of the shape being drawn, segment by segment.\"\\n },\\n \"Step 6: Command-to-Geometry Mapping\": {\\n \"Description\": \"Map the abstract \\'M\\' and \\'L\\' commands onto a concrete geometric representation, constructing a mental image of the shape as each command is processed.\",\\n \"Action\": \"Convert the path data into a visual form that can be easily understood and manipulated mentally.\",\\n \"Expected Outcome\": \"A dynamic visualization of the shape that evolves with each new piece of path data, leading to the identification of the shape as a kite.\"\\n },\\n \"Conclusion\": {\\n \"Description\": \"Based on the analysis and visualization steps, determine the shape drawn by the SVG path element.\",\\n \"Action\": \"Review the outcomes of each step and synthesize the information to identify the shape.\",\\n \"Expected Outcome\": \"The correct identification of the shape, supported by the structured analysis and reasoning process.\"\\n }\\n}\\n```',\n",
|
|||
|
" 'answer': 'Based on the provided reasoning structure and the SVG path element given, let\\'s analyze the path commands to identify the shape.\\n\\n**Step 1: Detailed Path Analysis**\\n- Description: The SVG path provided contains multiple \\'M\\' (moveto) and \\'L\\' (lineto) commands. Each command specifies a point in a 2D coordinate system.\\n- Action: The path commands are as follows:\\n 1. M 55.57,80.69 (Move to point)\\n 2. L 57.38,65.80 (Line to point)\\n 3. M 57.38,65.80 (Move to point)\\n 4. L 48.90,57.46 (Line to point)\\n 5. M 48.90,57.46 (Move to point)\\n 6. L 45.58,47.78 (Line to point)\\n 7. M 45.58,47.78 (Move to point)\\n 8. L 53.25,36.07 (Line to point)\\n 9. L 66.29,48.90 (Line to point)\\n 10. L 78.69,61.09 (Line to point)\\n 11. L 55.57,80.69 (Line to point)\\n- Expected Outcome: Understanding that the path commands describe a series of movements and lines that form a closed shape.\\n\\n**Step 2: Path Command Interpretation**\\n- Description: The \\'M\\' and \\'L\\' commands are used to move the \"pen\" to a starting point and draw lines to subsequent points, respectively.\\n- Action: The commands describe a shape starting at (55.57,80.69), drawing lines through several points, and finally closing the shape by returning to the starting point.\\n- Expected Outcome: A segmented representation showing a shape with distinct vertices at the specified coordinates.\\n\\n**Step 3: Shape Visualization**\\n- Description: Mentally constructing the shape from the provided path commands.\\n- Action: Visualizing the lines connecting in sequence from the starting point, through each point described by the \\'L\\' commands, and back to the starting point.\\n- Expected Outcome: A mental image of a shape that appears to have four distinct sides, suggesting it could be a quadrilateral.\\n\\n**Step 4: Path-to-Shape Synthesis**\\n- Description: Understanding how the path commands collectively form a specific shape.\\n- Action: Recognizing that the shape starts and ends at the same point, with lines drawn between intermediate points without overlapping, except at the starting/ending point.\\n- Expected Outcome: Identification of a closed, four-sided figure, which suggests it could be a kite based on the symmetry and structure of the lines.\\n\\n**Step 5: Sequential Command Analysis**\\n- Description: Analyzing each \\'M\\' to \\'L\\' sequence in isolation.\\n- Action: Observing that the path does not describe a regular polygon (like a hexagon or octagon) or a circle, but rather a shape with distinct angles and sides.\\n- Expected Outcome: A clearer understanding that the shape has four sides, with two pairs of adjacent sides being potentially unequal, which is characteristic of a kite.\\n\\n**Step 6: Command-to-Geometry Mapping**\\n- Description: Converting the abstract path commands into a geometric shape.\\n- Action: Mapping the path data to visualize a shape with two pairs of adjacent sides that are distinct yet symmetrical, indicative of a kite.\\n- Expected Outcome: A dynamic visualization that evolves to clearly represent a kite shape.\\n\\n**Conclusion**\\n- Description: Determining the shape drawn by the SVG path element.\\n- Action: Reviewing the outcomes of each analysis step, which consistently point towards a four-sided figure with distinct properties of a kite.\\n- Expected Outcome: The correct identification of the shape as a kite (D).'}"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 65,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"overall_chain.invoke(\n",
|
|||
|
" {\"task_description\": task_example, \"reasoning_modules\": reasoning_modules_str}\n",
|
|||
|
")"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": null,
|
|||
|
"id": "ea8568d5-bdb6-45cd-8d04-1ab305786caa",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": []
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": null,
|
|||
|
"id": "c14a291c-7c1b-43bc-807e-11180290985e",
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": []
|
|||
|
}
|
|||
|
],
|
|||
|
"metadata": {
|
|||
|
"kernelspec": {
|
|||
|
"display_name": "Python 3 (ipykernel)",
|
|||
|
"language": "python",
|
|||
|
"name": "python3"
|
|||
|
},
|
|||
|
"language_info": {
|
|||
|
"codemirror_mode": {
|
|||
|
"name": "ipython",
|
|||
|
"version": 3
|
|||
|
},
|
|||
|
"file_extension": ".py",
|
|||
|
"mimetype": "text/x-python",
|
|||
|
"name": "python",
|
|||
|
"nbconvert_exporter": "python",
|
|||
|
"pygments_lexer": "ipython3",
|
|||
|
"version": "3.10.1"
|
|||
|
}
|
|||
|
},
|
|||
|
"nbformat": 4,
|
|||
|
"nbformat_minor": 5
|
|||
|
}
|