{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "04b70841", "metadata": {}, "outputs": [], "source": [ "!pip install -q git+https://github.com/srush/MiniChain\n", "!git clone https://github.com/srush/MiniChain; cp -fr MiniChain/examples/* . " ] }, { "cell_type": "markdown", "id": "f8ea4879", "metadata": {}, "source": [ "Prompt from ...\n" ] }, { "cell_type": "code", "execution_count": null, "id": "0370e1bb", "metadata": {}, "outputs": [], "source": [ "prompt = \"\"\"\n", "Question: Who lived longer, Muhammad Ali or Alan Turing?\n", "Are follow up questions needed here: Yes.\n", "Follow up: How old was Muhammad Ali when he died?\n", "Intermediate answer: Muhammad Ali was 74 years old when he died.\n", "Follow up: How old was Alan Turing when he died?\n", "Intermediate answer: Alan Turing was 41 years old when he died.\n", "So the final answer is: Muhammad Ali\n", "\n", "Question: When was the founder of craigslist born?\n", "Are follow up questions needed here: Yes.\n", "Follow up: Who was the founder of craigslist?\n", "Intermediate answer: Craigslist was founded by Craig Newmark.\n", "Follow up: When was Craig Newmark born?\n", "Intermediate answer: Craig Newmark was born on December 6, 1952.\n", "So the final answer is: December 6, 1952\n", "\n", "Question: Who was the maternal grandfather of George Washington?\n", "Are follow up questions needed here: Yes.\n", "Follow up: Who was the mother of George Washington?\n", "Intermediate answer: The mother of George Washington was Mary Ball Washington.\n", "Follow up: Who was the father of Mary Ball Washington?\n", "Intermediate answer: The father of Mary Ball Washington was Joseph Ball.\n", "So the final answer is: Joseph Ball\n", "\n", "Question: Are both the directors of Jaws and Casino Royale from the same country?\n", "Are follow up questions needed here: Yes.\n", "Follow up: Who is the director of Jaws?\n", "Intermediate answer: The director of Jaws is Steven Spielberg.\n", "Follow up: Where is Steven Spielberg from?\n", "Intermediate answer: The United States.\n", "Follow up: Who is the director of Casino Royale?\n", "Intermediate answer: The director of Casino Royale is Martin Campbell.\n", "Follow up: Where is Martin Campbell from?\n", "Intermediate answer: New Zealand.\n", "So the final answer is: No\n", "\n", "Question: {{input}}\n", "Are followup questions needed here: {% if agent_scratchpad %}Yes{%else%}No{% endif %}.\n", "\"\"\"" ] }, { "cell_type": "code", "execution_count": null, "id": "82a93b59", "metadata": { "lines_to_next_cell": 1 }, "outputs": [], "source": [ "import jinja2" ] }, { "cell_type": "code", "execution_count": null, "id": "4e5105b2", "metadata": {}, "outputs": [], "source": [ "class SelfAsk:\n", " def render(self, input: str, agent_scratchpad: bool):\n", " return jinja.render(prompt, dict(input=input,\n", " agent_scatchpad=agent_scratchpad))\n", "\n", " def parse(self, response: str):\n", " pass\n", "\n", "\n", " def stop(self):\n", " return []" ] } ], "metadata": { "jupytext": { "cell_metadata_filter": "-all", "main_language": "python", "notebook_metadata_filter": "-all" } }, "nbformat": 4, "nbformat_minor": 5 }