{ "cells": [ { "cell_type": "markdown", "id": "f7a54d8ba1f68c88", "metadata": {}, "source": [ "# Thread of Thought\n", "\n", "[Thread of Thought](https://arxiv.org/pdf/2311.08734) (THoT) is an extension of zero-shot [Chain of Thought](../chain_of_thought) where the request to walk through the reasoning steps is improved. The paper tests the results of various phrases, but finds the best to be \"Walk me through this context in manageable parts step by step, summarizing and analyzing as we go.\" It is applicable to reasoning and mathematical tasks just like CoT, but is most useful for tasks with retrieval / large amounts of context and Q and A on this context.\n", "\n", "
\n" ] }, { "cell_type": "code", "execution_count": 1, "id": "554d38de5d695e27", "metadata": { "ExecuteTime": { "end_time": "2024-10-02T03:32:23.669348Z", "start_time": "2024-10-02T03:32:18.090466Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "To answer the question \"Where was Apple founded?\" let's break down the information available in the retrieved passages step by step.\n", "\n", "### Step 1: Identify Founding Information\n", "\n", "From **retrieved passage 1**, we learn the following:\n", "- Apple Inc. was founded on April 1, 1976.\n", "- The founders are Steve Jobs, Steve Wozniak, and Ronald Wayne.\n", "- The company started in the garage of Jobs' childhood home.\n", "\n", "### Step 2: Analyze the Location\n", "\n", "The precise location mentioned in **retrieved passage 1** is:\n", "- **Los Altos, California.**\n", "This indicates that Apple was founded in a residential setting, specifically in a garage, which is a common story for many tech startups, illustrating humble beginnings.\n", "\n", "### Step 3: Confirming with Additional Context\n", "\n", "While the remaining passages provide various pieces of information about Apple, such as the development of its products and its incorporation, they do not provide an alternative founding location. Therefore, the core location remains unchanged by the additional context.\n", "\n", "### Step 4: Summarizing\n", "\n", "In summary, Apple Inc. was founded in **Los Altos, California**, in the garage of Steve Jobs' childhood home. This information highlights the origins of a now-massive corporation, emphasizing that great companies can start in modest environments.\n", "\n", "Thus, the answer to the question \"Where was Apple founded?\" is **Los Altos, California**.\n" ] } ], "source": [ "from mirascope.core import openai, prompt_template\n", "\n", "rag_output = [\n", " \"\"\"Apple Inc. was founded on April 1, 1976, by Steve Jobs, Steve Wozniak, and\n", "Ronald Wayne. The company started in the garage of Jobs' childhood home in \n", "Los Altos, California.\"\"\",\n", " \"\"\"Steve Jobs was a visionary entrepreneur and the co-founder of Apple Inc.\n", "He played a key role in the development of the Macintosh, iPod, iPhone, and iPad.\"\"\",\n", " \"\"\"Apple's headquarters, known as Apple Park, is located in Cupertino, California.\n", "The campus, designed by Norman Foster, opened to employees in April 2017.\"\"\",\n", " \"\"\"In 1977, Apple Computer, Inc. was incorporated. The Apple II, one of the first\n", "highly successful mass-produced microcomputer products, was introduced that year.\"\"\",\n", " \"\"\"Apple's first product, the Apple I, was sold as a fully assembled circuit board.\n", "The idea for the company came from Steve Wozniak's interest in building a computer\n", "kit.\"\"\",\n", " \"\"\"Steve Wozniak and Steve Jobs were high school friends before they founded Apple\n", "together. They were both members of the Homebrew Computer Club, where they exchanged\n", "ideas with other computer enthusiasts.\"\"\",\n", " \"\"\"The first Apple Store opened in Tysons Corner, Virginia, in May 2001.\n", "Apple Stores have since become iconic retail spaces around the world.\"\"\",\n", " \"\"\"Apple has a strong commitment to environmental sustainability. The company\n", "aims to have its entire supply chain carbon neutral by 2030.\"\"\",\n", " \"\"\"Ronald Wayne, the lesser-known third co-founder of Apple, sold his shares\n", "in the company just 12 days after it was founded. He believed the venture was too\n", "risky and wanted to avoid potential financial loss.\"\"\",\n", " \"\"\"In 1984, Apple launched the Macintosh, the first personal computer to feature\n", "a graphical user interface and a mouse. This product revolutionized the computer\n", "industry and set new standards for user-friendly design.\"\"\",\n", "]\n", "\n", "\n", "def retrieve_passages(query: str):\n", " \"\"\"Simulates RAG retrieval.\"\"\"\n", " return rag_output\n", "\n", "\n", "thot_augment = \"\"\"Walk me through this context in manageable parts step by step,\n", "summarizing and analyzing as we go\"\"\"\n", "\n", "\n", "@openai.call(model=\"gpt-4o-mini\")\n", "@prompt_template(\n", " \"\"\"\n", " As a content reviewer, I provide multiple retrieved passages about\n", " this question; you need to answer the question.\n", "\n", " {context}\n", "\n", " {query} {thot_augment}\n", " \"\"\"\n", ")\n", "def call(query: str, thot_prompt: bool = False) -> openai.OpenAIDynamicConfig:\n", " passages = retrieve_passages(query)\n", " context = [\n", " f\"retrieved passage {i+1} is: {passage}\" for i, passage in enumerate(passages)\n", " ]\n", " return {\n", " \"computed_fields\": {\n", " \"context\": context,\n", " \"thot_augment\": thot_augment if thot_prompt else \"\",\n", " }\n", " }\n", "\n", "\n", "prompt = \"Where was Apple founded?\"\n", "\n", "print(call(query=prompt, thot_prompt=True))" ] }, { "cell_type": "markdown", "id": "4714bbc9777b8560", "metadata": {}, "source": [ "\n", "Effective Thread of Thought Usage
\n", "