srush HF staff commited on
Commit
4e3dc76
1 Parent(s): 9e0c59f

Upload with huggingface_hub

Browse files
Files changed (35) hide show
  1. #selfask.py# +51 -70
  2. app.py~ +21 -0
  3. base.sh +1 -1
  4. base.sh~ +2 -1
  5. bash.ipynb +92 -307
  6. bash.py +19 -55
  7. chat.pmpt.tpl +2 -0
  8. chat.py +17 -36
  9. gatsby.ipynb +0 -0
  10. gatsby.pmpt.tpl +1 -1
  11. gatsby.py +21 -27
  12. math_demo.py +22 -20
  13. math_demo.py~ +43 -0
  14. mycache. +0 -0
  15. ner.ipynb +89 -121
  16. ner.py +20 -31
  17. pal.ipynb +108 -428
  18. pal.py +18 -42
  19. qa.ipynb +0 -0
  20. qa.log +8 -10
  21. qa.pmpt.tpl +1 -1
  22. qa.py +21 -21
  23. selfask.ipynb +118 -742
  24. selfask.pmpt.tpl +3 -3
  25. selfask.py +51 -70
  26. stats.ipynb +108 -193
  27. stats.py +12 -18
  28. temp +0 -0
  29. temp.log +0 -0
  30. test +0 -0
  31. test.log +14 -0
  32. test.pmpt.tpl +1 -0
  33. test.py +22 -0
  34. test.py~ +8 -0
  35. test2.ipynb +91 -0
#selfask.py# CHANGED
@@ -1,83 +1,64 @@
1
- # Notebook implementation of the self-ask + Google tool use prompt.
2
- # Adapted from https://github.com/ofirpress/self-ask
3
 
4
- from dataclasses import dataclass
 
5
 
6
- from parsita import *
7
 
8
- import minichain
 
9
 
10
- # Define the state of the bot.
11
 
12
- @dataclass
13
- class IntermediateState:
14
- s: str
15
 
16
- @dataclass
17
- class FinalState:
18
- s: str
19
 
20
  @dataclass
21
- class Out:
22
- echo: str
23
- state: FinalState | IntermediateState
24
-
25
-
26
- # Self Ask Prompt
27
-
28
- class SelfAsk(minichain.TemplatePrompt[Out]):
29
- template_file = "selfask.pmpt.tpl"
30
- stop_template = "\nIntermediate answer:"
31
-
32
- # Parsita parser.
33
- class Parser(TextParsers):
34
- follow = (lit("Follow up:") >> reg(r".*")) > IntermediateState
35
- finish = (lit("So the final answer is: ") >> reg(r".*")) > FinalState
36
- response = follow | finish
37
-
38
- def parse(self, response: str, inp) -> Out:
39
- return Out(
40
- self.prompt(inp).prompt + response,
41
- self.Parser.response.parse(response).or_die(),
42
- )
43
-
44
- # Runtime loop
45
-
46
- def selfask(inp: str, openai, google) -> str:
47
- prompt1 = SelfAsk(openai)
48
- prompt2 = minichain.SimplePrompt(google)
49
- suffix = ""
50
  for i in range(3):
51
- out = prompt1(dict(input=inp, suffix=suffix, agent_scratchpad=True))
52
-
53
- if isinstance(out.state, FinalState):
54
- break
55
- suffix += out.echo
56
- out2 = prompt2(out.state.s)
57
- suffix += "\nIntermediate answer: " + out2 + "\n"
58
- return out.state.s
59
-
60
-
61
- with minichain.start_chain("selfask") as backend:
62
- result = selfask(
63
- "What is the zip code of the city where George Washington was born?",
64
- backend.OpenAI(),
65
- backend.Google(),
66
- )
67
- print(result)
68
 
69
- # View prompt examples.
70
 
71
- # + tags=["hide_inp"]
72
- SelfAsk().show(
73
- {
74
- "input": "What is the zip code of the city where George Washington was born?",
75
- "agent_scratchpad": True,
76
- },
77
- "Follow up: Where was George Washington born?",
78
- )
79
- # -
80
 
81
- # View log.
82
 
83
- minichain.show_log("selfask.log")
 
 
 
1
 
2
+ desc = """
3
+ ### Self-Ask
4
 
5
+ Notebook implementation of the self-ask + Google tool use prompt.
6
 
7
+ (Adapted from [Self-Ask repo](https://github.com/ofirpress/self-ask))
8
+ """
9
 
10
+ # $
11
 
12
+ from dataclasses import dataclass, replace
13
+ from typing import Optional
14
+ from minichain import prompt, show, OpenAI, Google
15
 
 
 
 
16
 
17
  @dataclass
18
+ class State:
19
+ question: str
20
+ history: str = ""
21
+ next_query: Optional[str] = None
22
+ final_answer: Optional[str] = None
23
+
24
+
25
+ @prompt(OpenAI(),
26
+ template_file = "selfask.pmpt.tpl",
27
+ stop_template = "\nIntermediate answer:")
28
+ def self_ask(model, state):
29
+ out = model(state)
30
+ res = out.split(":", 1)[1]
31
+ if out.startswith("Follow up:"):
32
+ return replace(state, next_query=res)
33
+ elif out.startswith("So the final answer is:"):
34
+ return replace(state, final_answer=res)
35
+
36
+ @prompt(Google())
37
+ def google(model, state):
38
+ if state.next_query is None:
39
+ return state
40
+
41
+ result = model(state.next_query)
42
+ return State(state.question,
43
+ state.history + "\nIntermediate answer: " + result + "\n")
44
+
45
+ def selfask(question):
46
+ state = State(question)
47
  for i in range(3):
48
+ state = self_ask(state)
49
+ state = google(state)
50
+ return state
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
 
52
+ # $
53
 
54
+ gradio = show(selfask,
55
+ examples=["What is the zip code of the city where George Washington was born?"],
56
+ subprompts=[self_ask, google] * 3,
57
+ description=desc,
58
+ code=open("selfask.py", "r").read().split("$")[1].strip().strip("#").strip(),
59
+ out_type="json"
60
+ )
61
+ if __name__ == "__main__":
62
+ gradio.launch()
63
 
 
64
 
 
app.py~ ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from chat import gradio as chat
3
+ from ner import gradio as ner
4
+ from math_demo import gradio as math_demo
5
+ from bash import gradio as bash
6
+ from pal import gradio as pal
7
+ from gatsby import gradio as gatsby
8
+ from qa import gradio as qa
9
+ from stats import gradio as stats
10
+
11
+ css = "#clean div.form {border: 0px} #response {border: 0px; background: #ffeec6} #prompt {border: 0px;background: aliceblue} #json {border: 0px} #result {border: 0px; background: #c5e0e5} #inner {padding: 20px} #inner textarea {border: 0px} .tabs div.tabitem {border: 0px}"
12
+
13
+ with gr.Blocks(css=css) as demo:
14
+ gr.HTML("<center> <img width='10%' style='display:inline; padding: 5px' src='https://user-images.githubusercontent.com/35882/218286642-67985b6f-d483-49be-825b-f62b72c469cd.png'> <h1 style='display:inline'> Mini-Chain </h1> <img width='10%' style='display:inline;padding: 5px' src='https://avatars.githubusercontent.com/u/25720743?s=200&v=4'> </center><br><center><a href='https://github.com/srush/minichain'>[code]</a> <a href='https://user-images.githubusercontent.com/35882/218286642-67985b6f-d483-49be-825b-f62b72c469cd.png'>[docs]</a></center>")
15
+
16
+ gr.TabbedInterface([math_demo, qa, chat, gatsby, ner, bash, pal, stats],
17
+ ["Math", "QA", "Chat", "Book", "NER", "Bash", "PAL", "Stats"],
18
+ css = css)
19
+
20
+ demo.launch()
21
+
base.sh CHANGED
@@ -1,2 +1,2 @@
1
- export OPENAI_KEY="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"
2
  export SERP_KEY="593a073fa4c730efe918e592a538b36e80841bc8f8dd4070c1566920f75ba140"
 
1
+ export OPENAI_API_KEY="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"
2
  export SERP_KEY="593a073fa4c730efe918e592a538b36e80841bc8f8dd4070c1566920f75ba140"
base.sh~ CHANGED
@@ -1 +1,2 @@
1
- export OPENAI_KEY="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"
 
 
1
+ export OPENAI_KEY="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"
2
+ export SERP_KEY="593a073fa4c730efe918e592a538b36e80841bc8f8dd4070c1566920f75ba140"
bash.ipynb CHANGED
@@ -1,387 +1,172 @@
1
  {
2
  "cells": [
3
- {
4
- "cell_type": "markdown",
5
- "id": "27962df3",
6
- "metadata": {},
7
- "source": [
8
- "Notebook to generate and run a bash command.\n",
9
- "Adapted from LangChain\n",
10
- "[BashChain](https://langchain.readthedocs.io/en/latest/modules/chains/examples/llm_bash.html)"
11
- ]
12
- },
13
  {
14
  "cell_type": "code",
15
  "execution_count": 1,
16
- "id": "e01d45bc",
17
  "metadata": {
18
  "execution": {
19
- "iopub.execute_input": "2023-02-27T14:12:17.548344Z",
20
- "iopub.status.busy": "2023-02-27T14:12:17.547695Z",
21
- "iopub.status.idle": "2023-02-27T14:12:17.767947Z",
22
- "shell.execute_reply": "2023-02-27T14:12:17.767208Z"
23
- }
 
 
 
24
  },
25
  "outputs": [],
26
  "source": [
27
- "import minichain"
 
 
 
 
 
 
 
28
  ]
29
  },
30
  {
31
  "cell_type": "markdown",
32
- "id": "b2caf597",
33
- "metadata": {
34
- "lines_to_next_cell": 2
35
- },
36
  "source": [
37
- "Prompt that asks LLM to produce a bash command."
38
  ]
39
  },
40
  {
41
  "cell_type": "code",
42
  "execution_count": 2,
43
- "id": "8669ca4e",
44
  "metadata": {
45
  "execution": {
46
- "iopub.execute_input": "2023-02-27T14:12:17.773257Z",
47
- "iopub.status.busy": "2023-02-27T14:12:17.771880Z",
48
- "iopub.status.idle": "2023-02-27T14:12:17.778057Z",
49
- "shell.execute_reply": "2023-02-27T14:12:17.777432Z"
50
- },
51
- "lines_to_next_cell": 2
52
  },
53
  "outputs": [],
54
  "source": [
55
- "class CLIPrompt(minichain.TemplatePrompt):\n",
56
- " template_file = \"bash.pmpt.tpl\"\n",
57
- "\n",
58
- " def parse(self, out: str, inp):\n",
59
- " out = out.strip()\n",
60
- " assert out.startswith(\"```bash\")\n",
61
- " return out.split(\"\\n\")[1:-1]"
62
  ]
63
  },
64
  {
65
- "cell_type": "markdown",
66
- "id": "79cc544e",
 
67
  "metadata": {
68
- "lines_to_next_cell": 2
 
 
 
 
 
 
69
  },
 
70
  "source": [
71
- "Prompt that runs the bash command."
 
 
 
72
  ]
73
  },
74
  {
75
  "cell_type": "code",
76
- "execution_count": 3,
77
- "id": "db1e09b6",
78
  "metadata": {
79
  "execution": {
80
- "iopub.execute_input": "2023-02-27T14:12:17.782732Z",
81
- "iopub.status.busy": "2023-02-27T14:12:17.781591Z",
82
- "iopub.status.idle": "2023-02-27T14:12:17.787303Z",
83
- "shell.execute_reply": "2023-02-27T14:12:17.786651Z"
84
- }
 
85
  },
86
  "outputs": [],
87
  "source": [
88
- "class BashPrompt(minichain.Prompt):\n",
89
- " def prompt(self, inp) -> str:\n",
90
- " return \";\".join(inp).replace(\"\\n\", \"\")\n",
91
- "\n",
92
- " def parse(self, out: str, inp) -> str:\n",
93
- " return out"
94
- ]
95
- },
96
- {
97
- "cell_type": "markdown",
98
- "id": "5b993ae8",
99
- "metadata": {},
100
- "source": [
101
- "Generate and run bash command."
102
  ]
103
  },
104
  {
105
  "cell_type": "code",
106
- "execution_count": 4,
107
- "id": "17572fff",
108
  "metadata": {
109
  "execution": {
110
- "iopub.execute_input": "2023-02-27T14:12:17.792430Z",
111
- "iopub.status.busy": "2023-02-27T14:12:17.791251Z",
112
- "iopub.status.idle": "2023-02-27T14:12:19.652953Z",
113
- "shell.execute_reply": "2023-02-27T14:12:19.650586Z"
114
  }
115
  },
116
- "outputs": [
117
- {
118
- "name": "stdout",
119
- "output_type": "stream",
120
- "text": [
121
- "#backend.py#\n",
122
- "backend.py\n",
123
- "base.py\n",
124
- "__init__.py\n",
125
- "lang.py\n",
126
- "prompts.py\n",
127
- "__pycache__\n",
128
- "templates\n",
129
- "\n"
130
- ]
131
- }
132
- ],
133
  "source": [
134
- "with minichain.start_chain(\"bash\") as backend:\n",
135
- " question = (\n",
136
- " '\"go up one directory, and then into the minichain directory,'\n",
137
- " 'and list the files in the directory\"'\n",
138
- " )\n",
139
- " prompt = CLIPrompt(backend.OpenAI()).chain(BashPrompt(backend.BashProcess()))\n",
140
- " result = prompt({\"question\": question})\n",
141
- " print(result)"
142
  ]
143
  },
144
  {
145
  "cell_type": "markdown",
146
- "id": "aadedf29",
147
  "metadata": {},
148
  "source": [
149
- "View the prompts."
150
  ]
151
  },
152
  {
153
  "cell_type": "code",
154
- "execution_count": 5,
155
- "id": "0e1c2f1a",
156
  "metadata": {
157
  "execution": {
158
- "iopub.execute_input": "2023-02-27T14:12:19.662941Z",
159
- "iopub.status.busy": "2023-02-27T14:12:19.661254Z",
160
- "iopub.status.idle": "2023-02-27T14:12:19.738758Z",
161
- "shell.execute_reply": "2023-02-27T14:12:19.738197Z"
162
  },
163
- "lines_to_next_cell": 2,
164
- "tags": [
165
- "hide_inp"
166
- ]
167
  },
168
  "outputs": [
169
  {
170
- "data": {
171
- "text/html": [
172
- "\n",
173
- "<!-- <link rel=\"stylesheet\" href=\"https://cdn.rawgit.com/Chalarangelo/mini.css/v3.0.1/dist/mini-default.min.css\"> -->\n",
174
- " <main class=\"container\">\n",
175
- "\n",
176
- "<h3>CLIPrompt</h3>\n",
177
- "\n",
178
- "<dl>\n",
179
- " <dt>Input:</dt>\n",
180
- " <dd>\n",
181
- "<div class=\"highlight\"><pre><span></span><span class=\"p\">{</span><span class=\"s1\">&#39;question&#39;</span><span class=\"p\">:</span> <span class=\"s1\">&#39;list the files in the directory&#39;</span><span class=\"p\">}</span>\n",
182
- "</pre></div>\n",
183
- "\n",
184
- "\n",
185
- " </dd>\n",
186
- "\n",
187
- " <dt> Full Prompt: </dt>\n",
188
- " <dd>\n",
189
- " <details>\n",
190
- " <summary>Prompt</summary>\n",
191
- " <p>If someone asks you to perform a task, your job is to come up with a series of bash commands that will perform the task. There is no need to put \"#!/bin/bash\" in your answer. Make sure to reason step by step, using this format:<br><br>Question: \"copy the files in the directory named 'target' into a new directory at the same level as target called 'myNewDirectory'\"<br><br>I need to take the following actions:<br>- List all files in the directory<br>- Create a new directory<br>- Copy the files from the first directory into the second directory<br>```bash<br>ls<br>mkdir myNewDirectory<br>cp -r target/* myNewDirectory<br>```<br><br>That is the format. Begin!<br><br>Question: <div style='color:red'>list the files in the directory</div></p>\n",
192
- " </details>\n",
193
- " </dd>\n",
194
- "\n",
195
- " <dt> Response: </dt>\n",
196
- " <dd>\n",
197
- " ```bash<br>ls<br>```\n",
198
- " </dd>\n",
199
- "\n",
200
- " <dt>Value:</dt>\n",
201
- " <dd>\n",
202
- "<div class=\"highlight\"><pre><span></span><span class=\"p\">[</span><span class=\"s1\">&#39;ls&#39;</span><span class=\"p\">]</span>\n",
203
- "</pre></div>\n",
204
- "\n",
205
- " </dd>\n",
206
- "</main>\n"
207
- ],
208
- "text/plain": [
209
- "HTML(html='\\n<!-- <link rel=\"stylesheet\" href=\"https://cdn.rawgit.com/Chalarangelo/mini.css/v3.0.1/dist/mini-default.min.css\"> -->\\n <main class=\"container\">\\n\\n<h3>CLIPrompt</h3>\\n\\n<dl>\\n <dt>Input:</dt>\\n <dd>\\n<div class=\"highlight\"><pre><span></span><span class=\"p\">{</span><span class=\"s1\">&#39;question&#39;</span><span class=\"p\">:</span> <span class=\"s1\">&#39;list the files in the directory&#39;</span><span class=\"p\">}</span>\\n</pre></div>\\n\\n\\n </dd>\\n\\n <dt> Full Prompt: </dt>\\n <dd>\\n <details>\\n <summary>Prompt</summary>\\n <p>If someone asks you to perform a task, your job is to come up with a series of bash commands that will perform the task. There is no need to put \"#!/bin/bash\" in your answer. Make sure to reason step by step, using this format:<br><br>Question: \"copy the files in the directory named \\'target\\' into a new directory at the same level as target called \\'myNewDirectory\\'\"<br><br>I need to take the following actions:<br>- List all files in the directory<br>- Create a new directory<br>- Copy the files from the first directory into the second directory<br>```bash<br>ls<br>mkdir myNewDirectory<br>cp -r target/* myNewDirectory<br>```<br><br>That is the format. Begin!<br><br>Question: <div style=\\'color:red\\'>list the files in the directory</div></p>\\n </details>\\n </dd>\\n\\n <dt> Response: </dt>\\n <dd>\\n ```bash<br>ls<br>```\\n </dd>\\n\\n <dt>Value:</dt>\\n <dd>\\n<div class=\"highlight\"><pre><span></span><span class=\"p\">[</span><span class=\"s1\">&#39;ls&#39;</span><span class=\"p\">]</span>\\n</pre></div>\\n\\n </dd>\\n</main>\\n')"
210
- ]
211
- },
212
- "execution_count": 5,
213
- "metadata": {},
214
- "output_type": "execute_result"
215
- }
216
- ],
217
- "source": [
218
- "CLIPrompt().show(\n",
219
- " {\"question\": \"list the files in the directory\"}, \"\"\"```bash\\nls\\n```\"\"\"\n",
220
- ")"
221
- ]
222
- },
223
- {
224
- "cell_type": "code",
225
- "execution_count": 6,
226
- "id": "79cf9c84",
227
- "metadata": {
228
- "execution": {
229
- "iopub.execute_input": "2023-02-27T14:12:19.740976Z",
230
- "iopub.status.busy": "2023-02-27T14:12:19.740788Z",
231
- "iopub.status.idle": "2023-02-27T14:12:19.745592Z",
232
- "shell.execute_reply": "2023-02-27T14:12:19.745136Z"
233
  },
234
- "tags": [
235
- "hide_inp"
236
- ]
237
- },
238
- "outputs": [
239
  {
240
  "data": {
241
  "text/html": [
242
- "\n",
243
- "<!-- <link rel=\"stylesheet\" href=\"https://cdn.rawgit.com/Chalarangelo/mini.css/v3.0.1/dist/mini-default.min.css\"> -->\n",
244
- " <main class=\"container\">\n",
245
- "\n",
246
- "<h3>BashPrompt</h3>\n",
247
- "\n",
248
- "<dl>\n",
249
- " <dt>Input:</dt>\n",
250
- " <dd>\n",
251
- "<div class=\"highlight\"><pre><span></span><span class=\"p\">[</span><span class=\"s1\">&#39;ls&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;cat file.txt&#39;</span><span class=\"p\">]</span>\n",
252
- "</pre></div>\n",
253
- "\n",
254
- "\n",
255
- " </dd>\n",
256
- "\n",
257
- " <dt> Full Prompt: </dt>\n",
258
- " <dd>\n",
259
- " <details>\n",
260
- " <summary>Prompt</summary>\n",
261
- " <p>ls;cat file.txt</p>\n",
262
- " </details>\n",
263
- " </dd>\n",
264
- "\n",
265
- " <dt> Response: </dt>\n",
266
- " <dd>\n",
267
- " hello\n",
268
- " </dd>\n",
269
- "\n",
270
- " <dt>Value:</dt>\n",
271
- " <dd>\n",
272
- "<div class=\"highlight\"><pre><span></span><span class=\"n\">hello</span>\n",
273
- "</pre></div>\n",
274
- "\n",
275
- " </dd>\n",
276
- "</main>\n"
277
  ],
278
  "text/plain": [
279
- "HTML(html='\\n<!-- <link rel=\"stylesheet\" href=\"https://cdn.rawgit.com/Chalarangelo/mini.css/v3.0.1/dist/mini-default.min.css\"> -->\\n <main class=\"container\">\\n\\n<h3>BashPrompt</h3>\\n\\n<dl>\\n <dt>Input:</dt>\\n <dd>\\n<div class=\"highlight\"><pre><span></span><span class=\"p\">[</span><span class=\"s1\">&#39;ls&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;cat file.txt&#39;</span><span class=\"p\">]</span>\\n</pre></div>\\n\\n\\n </dd>\\n\\n <dt> Full Prompt: </dt>\\n <dd>\\n <details>\\n <summary>Prompt</summary>\\n <p>ls;cat file.txt</p>\\n </details>\\n </dd>\\n\\n <dt> Response: </dt>\\n <dd>\\n hello\\n </dd>\\n\\n <dt>Value:</dt>\\n <dd>\\n<div class=\"highlight\"><pre><span></span><span class=\"n\">hello</span>\\n</pre></div>\\n\\n </dd>\\n</main>\\n')"
280
  ]
281
  },
282
- "execution_count": 6,
283
  "metadata": {},
284
- "output_type": "execute_result"
285
- }
286
- ],
287
- "source": [
288
- "BashPrompt().show([\"ls\", \"cat file.txt\"], \"hello\")"
289
- ]
290
- },
291
- {
292
- "cell_type": "markdown",
293
- "id": "89c7bc6c",
294
- "metadata": {},
295
- "source": [
296
- "View the run log."
297
- ]
298
- },
299
- {
300
- "cell_type": "code",
301
- "execution_count": 7,
302
- "id": "7dbcec08",
303
- "metadata": {
304
- "execution": {
305
- "iopub.execute_input": "2023-02-27T14:12:19.748151Z",
306
- "iopub.status.busy": "2023-02-27T14:12:19.747899Z",
307
- "iopub.status.idle": "2023-02-27T14:12:19.768720Z",
308
- "shell.execute_reply": "2023-02-27T14:12:19.768248Z"
309
- }
310
- },
311
- "outputs": [
312
- {
313
- "name": "stderr",
314
- "output_type": "stream",
315
- "text": [
316
- "\u001b[38;5;15mfc682a98-f50a-4837-8b6d-87e843c19732\u001b[1m\u001b[0m\n",
317
- "└── \u001b[38;5;5m<class '__main__.CLIPrompt'>\u001b[0m/1\u001b[0m ⇒ \u001b[38;5;2mstarted\u001b[0m \u001b[38;5;15m2023-02-27 14:12:18Z\u001b[2m\u001b[0m ⧖ \u001b[38;5;4m1.531s\u001b[2m\u001b[0m\n",
318
- " ├─�� \u001b[38;5;5mInput Function\u001b[0m/2/1\u001b[0m ⇒ \u001b[38;5;2mstarted\u001b[0m \u001b[38;5;15m2023-02-27 14:12:18Z\u001b[2m\u001b[0m ⧖ \u001b[38;5;4m0.003s\u001b[2m\u001b[0m\n",
319
- " │ ├── \u001b[38;5;4minput\u001b[0m: \u001b[0m\n",
320
- " │ │ └── \u001b[38;5;4mquestion\u001b[0m: \"go up one directory, and then into the minichain directory,and list the files in the directory\"\u001b[0m\n",
321
- " │ └── \u001b[38;5;5mInput Function\u001b[0m/2/2\u001b[0m ⇒ \u001b[38;5;2msucceeded\u001b[0m \u001b[38;5;15m2023-02-27 14:12:18Z\u001b[2m\u001b[0m\n",
322
- " ├── \u001b[38;5;5mPrompted\u001b[0m/3/1\u001b[0m ⇒ \u001b[38;5;2mstarted\u001b[0m \u001b[38;5;15m2023-02-27 14:12:18Z\u001b[2m\u001b[0m ⧖ \u001b[38;5;4m1.528s\u001b[2m\u001b[0m\n",
323
- " │ ├── \u001b[38;5;4mprompt\u001b[0m: If someone asks you to perform a task, your job is to come up with a series of bash commands that will perform the task. There is no need to put \"#!/bin/bash\" in your answer. Make sure to reason step by step, using this format:⏎\n",
324
- " │ │ ⏎\n",
325
- " │ │ Question: \"copy the files in the directory named 'target' into a new directory at the same level as target called 'myNewDirectory'\"⏎\n",
326
- " │ │ ⏎\n",
327
- " │ │ I need to take the following actions:⏎\n",
328
- " │ │ - List all files in the directory⏎\n",
329
- " │ │ - Create a new directory⏎\n",
330
- " │ │ - Copy the files from the first directory into the second directory⏎\n",
331
- " │ │ ```bash⏎\n",
332
- " │ │ ls⏎\n",
333
- " │ │ mkdir myNewDirectory⏎\n",
334
- " │ │ cp -r target/* myNewDirectory⏎\n",
335
- " │ │ ```⏎\n",
336
- " │ │ ⏎\n",
337
- " │ │ That is the format. Begin!⏎\n",
338
- " │ │ ⏎\n",
339
- " │ │ Question: \"go up one directory, and then into the minichain directory,and list the files in the directory\"\u001b[0m\n",
340
- " │ └── \u001b[38;5;5mPrompted\u001b[0m/3/2\u001b[0m ⇒ \u001b[38;5;2msucceeded\u001b[0m \u001b[38;5;15m2023-02-27 14:12:19Z\u001b[2m\u001b[0m\n",
341
- " ├── \u001b[38;5;5mResult\u001b[0m/4/1\u001b[0m ⇒ \u001b[38;5;2mstarted\u001b[0m \u001b[38;5;15m2023-02-27 14:12:19Z\u001b[2m\u001b[0m ⧖ \u001b[38;5;4m0.000s\u001b[2m\u001b[0m\n",
342
- " │ ├── \u001b[38;5;4mresult\u001b[0m: ⏎\n",
343
- " │ │ ⏎\n",
344
- " │ │ ```bash⏎\n",
345
- " │ │ cd ..⏎\n",
346
- " │ │ cd minichain⏎\n",
347
- " │ │ ls⏎\n",
348
- " │ │ ```\u001b[0m\n",
349
- " │ └── \u001b[38;5;5mResult\u001b[0m/4/2\u001b[0m ⇒ \u001b[38;5;2msucceeded\u001b[0m \u001b[38;5;15m2023-02-27 14:12:19Z\u001b[2m\u001b[0m\n",
350
- " └── \u001b[38;5;5m<class '__main__.CLIPrompt'>\u001b[0m/5\u001b[0m ⇒ \u001b[38;5;2msucceeded\u001b[0m \u001b[38;5;15m2023-02-27 14:12:19Z\u001b[2m\u001b[0m\n",
351
- "\n",
352
- "\u001b[38;5;15m328e2368-6c0f-4a03-ae78-26aa43a517e3\u001b[1m\u001b[0m\n",
353
- "└── \u001b[38;5;5m<class '__main__.BashPrompt'>\u001b[0m/1\u001b[0m ⇒ \u001b[38;5;2mstarted\u001b[0m \u001b[38;5;15m2023-02-27 14:12:19Z\u001b[2m\u001b[0m ⧖ \u001b[38;5;4m0.006s\u001b[2m\u001b[0m\n",
354
- " ├── \u001b[38;5;5mInput Function\u001b[0m/2/1\u001b[0m ⇒ \u001b[38;5;2mstarted\u001b[0m \u001b[38;5;15m2023-02-27 14:12:19Z\u001b[2m\u001b[0m ⧖ \u001b[38;5;4m0.000s\u001b[2m\u001b[0m\n",
355
- " │ ├── \u001b[38;5;4minput\u001b[0m: \u001b[0m\n",
356
- " │ │ ├── \u001b[38;5;4m0\u001b[0m: cd ..\u001b[0m\n",
357
- " │ │ ├── \u001b[38;5;4m1\u001b[0m: cd minichain\u001b[0m\n",
358
- " │ │ └── \u001b[38;5;4m2\u001b[0m: ls\u001b[0m\n",
359
- " │ └── \u001b[38;5;5mInput Function\u001b[0m/2/2\u001b[0m ⇒ \u001b[38;5;2msucceeded\u001b[0m \u001b[38;5;15m2023-02-27 14:12:19Z\u001b[2m\u001b[0m\n",
360
- " ├── \u001b[38;5;5mPrompted\u001b[0m/3/1\u001b[0m ⇒ \u001b[38;5;2mstarted\u001b[0m \u001b[38;5;15m2023-02-27 14:12:19Z\u001b[2m\u001b[0m ⧖ \u001b[38;5;4m0.005s\u001b[2m\u001b[0m\n",
361
- " │ ├── \u001b[38;5;4mprompt\u001b[0m: cd ..;cd minichain;ls\u001b[0m\n",
362
- " │ └── \u001b[38;5;5mPrompted\u001b[0m/3/2\u001b[0m ⇒ \u001b[38;5;2msucceeded\u001b[0m \u001b[38;5;15m2023-02-27 14:12:19Z\u001b[2m\u001b[0m\n",
363
- " ├── \u001b[38;5;5mResult\u001b[0m/4/1\u001b[0m ⇒ \u001b[38;5;2mstarted\u001b[0m \u001b[38;5;15m2023-02-27 14:12:19Z\u001b[2m\u001b[0m ⧖ \u001b[38;5;4m0.000s\u001b[2m\u001b[0m\n",
364
- " │ ├── \u001b[38;5;4mresult\u001b[0m: #backend.py#⏎\n",
365
- " │ │ backend.py⏎\n",
366
- " │ │ base.py⏎\n",
367
- " │ │ __init__.py⏎\n",
368
- " │ │ lang.py⏎\n",
369
- " │ │ prompts.py⏎\n",
370
- " │ │ __pycache__⏎\n",
371
- " │ │ templates⏎\n",
372
- " │ │ \u001b[0m\n",
373
- " │ └── \u001b[38;5;5mResult\u001b[0m/4/2\u001b[0m ⇒ \u001b[38;5;2msucceeded\u001b[0m \u001b[38;5;15m2023-02-27 14:12:19Z\u001b[2m\u001b[0m\n",
374
- " └── \u001b[38;5;5m<class '__main__.BashPrompt'>\u001b[0m/5\u001b[0m ⇒ \u001b[38;5;2msucceeded\u001b[0m \u001b[38;5;15m2023-02-27 14:12:19Z\u001b[2m\u001b[0m\n",
375
- "\n",
376
- "\u001b[38;5;15mca5f4b25-55ca-441d-a0d2-f39ad0bca2d0\u001b[1m\u001b[0m\n",
377
- "└── \u001b[38;5;5mbash\u001b[0m/1\u001b[0m ⇒ \u001b[38;5;2mstarted\u001b[0m \u001b[38;5;15m2023-02-27 14:12:17Z\u001b[2m\u001b[0m ⧖ \u001b[38;5;4m1.850s\u001b[2m\u001b[0m\n",
378
- " └── \u001b[38;5;5mbash\u001b[0m/2\u001b[0m ⇒ \u001b[38;5;2msucceeded\u001b[0m \u001b[38;5;15m2023-02-27 14:12:19Z\u001b[2m\u001b[0m\n",
379
- "\n"
380
- ]
381
  }
382
  ],
383
  "source": [
384
- "minichain.show_log(\"bash.log\")"
 
 
 
 
 
 
 
 
 
 
385
  ]
386
  }
387
  ],
 
1
  {
2
  "cells": [
 
 
 
 
 
 
 
 
 
 
3
  {
4
  "cell_type": "code",
5
  "execution_count": 1,
6
+ "id": "d1d5ec44",
7
  "metadata": {
8
  "execution": {
9
+ "iopub.execute_input": "2023-03-22T17:00:17.499299Z",
10
+ "iopub.status.busy": "2023-03-22T17:00:17.498973Z",
11
+ "iopub.status.idle": "2023-03-22T17:00:17.506839Z",
12
+ "shell.execute_reply": "2023-03-22T17:00:17.506087Z"
13
+ },
14
+ "tags": [
15
+ "hide_inp"
16
+ ]
17
  },
18
  "outputs": [],
19
  "source": [
20
+ "\n",
21
+ "desc = \"\"\"\n",
22
+ "### Bash Command Suggestion\n",
23
+ "\n",
24
+ "Chain that ask for a command-line question and then runs the bash command. [[Code](https://github.com/srush/MiniChain/blob/main/examples/bash.py)]\n",
25
+ "\n",
26
+ "(Adapted from LangChain [BashChain](https://langchain.readthedocs.io/en/latest/modules/chains/examples/llm_bash.html))\n",
27
+ "\"\"\""
28
  ]
29
  },
30
  {
31
  "cell_type": "markdown",
32
+ "id": "94100dff",
33
+ "metadata": {},
 
 
34
  "source": [
35
+ "$"
36
  ]
37
  },
38
  {
39
  "cell_type": "code",
40
  "execution_count": 2,
41
+ "id": "b2ae061e",
42
  "metadata": {
43
  "execution": {
44
+ "iopub.execute_input": "2023-03-22T17:00:17.509606Z",
45
+ "iopub.status.busy": "2023-03-22T17:00:17.509377Z",
46
+ "iopub.status.idle": "2023-03-22T17:00:18.808162Z",
47
+ "shell.execute_reply": "2023-03-22T17:00:18.807504Z"
48
+ }
 
49
  },
50
  "outputs": [],
51
  "source": [
52
+ "from minichain import show, prompt, OpenAI, Bash"
 
 
 
 
 
 
53
  ]
54
  },
55
  {
56
+ "cell_type": "code",
57
+ "execution_count": 3,
58
+ "id": "9c440e40",
59
  "metadata": {
60
+ "execution": {
61
+ "iopub.execute_input": "2023-03-22T17:00:18.810785Z",
62
+ "iopub.status.busy": "2023-03-22T17:00:18.810465Z",
63
+ "iopub.status.idle": "2023-03-22T17:00:18.814003Z",
64
+ "shell.execute_reply": "2023-03-22T17:00:18.813511Z"
65
+ },
66
+ "lines_to_next_cell": 1
67
  },
68
+ "outputs": [],
69
  "source": [
70
+ "@prompt(OpenAI(), template_file = \"bash.pmpt.tpl\")\n",
71
+ "def cli_prompt(model, query):\n",
72
+ " x = model(dict(question=query))\n",
73
+ " return \"\\n\".join(x.strip().split(\"\\n\")[1:-1])"
74
  ]
75
  },
76
  {
77
  "cell_type": "code",
78
+ "execution_count": 4,
79
+ "id": "74115a3f",
80
  "metadata": {
81
  "execution": {
82
+ "iopub.execute_input": "2023-03-22T17:00:18.816250Z",
83
+ "iopub.status.busy": "2023-03-22T17:00:18.815868Z",
84
+ "iopub.status.idle": "2023-03-22T17:00:18.818697Z",
85
+ "shell.execute_reply": "2023-03-22T17:00:18.818263Z"
86
+ },
87
+ "lines_to_next_cell": 1
88
  },
89
  "outputs": [],
90
  "source": [
91
+ "@prompt(Bash())\n",
92
+ "def bash_run(model, x):\n",
93
+ " return model(x)"
 
 
 
 
 
 
 
 
 
 
 
94
  ]
95
  },
96
  {
97
  "cell_type": "code",
98
+ "execution_count": 5,
99
+ "id": "88210a7d",
100
  "metadata": {
101
  "execution": {
102
+ "iopub.execute_input": "2023-03-22T17:00:18.820762Z",
103
+ "iopub.status.busy": "2023-03-22T17:00:18.820577Z",
104
+ "iopub.status.idle": "2023-03-22T17:00:18.823279Z",
105
+ "shell.execute_reply": "2023-03-22T17:00:18.822838Z"
106
  }
107
  },
108
+ "outputs": [],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  "source": [
110
+ "def bash(query):\n",
111
+ " return bash_run(cli_prompt(query))"
 
 
 
 
 
 
112
  ]
113
  },
114
  {
115
  "cell_type": "markdown",
116
+ "id": "99d969c2",
117
  "metadata": {},
118
  "source": [
119
+ "$"
120
  ]
121
  },
122
  {
123
  "cell_type": "code",
124
+ "execution_count": 6,
125
+ "id": "fe4ffa7a",
126
  "metadata": {
127
  "execution": {
128
+ "iopub.execute_input": "2023-03-22T17:00:18.825360Z",
129
+ "iopub.status.busy": "2023-03-22T17:00:18.825177Z",
130
+ "iopub.status.idle": "2023-03-22T17:00:19.158113Z",
131
+ "shell.execute_reply": "2023-03-22T17:00:19.157509Z"
132
  },
133
+ "lines_to_next_cell": 2
 
 
 
134
  },
135
  "outputs": [
136
  {
137
+ "name": "stdout",
138
+ "output_type": "stream",
139
+ "text": [
140
+ "Running on local URL: http://127.0.0.1:7861\n",
141
+ "\n",
142
+ "To create a public link, set `share=True` in `launch()`.\n"
143
+ ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
  },
 
 
 
 
 
145
  {
146
  "data": {
147
  "text/html": [
148
+ "<div><iframe src=\"http://127.0.0.1:7861/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
  ],
150
  "text/plain": [
151
+ "<IPython.core.display.HTML object>"
152
  ]
153
  },
 
154
  "metadata": {},
155
+ "output_type": "display_data"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156
  }
157
  ],
158
  "source": [
159
+ "gradio = show(bash,\n",
160
+ " subprompts=[cli_prompt, bash_run],\n",
161
+ " examples=['Go up one directory, and then into the minichain directory,'\n",
162
+ " 'and list the files in the directory',\n",
163
+ " \"Please write a bash script that prints 'Hello World' to the console.\"],\n",
164
+ " out_type=\"markdown\",\n",
165
+ " description=desc,\n",
166
+ " code=open(\"bash.py\", \"r\").read().split(\"$\")[1].strip().strip(\"#\").strip(),\n",
167
+ " )\n",
168
+ "if __name__ == \"__main__\":\n",
169
+ " gradio.launch()"
170
  ]
171
  }
172
  ],
bash.py CHANGED
@@ -11,69 +11,33 @@ Chain that ask for a command-line question and then runs the bash command. [[Cod
11
 
12
  # $
13
 
14
- import minichain
15
 
16
- # Prompt that asks LLM to produce a bash command.
17
 
 
 
 
 
18
 
19
- class CLIPrompt(minichain.TemplatePrompt):
20
- template_file = "bash.pmpt.tpl"
 
21
 
22
- def parse(self, out: str, inp):
23
- out = out.strip()
24
- assert out.startswith("```bash")
25
- return out.split("\n")[1:-1]
26
 
27
 
28
- # Prompt that runs the bash command.
29
-
30
-
31
- class BashPrompt(minichain.Prompt):
32
- def prompt(self, inp) -> str:
33
- return ";".join(inp).replace("\n", "")
34
-
35
- def parse(self, out: str, inp) -> str:
36
- return out
37
-
38
-
39
- # Generate and run bash command.
40
-
41
- with minichain.start_chain("bash") as backend:
42
- question = (
43
-
44
- )
45
- prompt = CLIPrompt(backend.OpenAI()).chain(BashPrompt(backend.BashProcess()))
46
-
47
  # $
48
-
49
- gradio = prompt.to_gradio(fields =["question"],
50
- examples=['Go up one directory, and then into the minichain directory,'
51
- 'and list the files in the directory',
52
- "Please write a bash script that prints 'Hello World' to the console."],
53
- out_type="markdown",
54
- description=desc,
55
- code=open("bash.py", "r").read().split("$")[1].strip().strip("#").strip(),
56
- templates=[open("bash.pmpt.tpl")]
57
- )
58
 
 
 
 
 
 
 
 
 
 
59
  if __name__ == "__main__":
60
  gradio.launch()
61
 
62
-
63
-
64
- # View the prompts.
65
-
66
- # + tags=["hide_inp"]
67
- # CLIPrompt().show(
68
- # {"question": "list the files in the directory"}, """```bash\nls\n```"""
69
- # )
70
- # # -
71
-
72
-
73
- # # + tags=["hide_inp"]
74
- # BashPrompt().show(["ls", "cat file.txt"], "hello")
75
- # # -
76
-
77
- # # View the run log.
78
-
79
- # minichain.show_log("bash.log")
 
11
 
12
  # $
13
 
14
+ from minichain import show, prompt, OpenAI, Bash
15
 
 
16
 
17
+ @prompt(OpenAI(), template_file = "bash.pmpt.tpl")
18
+ def cli_prompt(model, query):
19
+ x = model(dict(question=query))
20
+ return "\n".join(x.strip().split("\n")[1:-1])
21
 
22
+ @prompt(Bash())
23
+ def bash_run(model, x):
24
+ return model(x)
25
 
26
+ def bash(query):
27
+ return bash_run(cli_prompt(query))
 
 
28
 
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  # $
 
 
 
 
 
 
 
 
 
 
31
 
32
+ gradio = show(bash,
33
+ subprompts=[cli_prompt, bash_run],
34
+ examples=['Go up one directory, and then into the minichain directory,'
35
+ 'and list the files in the directory',
36
+ "Please write a bash script that prints 'Hello World' to the console."],
37
+ out_type="markdown",
38
+ description=desc,
39
+ code=open("bash.py", "r").read().split("$")[1].strip().strip("#").strip(),
40
+ )
41
  if __name__ == "__main__":
42
  gradio.launch()
43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
chat.pmpt.tpl CHANGED
@@ -6,6 +6,8 @@ Assistant is constantly learning and improving, and its capabilities are constan
6
 
7
  Overall, Assistant is a powerful tool that can help with a wide range of tasks and provide valuable insights and information on a wide range of topics. Whether you need help with a specific question or just want to have a conversation about a particular topic, Assistant is here to assist.
8
 
 
 
9
  {% for d in memory %}
10
  Human: {{d[0]}}
11
  AI: {{d[1]}}
 
6
 
7
  Overall, Assistant is a powerful tool that can help with a wide range of tasks and provide valuable insights and information on a wide range of topics. Whether you need help with a specific question or just want to have a conversation about a particular topic, Assistant is here to assist.
8
 
9
+ I want you to act as a Linux terminal. I will type commands and you will reply with what the terminal should show. I want you to only reply with the terminal output inside one unique code block, and nothing else. Do not write explanations. Do not type commands unless I instruct you to do so. When I need to tell you something in English I will do so by putting text inside curly brackets {like this}.
10
+
11
  {% for d in memory %}
12
  Human: {{d[0]}}
13
  AI: {{d[1]}}
chat.py CHANGED
@@ -2,24 +2,19 @@
2
  desc = """
3
  ### Chat
4
 
5
- "ChatGPT" like example for multi-turn chat with state. [[Code](https://github.com/srush/MiniChain/blob/main/examples/chat.py)]
6
 
7
  (Adapted from [LangChain](https://langchain.readthedocs.io/en/latest/modules/memory/examples/chatgpt_clone.html)'s version of this [blog post](https://www.engraved.blog/building-a-virtual-machine-inside/).)
 
8
  """
9
  # -
10
 
11
 
12
- import warnings
13
-
14
- # + tags=["hide_inp"]
15
- warnings.filterwarnings("ignore")
16
- # -
17
-
18
  # $
19
 
20
- from dataclasses import dataclass
21
  from typing import List, Tuple
22
- import minichain
23
 
24
  # Generic stateful Memory
25
 
@@ -36,25 +31,15 @@ class State:
36
 
37
  # Chat prompt with memory
38
 
39
- class ChatPrompt(minichain.TemplatePrompt):
40
- template_file = "chatgpt.pmpt.tpl"
41
- def parse(self, out: str, inp: State) -> State:
42
- result = out.split("Assistant:")[-1]
43
- return inp.push(result)
44
-
45
- # class Human(minichain.Prompt):
46
- # def parse(self, out: str, inp: State) -> State:
47
- # return inp.human_input = out
48
-
49
-
50
- with minichain.start_chain("chat") as backend:
51
- prompt = ChatPrompt(backend.OpenAI())
52
- state = State([])
53
 
54
  # $
55
-
56
  examples = [
57
- "I want you to act as a Linux terminal. I will type commands and you will reply with what the terminal should show. I want you to only reply with the terminal output inside one unique code block, and nothing else. Do not write explanations. Do not type commands unless I instruct you to do so. When I need to tell you something in English I will do so by putting text inside curly brackets {like this}. My first command is pwd.",
58
  "ls ~",
59
  "cd ~",
60
  "{Please make a file jokes.txt inside and put some jokes inside}",
@@ -64,19 +49,15 @@ examples = [
64
  "nvidia-smi"
65
  ]
66
 
67
- gradio = prompt.to_gradio(fields= ["human_input"],
68
- initial_state= state,
69
- examples=examples,
70
- out_type="json",
71
- description=desc,
72
- code=open("chat.py", "r").read().split("$")[1].strip().strip("#").strip(),
73
- templates=[open("chat.pmpt.tpl")]
74
-
75
  )
76
  if __name__ == "__main__":
77
  gradio.launch()
78
 
79
- # for i in range(len(fake_human)):
80
- # human.chain(prompt)
81
 
82
-
 
2
  desc = """
3
  ### Chat
4
 
5
+ A chat-like example for multi-turn chat with state. [[Code](https://github.com/srush/MiniChain/blob/main/examples/chat.py)]
6
 
7
  (Adapted from [LangChain](https://langchain.readthedocs.io/en/latest/modules/memory/examples/chatgpt_clone.html)'s version of this [blog post](https://www.engraved.blog/building-a-virtual-machine-inside/).)
8
+
9
  """
10
  # -
11
 
12
 
 
 
 
 
 
 
13
  # $
14
 
15
+ from dataclasses import dataclass, replace
16
  from typing import List, Tuple
17
+ from minichain import OpenAI, prompt, show
18
 
19
  # Generic stateful Memory
20
 
 
31
 
32
  # Chat prompt with memory
33
 
34
+ @prompt(OpenAI(), template_file="chat.pmpt.tpl")
35
+ def chat_prompt(model, state: State) -> State:
36
+ out = model(state)
37
+ result = out.split("Assistant:")[-1]
38
+ return state.push(result)
 
 
 
 
 
 
 
 
 
39
 
40
  # $
41
+
42
  examples = [
 
43
  "ls ~",
44
  "cd ~",
45
  "{Please make a file jokes.txt inside and put some jokes inside}",
 
49
  "nvidia-smi"
50
  ]
51
 
52
+ gradio = show(lambda command, state: chat_prompt(replace(state, human_input=command)),
53
+ initial_state=State([]),
54
+ subprompts=[chat_prompt],
55
+ examples=examples,
56
+ out_type="json",
57
+ description=desc,
58
+ code=open("chat.py", "r").read().split("$")[1].strip().strip("#").strip(),
 
59
  )
60
  if __name__ == "__main__":
61
  gradio.launch()
62
 
 
 
63
 
 
gatsby.ipynb CHANGED
The diff for this file is too large to render. See raw diff
 
gatsby.pmpt.tpl CHANGED
@@ -1,4 +1,4 @@
1
- Context information is below.
2
 
3
 
4
  ---------------------
 
1
+ Context information is below.
2
 
3
 
4
  ---------------------
gatsby.py CHANGED
@@ -12,8 +12,7 @@ Chain that does question answering with Hugging Face embeddings. [[Code](https:/
12
 
13
  import datasets
14
  import numpy as np
15
-
16
- from minichain import EmbeddingPrompt, TemplatePrompt, show_log, start_chain
17
 
18
  # Load data with embeddings (computed beforehand)
19
 
@@ -22,38 +21,33 @@ gatsby.add_faiss_index("embeddings")
22
 
23
  # Fast KNN retieval prompt
24
 
25
- class KNNPrompt(EmbeddingPrompt):
26
- def prompt(self, inp):
27
- return inp["query"]
28
-
29
- def find(self, out, inp):
30
- res = gatsby.get_nearest_examples("embeddings", np.array(out), 1)
31
- return {"question": inp["query"], "docs": res.examples["passages"]}
32
-
33
- # QA prompt to ask question with examples
34
 
 
 
 
 
35
 
36
- class QAPrompt(TemplatePrompt):
37
- template_file = "gatsby.pmpt.tpl"
 
38
 
39
 
40
- with start_chain("gatsby") as backend:
41
- prompt = KNNPrompt(
42
- backend.HuggingFaceEmbed("sentence-transformers/all-mpnet-base-v2")
43
- ).chain(QAPrompt(backend.OpenAI()))
44
-
45
  # $
46
 
47
 
48
-
49
- gradio = prompt.to_gradio(fields=["query"],
50
- examples=["What did Gatsby do before he met Daisy?",
51
- "What did the narrator do after getting back to Chicago?"],
52
- keys={"HF_KEY"},
53
- description=desc,
54
- code=open("gatsby.py", "r").read().split("$")[1].strip().strip("#").strip(),
55
- templates=[open("gatsby.pmpt.tpl")]
56
- )
57
  if __name__ == "__main__":
58
  gradio.launch()
59
 
 
12
 
13
  import datasets
14
  import numpy as np
15
+ from minichain import prompt, show, HuggingFaceEmbed, OpenAI
 
16
 
17
  # Load data with embeddings (computed beforehand)
18
 
 
21
 
22
  # Fast KNN retieval prompt
23
 
24
+ @prompt(HuggingFaceEmbed("sentence-transformers/all-mpnet-base-v2"))
25
+ def get_neighbors(model, inp, k=1):
26
+ embedding = model(inp)
27
+ res = olympics.get_nearest_examples("embeddings", np.array(embedding), k)
28
+ return res.examples["passages"]
 
 
 
 
29
 
30
+ @prompt(OpenAI(),
31
+ template_file="gatsby.pmpt.tpl")
32
+ def ask(model, query, neighbors):
33
+ return model(dict(question=query, docs=neighbors))
34
 
35
+ def gatsby(query):
36
+ n = get_neighbors(query)
37
+ return ask(query, n)
38
 
39
 
 
 
 
 
 
40
  # $
41
 
42
 
43
+ gradio = show(gatsby,
44
+ subprompts=[get_neighbors, ask],
45
+ examples=["What did Gatsby do before he met Daisy?",
46
+ "What did the narrator do after getting back to Chicago?"],
47
+ keys={"HF_KEY"},
48
+ description=desc,
49
+ code=open("gatsby.py", "r").read().split("$")[1].strip().strip("#").strip()
50
+ )
 
51
  if __name__ == "__main__":
52
  gradio.launch()
53
 
math_demo.py CHANGED
@@ -10,33 +10,35 @@ Chain that solves a math word problem by first generating and then running Pytho
10
 
11
  # $
12
 
13
- import minichain
14
 
15
- # Prompt that asks LLM for code from math.
16
 
17
- class MathPrompt(minichain.TemplatePrompt):
18
- template_file = "math.pmpt.tpl"
19
-
20
- # Ask a question and run it as python code.
21
 
22
- with minichain.start_chain("math") as backend:
23
- math_prompt = MathPrompt(backend.OpenAI())
24
- code_prompt = minichain.SimplePrompt(backend.Python())
25
- prompt = math_prompt.chain(code_prompt)
 
 
 
 
26
 
27
  # $
28
 
29
  # + tags=["hide_inp"]
30
- gradio = prompt.to_gradio(fields =["question"],
31
- examples=["What is the sum of the powers of 3 (3^i) that are smaller than 100?",
32
- "What is the sum of the 10 first positive integers?",
33
- "Carla is downloading a 200 GB file. She can download 2 GB/minute, but 40% of the way through the download, the download fails. Then Carla has to restart the download from the beginning. How load did it take her to download the file in minutes?"],
34
- out_type="markdown",
35
- description=desc,
36
- code=open("math_demo.py", "r").read().split("$")[1].strip().strip("#").strip(),
37
- templates=[open("math.pmpt.tpl")]
38
-
39
- )
40
  if __name__ == "__main__":
41
  gradio.launch()
42
  # -
 
10
 
11
  # $
12
 
13
+ from minichain import show, prompt, OpenAI, Python
14
 
 
15
 
16
+ @prompt(OpenAI(), template_file="math.pmpt.tpl")
17
+ def math_prompt(model, question):
18
+ "Prompt to call GPT with a Jinja template"
19
+ return model(dict(question=question))
20
 
21
+ @prompt(Python())
22
+ def python(model, code):
23
+ "Prompt to call Python interpreter"
24
+ return int(model(code))
25
+
26
+ def math_demo(question):
27
+ "Chain them together"
28
+ return python(math_prompt(question))
29
 
30
  # $
31
 
32
  # + tags=["hide_inp"]
33
+ gradio = show(math_demo,
34
+ examples=["What is the sum of the powers of 3 (3^i) that are smaller than 100?",
35
+ "What is the sum of the 10 first positive integers?",],
36
+ # "Carla is downloading a 200 GB file. She can download 2 GB/minute, but 40% of the way through the download, the download fails. Then Carla has to restart the download from the beginning. How load did it take her to download the file in minutes?"],
37
+ subprompts=[math_prompt, python],
38
+ out_type="json",
39
+ description=desc,
40
+ code=open("math_demo.py", "r").read().split("$")[1].strip().strip("#").strip(),
41
+ )
 
42
  if __name__ == "__main__":
43
  gradio.launch()
44
  # -
math_demo.py~ ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # + tags=["hide_inp"]
2
+ desc = """
3
+ ### Word Problem Solver
4
+
5
+ Chain that solves a math word problem by first generating and then running Python code. [[Code](https://github.com/srush/MiniChain/blob/main/examples/math.py)]
6
+
7
+ (Adapted from Dust [maths-generate-code](https://dust.tt/spolu/a/d12ac33169))
8
+ """
9
+ # -
10
+
11
+ # $
12
+
13
+ import minichain
14
+
15
+ # Prompt that asks LLM for code from math.
16
+
17
+ class MathPrompt(minichain.TemplatePrompt):
18
+ template_file = "math.pmpt.tpl"
19
+
20
+ # Ask a question and run it as python code.
21
+
22
+ with minichain.start_chain("math") as backend:
23
+ math_prompt = MathPrompt(backend.OpenAI())
24
+ code_prompt = minichain.SimplePrompt(backend.Python())
25
+ prompt = math_prompt.chain(code_prompt)
26
+
27
+ # $
28
+
29
+ # + tags=["hide_inp"]
30
+ gradio = prompt.to_gradio(fields =["question"],
31
+ examples=["What is the sum of the powers of 3 (3^i) that are smaller than 100?",
32
+ "What is the sum of the 10 first positive integers?",
33
+ "Carla is downloading a 200 GB file. She can download 2 GB/minute, but 40% of the way through the download, the download fails. Then Carla has to restart the download from the beginning. How load did it take her to download the file in minutes?"],
34
+ out_type="markdown",
35
+ description=desc,
36
+ code=open("math_demo.py", "r").read().split("$")[1].strip().strip("#").strip(),
37
+ templates=[open("math.pmpt.tpl")]
38
+
39
+ )
40
+ if __name__ == "__main__":
41
+ gradio.launch()
42
+ # -
43
+
mycache. ADDED
Binary file (24.6 kB). View file
 
ner.ipynb CHANGED
@@ -1,182 +1,158 @@
1
  {
2
  "cells": [
3
  {
4
- "cell_type": "markdown",
5
- "id": "2e16f61f",
6
- "metadata": {},
 
 
 
 
 
 
 
 
 
 
 
 
7
  "source": [
8
- "# NER"
 
 
 
 
 
 
 
9
  ]
10
  },
11
  {
12
  "cell_type": "markdown",
13
- "id": "904e43dd",
14
  "metadata": {},
15
  "source": [
16
- "Notebook implementation of named entity recognition.\n",
17
- "Adapted from [promptify](https://github.com/promptslab/Promptify/blob/main/promptify/prompts/nlp/templates/ner.jinja)."
18
  ]
19
  },
20
  {
21
  "cell_type": "code",
22
  "execution_count": 2,
23
- "id": "b4b1d58e",
24
  "metadata": {
25
  "execution": {
26
- "iopub.execute_input": "2023-03-13T23:43:12.445242Z",
27
- "iopub.status.busy": "2023-03-13T23:43:12.444962Z",
28
- "iopub.status.idle": "2023-03-13T23:43:12.450741Z",
29
- "shell.execute_reply": "2023-03-13T23:43:12.450139Z"
30
- }
 
31
  },
32
  "outputs": [],
33
  "source": [
34
- "import json"
35
  ]
36
  },
37
  {
38
  "cell_type": "code",
39
  "execution_count": 3,
40
- "id": "fdb154d0",
41
  "metadata": {
42
  "execution": {
43
- "iopub.execute_input": "2023-03-13T23:43:12.453113Z",
44
- "iopub.status.busy": "2023-03-13T23:43:12.452884Z",
45
- "iopub.status.idle": "2023-03-13T23:43:12.649309Z",
46
- "shell.execute_reply": "2023-03-13T23:43:12.648483Z"
47
  },
48
  "lines_to_next_cell": 1
49
  },
50
  "outputs": [],
51
  "source": [
52
- "import minichain"
53
- ]
54
- },
55
- {
56
- "cell_type": "markdown",
57
- "id": "d5665917",
58
- "metadata": {},
59
- "source": [
60
- "Prompt to extract NER tags as json"
61
  ]
62
  },
63
  {
64
  "cell_type": "code",
65
  "execution_count": 4,
66
- "id": "1cfe0e75",
67
  "metadata": {
68
  "execution": {
69
- "iopub.execute_input": "2023-03-13T23:43:12.654908Z",
70
- "iopub.status.busy": "2023-03-13T23:43:12.653463Z",
71
- "iopub.status.idle": "2023-03-13T23:43:12.660078Z",
72
- "shell.execute_reply": "2023-03-13T23:43:12.659313Z"
73
- },
74
- "lines_to_next_cell": 1
75
  },
76
  "outputs": [],
77
  "source": [
78
- "class NERPrompt(minichain.TemplatePrompt):\n",
79
- " template_file = \"ner.pmpt.tpl\"\n",
80
- "\n",
81
- " def parse(self, response, inp):\n",
82
- " return json.loads(response)"
83
- ]
84
- },
85
- {
86
- "cell_type": "markdown",
87
- "id": "11619d3d",
88
- "metadata": {},
89
- "source": [
90
- "Use NER to ask a simple queston."
91
  ]
92
  },
93
  {
94
  "cell_type": "code",
95
  "execution_count": 5,
96
- "id": "584bef0d",
97
  "metadata": {
98
  "execution": {
99
- "iopub.execute_input": "2023-03-13T23:43:12.667113Z",
100
- "iopub.status.busy": "2023-03-13T23:43:12.665599Z",
101
- "iopub.status.idle": "2023-03-13T23:43:12.673456Z",
102
- "shell.execute_reply": "2023-03-13T23:43:12.672558Z"
103
- },
104
- "lines_to_next_cell": 1
105
  },
106
  "outputs": [],
107
  "source": [
108
- "class TeamPrompt(minichain.Prompt):\n",
109
- " def prompt(self, inp):\n",
110
- " return \"Can you describe these basketball teams? \" + \\\n",
111
- " \" \".join([i[\"E\"] for i in inp if i[\"T\"] ==\"Team\"])\n",
112
- "\n",
113
- " def parse(self, response, inp):\n",
114
- " return response"
115
  ]
116
  },
117
  {
118
  "cell_type": "markdown",
119
- "id": "6ea6c161",
120
  "metadata": {},
121
  "source": [
122
- "Run the system."
123
  ]
124
  },
125
  {
126
  "cell_type": "code",
127
  "execution_count": 6,
128
- "id": "a8ee77f4",
129
  "metadata": {
130
  "execution": {
131
- "iopub.execute_input": "2023-03-13T23:43:12.678805Z",
132
- "iopub.status.busy": "2023-03-13T23:43:12.678446Z",
133
- "iopub.status.idle": "2023-03-13T23:43:12.682592Z",
134
- "shell.execute_reply": "2023-03-13T23:43:12.682060Z"
135
  }
136
  },
137
  "outputs": [],
138
  "source": [
139
- "with minichain.start_chain(\"ner\") as backend:\n",
140
- " ner_prompt = NERPrompt(backend.OpenAI())\n",
141
- " team_prompt = TeamPrompt(backend.OpenAI())\n",
142
- " prompt = ner_prompt.chain(team_prompt)\n",
143
- " # results = prompt(\n",
144
- " # {\"text_input\": \"An NBA playoff pairing a year ago, the 76ers (39-20) meet the Miami Heat (32-29) for the first time this season on Monday night at home.\",\n",
145
- " # \"labels\" : [\"Team\", \"Date\"],\n",
146
- " # \"domain\": \"Sports\"\n",
147
- " # }\n",
148
- " # )\n",
149
- " # print(results)"
150
  ]
151
  },
152
  {
153
  "cell_type": "code",
154
  "execution_count": 7,
155
- "id": "55b9ce94",
156
- "metadata": {
157
- "execution": {
158
- "iopub.execute_input": "2023-03-13T23:43:12.684777Z",
159
- "iopub.status.busy": "2023-03-13T23:43:12.684591Z",
160
- "iopub.status.idle": "2023-03-13T23:43:12.687815Z",
161
- "shell.execute_reply": "2023-03-13T23:43:12.687194Z"
162
- }
163
- },
164
- "outputs": [],
165
- "source": [
166
- "ner_prompt.set_display_options(markdown=True)\n",
167
- "team_prompt.set_display_options(markdown=True) "
168
- ]
169
- },
170
- {
171
- "cell_type": "code",
172
- "execution_count": 8,
173
- "id": "fe56c4ba",
174
  "metadata": {
175
  "execution": {
176
- "iopub.execute_input": "2023-03-13T23:43:12.690233Z",
177
- "iopub.status.busy": "2023-03-13T23:43:12.689776Z",
178
- "iopub.status.idle": "2023-03-13T23:43:19.799186Z",
179
- "shell.execute_reply": "2023-03-13T23:43:19.798652Z"
180
  },
181
  "lines_to_next_cell": 2
182
  },
@@ -185,7 +161,7 @@
185
  "name": "stdout",
186
  "output_type": "stream",
187
  "text": [
188
- "Running on local URL: http://127.0.0.1:7860\n",
189
  "\n",
190
  "To create a public link, set `share=True` in `launch()`.\n"
191
  ]
@@ -193,7 +169,7 @@
193
  {
194
  "data": {
195
  "text/html": [
196
- "<div><iframe src=\"http://127.0.0.1:7860/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
197
  ],
198
  "text/plain": [
199
  "<IPython.core.display.HTML object>"
@@ -201,24 +177,16 @@
201
  },
202
  "metadata": {},
203
  "output_type": "display_data"
204
- },
205
- {
206
- "data": {
207
- "text/plain": []
208
- },
209
- "execution_count": 8,
210
- "metadata": {},
211
- "output_type": "execute_result"
212
  }
213
  ],
214
  "source": [
215
- "prompt.to_gradio(fields =[\"text_input\", \"labels\", \"domain\"],\n",
216
- " examples=[[\"An NBA playoff pairing a year ago, the 76ers (39-20) meet the Miami Heat (32-29) for the first time this season on Monday night at home.\", \"Team, Date\", \"Sports\"]]).launch()"
217
  ]
218
  },
219
  {
220
  "cell_type": "markdown",
221
- "id": "0c81d136",
222
  "metadata": {},
223
  "source": [
224
  "View prompt examples."
@@ -227,13 +195,13 @@
227
  {
228
  "cell_type": "code",
229
  "execution_count": 8,
230
- "id": "d75cba8c",
231
  "metadata": {
232
  "execution": {
233
- "iopub.execute_input": "2023-03-13T23:43:19.802519Z",
234
- "iopub.status.busy": "2023-03-13T23:43:19.802098Z",
235
- "iopub.status.idle": "2023-03-13T23:43:19.805558Z",
236
- "shell.execute_reply": "2023-03-13T23:43:19.804994Z"
237
  },
238
  "tags": [
239
  "hide_inp"
 
1
  {
2
  "cells": [
3
  {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "id": "6b40c8cc",
7
+ "metadata": {
8
+ "execution": {
9
+ "iopub.execute_input": "2023-03-22T17:00:46.670809Z",
10
+ "iopub.status.busy": "2023-03-22T17:00:46.670088Z",
11
+ "iopub.status.idle": "2023-03-22T17:00:46.679313Z",
12
+ "shell.execute_reply": "2023-03-22T17:00:46.678767Z"
13
+ },
14
+ "tags": [
15
+ "hide_inp"
16
+ ]
17
+ },
18
+ "outputs": [],
19
  "source": [
20
+ "\n",
21
+ "desc = \"\"\"\n",
22
+ "### Named Entity Recognition\n",
23
+ "\n",
24
+ "Chain that does named entity recognition with arbitrary labels. [[Code](https://github.com/srush/MiniChain/blob/main/examples/ner.py)]\n",
25
+ "\n",
26
+ "(Adapted from [promptify](https://github.com/promptslab/Promptify/blob/main/promptify/prompts/nlp/templates/ner.jinja)).\n",
27
+ "\"\"\""
28
  ]
29
  },
30
  {
31
  "cell_type": "markdown",
32
+ "id": "f6e33520",
33
  "metadata": {},
34
  "source": [
35
+ "$"
 
36
  ]
37
  },
38
  {
39
  "cell_type": "code",
40
  "execution_count": 2,
41
+ "id": "de258da8",
42
  "metadata": {
43
  "execution": {
44
+ "iopub.execute_input": "2023-03-22T17:00:46.681769Z",
45
+ "iopub.status.busy": "2023-03-22T17:00:46.681580Z",
46
+ "iopub.status.idle": "2023-03-22T17:00:47.985872Z",
47
+ "shell.execute_reply": "2023-03-22T17:00:47.985221Z"
48
+ },
49
+ "lines_to_next_cell": 1
50
  },
51
  "outputs": [],
52
  "source": [
53
+ "from minichain import prompt, show, OpenAI"
54
  ]
55
  },
56
  {
57
  "cell_type": "code",
58
  "execution_count": 3,
59
+ "id": "f517f9a5",
60
  "metadata": {
61
  "execution": {
62
+ "iopub.execute_input": "2023-03-22T17:00:47.988564Z",
63
+ "iopub.status.busy": "2023-03-22T17:00:47.988242Z",
64
+ "iopub.status.idle": "2023-03-22T17:00:47.991610Z",
65
+ "shell.execute_reply": "2023-03-22T17:00:47.991041Z"
66
  },
67
  "lines_to_next_cell": 1
68
  },
69
  "outputs": [],
70
  "source": [
71
+ "@prompt(OpenAI(), template_file = \"ner.pmpt.tpl\", parser=\"json\")\n",
72
+ "def ner_extract(model, **kwargs):\n",
73
+ " return model(kwargs)"
 
 
 
 
 
 
74
  ]
75
  },
76
  {
77
  "cell_type": "code",
78
  "execution_count": 4,
79
+ "id": "fe5ec878",
80
  "metadata": {
81
  "execution": {
82
+ "iopub.execute_input": "2023-03-22T17:00:47.993777Z",
83
+ "iopub.status.busy": "2023-03-22T17:00:47.993478Z",
84
+ "iopub.status.idle": "2023-03-22T17:00:47.996957Z",
85
+ "shell.execute_reply": "2023-03-22T17:00:47.996449Z"
86
+ }
 
87
  },
88
  "outputs": [],
89
  "source": [
90
+ "@prompt(OpenAI())\n",
91
+ "def team_describe(model, inp):\n",
92
+ " query = \"Can you describe these basketball teams? \" + \\\n",
93
+ " \" \".join([i[\"E\"] for i in inp if i[\"T\"] ==\"Team\"])\n",
94
+ " return model(query)"
 
 
 
 
 
 
 
 
95
  ]
96
  },
97
  {
98
  "cell_type": "code",
99
  "execution_count": 5,
100
+ "id": "cf059e37",
101
  "metadata": {
102
  "execution": {
103
+ "iopub.execute_input": "2023-03-22T17:00:47.999077Z",
104
+ "iopub.status.busy": "2023-03-22T17:00:47.998839Z",
105
+ "iopub.status.idle": "2023-03-22T17:00:48.002102Z",
106
+ "shell.execute_reply": "2023-03-22T17:00:48.001662Z"
107
+ }
 
108
  },
109
  "outputs": [],
110
  "source": [
111
+ "def ner(text_input, labels, domain):\n",
112
+ " extract = ner_extract(dict(text_input=text_input, labels=labels, domain=domain))\n",
113
+ " return team_describe(extract)"
 
 
 
 
114
  ]
115
  },
116
  {
117
  "cell_type": "markdown",
118
+ "id": "fe198253",
119
  "metadata": {},
120
  "source": [
121
+ "$"
122
  ]
123
  },
124
  {
125
  "cell_type": "code",
126
  "execution_count": 6,
127
+ "id": "24ca918c",
128
  "metadata": {
129
  "execution": {
130
+ "iopub.execute_input": "2023-03-22T17:00:48.004490Z",
131
+ "iopub.status.busy": "2023-03-22T17:00:48.004142Z",
132
+ "iopub.status.idle": "2023-03-22T17:00:48.254708Z",
133
+ "shell.execute_reply": "2023-03-22T17:00:48.254069Z"
134
  }
135
  },
136
  "outputs": [],
137
  "source": [
138
+ "gradio = show(ner,\n",
139
+ " examples=[[\"An NBA playoff pairing a year ago, the 76ers (39-20) meet the Miami Heat (32-29) for the first time this season on Monday night at home.\", \"Team, Date\", \"Sports\"]],\n",
140
+ " description=desc,\n",
141
+ " subprompts=[ner_extract, team_describe],\n",
142
+ " code=open(\"ner.py\", \"r\").read().split(\"$\")[1].strip().strip(\"#\").strip(),\n",
143
+ " )"
 
 
 
 
 
144
  ]
145
  },
146
  {
147
  "cell_type": "code",
148
  "execution_count": 7,
149
+ "id": "d5247097",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
  "metadata": {
151
  "execution": {
152
+ "iopub.execute_input": "2023-03-22T17:00:48.257352Z",
153
+ "iopub.status.busy": "2023-03-22T17:00:48.257149Z",
154
+ "iopub.status.idle": "2023-03-22T17:00:48.319870Z",
155
+ "shell.execute_reply": "2023-03-22T17:00:48.319111Z"
156
  },
157
  "lines_to_next_cell": 2
158
  },
 
161
  "name": "stdout",
162
  "output_type": "stream",
163
  "text": [
164
+ "Running on local URL: http://127.0.0.1:7861\n",
165
  "\n",
166
  "To create a public link, set `share=True` in `launch()`.\n"
167
  ]
 
169
  {
170
  "data": {
171
  "text/html": [
172
+ "<div><iframe src=\"http://127.0.0.1:7861/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
173
  ],
174
  "text/plain": [
175
  "<IPython.core.display.HTML object>"
 
177
  },
178
  "metadata": {},
179
  "output_type": "display_data"
 
 
 
 
 
 
 
 
180
  }
181
  ],
182
  "source": [
183
+ "if __name__ == \"__main__\":\n",
184
+ " gradio.launch()"
185
  ]
186
  },
187
  {
188
  "cell_type": "markdown",
189
+ "id": "7cbb9856",
190
  "metadata": {},
191
  "source": [
192
  "View prompt examples."
 
195
  {
196
  "cell_type": "code",
197
  "execution_count": 8,
198
+ "id": "83d3ad7a",
199
  "metadata": {
200
  "execution": {
201
+ "iopub.execute_input": "2023-03-22T17:00:48.322776Z",
202
+ "iopub.status.busy": "2023-03-22T17:00:48.322504Z",
203
+ "iopub.status.idle": "2023-03-22T17:00:48.326248Z",
204
+ "shell.execute_reply": "2023-03-22T17:00:48.325611Z"
205
  },
206
  "tags": [
207
  "hide_inp"
ner.py CHANGED
@@ -11,48 +11,37 @@ Chain that does named entity recognition with arbitrary labels. [[Code](https://
11
 
12
  # $
13
 
14
- import json
15
- import minichain
16
 
17
- # Prompt to extract NER tags as json
 
 
18
 
19
- class NERPrompt(minichain.TemplatePrompt):
20
- template_file = "ner.pmpt.tpl"
 
 
 
21
 
22
- def parse(self, response, inp):
23
- return json.loads(response)
24
 
25
- # Use NER to ask a simple queston.
 
 
26
 
27
- class TeamPrompt(minichain.Prompt):
28
- def prompt(self, inp):
29
- return "Can you describe these basketball teams? " + \
30
- " ".join([i["E"] for i in inp if i["T"] =="Team"])
31
 
32
- def parse(self, response, inp):
33
- return response
34
-
35
- # Run the system.
36
 
37
- with minichain.start_chain("ner") as backend:
38
- ner_prompt = NERPrompt(backend.OpenAI())
39
- team_prompt = TeamPrompt(backend.OpenAI())
40
- prompt = ner_prompt.chain(team_prompt)
 
 
41
 
42
- # $
43
-
44
- gradio = prompt.to_gradio(fields =["text_input", "labels", "domain"],
45
- examples=[["An NBA playoff pairing a year ago, the 76ers (39-20) meet the Miami Heat (32-29) for the first time this season on Monday night at home.", "Team, Date", "Sports"]],
46
- description=desc,
47
- code=open("ner.py", "r").read().split("$")[1].strip().strip("#").strip(),
48
- templates=[open("ner.pmpt.tpl")]
49
- )
50
-
51
-
52
  if __name__ == "__main__":
53
  gradio.launch()
54
 
55
-
56
  # View prompt examples.
57
 
58
  # + tags=["hide_inp"]
 
11
 
12
  # $
13
 
14
+ from minichain import prompt, show, OpenAI
 
15
 
16
+ @prompt(OpenAI(), template_file = "ner.pmpt.tpl", parser="json")
17
+ def ner_extract(model, **kwargs):
18
+ return model(kwargs)
19
 
20
+ @prompt(OpenAI())
21
+ def team_describe(model, inp):
22
+ query = "Can you describe these basketball teams? " + \
23
+ " ".join([i["E"] for i in inp if i["T"] =="Team"])
24
+ return model(query)
25
 
 
 
26
 
27
+ def ner(text_input, labels, domain):
28
+ extract = ner_extract(dict(text_input=text_input, labels=labels, domain=domain))
29
+ return team_describe(extract)
30
 
 
 
 
 
31
 
32
+ # $
 
 
 
33
 
34
+ gradio = show(ner,
35
+ examples=[["An NBA playoff pairing a year ago, the 76ers (39-20) meet the Miami Heat (32-29) for the first time this season on Monday night at home.", "Team, Date", "Sports"]],
36
+ description=desc,
37
+ subprompts=[ner_extract, team_describe],
38
+ code=open("ner.py", "r").read().split("$")[1].strip().strip("#").strip(),
39
+ )
40
 
 
 
 
 
 
 
 
 
 
 
41
  if __name__ == "__main__":
42
  gradio.launch()
43
 
44
+
45
  # View prompt examples.
46
 
47
  # + tags=["hide_inp"]
pal.ipynb CHANGED
@@ -1,527 +1,207 @@
1
  {
2
  "cells": [
3
- {
4
- "cell_type": "markdown",
5
- "id": "95a637f8",
6
- "metadata": {},
7
- "source": [
8
- "Adapted from Prompt-aided Language Models [PAL](https://arxiv.org/pdf/2211.10435.pdf)."
9
- ]
10
- },
11
  {
12
  "cell_type": "code",
13
  "execution_count": 1,
14
- "id": "3eefe2ae",
15
  "metadata": {
16
  "execution": {
17
- "iopub.execute_input": "2023-02-27T14:15:43.541342Z",
18
- "iopub.status.busy": "2023-02-27T14:15:43.541045Z",
19
- "iopub.status.idle": "2023-02-27T14:15:43.740615Z",
20
- "shell.execute_reply": "2023-02-27T14:15:43.739910Z"
21
- },
22
- "lines_to_next_cell": 1
23
  },
24
  "outputs": [],
25
  "source": [
26
- "import minichain"
 
 
 
 
 
 
27
  ]
28
  },
29
  {
30
  "cell_type": "markdown",
31
- "id": "1932de81",
32
  "metadata": {},
33
  "source": [
34
- "PAL Prompt"
35
  ]
36
  },
37
  {
38
  "cell_type": "code",
39
  "execution_count": 2,
40
- "id": "8b0f3ba4",
41
  "metadata": {
42
  "execution": {
43
- "iopub.execute_input": "2023-02-27T14:15:43.745885Z",
44
- "iopub.status.busy": "2023-02-27T14:15:43.744171Z",
45
- "iopub.status.idle": "2023-02-27T14:15:43.749926Z",
46
- "shell.execute_reply": "2023-02-27T14:15:43.749298Z"
47
  },
48
  "lines_to_next_cell": 1
49
  },
50
  "outputs": [],
51
  "source": [
52
- "class PalPrompt(minichain.TemplatePrompt):\n",
53
- " template_file = \"pal.pmpt.tpl\""
54
- ]
55
- },
56
- {
57
- "cell_type": "markdown",
58
- "id": "5e6b0f1e",
59
- "metadata": {},
60
- "source": [
61
- "Prompt to run and print python code."
62
  ]
63
  },
64
  {
65
  "cell_type": "code",
66
  "execution_count": 3,
67
- "id": "5f5fea2c",
68
  "metadata": {
69
  "execution": {
70
- "iopub.execute_input": "2023-02-27T14:15:43.754328Z",
71
- "iopub.status.busy": "2023-02-27T14:15:43.753171Z",
72
- "iopub.status.idle": "2023-02-27T14:15:43.758857Z",
73
- "shell.execute_reply": "2023-02-27T14:15:43.758175Z"
74
  },
75
  "lines_to_next_cell": 1
76
  },
77
  "outputs": [],
78
  "source": [
79
- "class PyPrompt(minichain.Prompt):\n",
80
- " def prompt(self, inp):\n",
81
- " return inp + \"\\nprint(solution())\"\n",
82
- "\n",
83
- " def parse(self, response, inp):\n",
84
- " return int(response)"
85
  ]
86
  },
87
  {
88
- "cell_type": "markdown",
89
- "id": "b494356e",
90
- "metadata": {},
 
 
 
 
 
 
 
 
 
 
91
  "source": [
92
- "Chain the prompts."
 
 
93
  ]
94
  },
95
  {
96
  "cell_type": "code",
97
- "execution_count": 4,
98
- "id": "d6e170f7",
99
  "metadata": {
100
  "execution": {
101
- "iopub.execute_input": "2023-02-27T14:15:43.763969Z",
102
- "iopub.status.busy": "2023-02-27T14:15:43.762806Z",
103
- "iopub.status.idle": "2023-02-27T14:15:54.833413Z",
104
- "shell.execute_reply": "2023-02-27T14:15:54.832851Z"
105
- }
 
106
  },
107
- "outputs": [
108
- {
109
- "name": "stdout",
110
- "output_type": "stream",
111
- "text": [
112
- "9\n"
113
- ]
114
- }
115
- ],
116
  "source": [
117
- "with minichain.start_chain(\"pal\") as backend:\n",
118
- " question = \"Melanie is a door-to-door saleswoman. She sold a third of her ' \\\n",
119
- " 'vacuum cleaners at the green house, 2 more to the red house, and half of ' \\\n",
120
- " 'what was left at the orange house. If Melanie has 5 vacuum cleaners left, ' \\\n",
121
- " 'how many did she start with?'\"\n",
122
- " prompt = PalPrompt(backend.OpenAI()).chain(PyPrompt(backend.Python()))\n",
123
- " result = prompt({\"question\": question})\n",
124
- " print(result)"
125
  ]
126
  },
127
  {
128
  "cell_type": "markdown",
129
- "id": "4a631744",
130
  "metadata": {},
131
  "source": [
132
- "View prompt examples."
133
  ]
134
  },
135
  {
136
  "cell_type": "code",
137
- "execution_count": 5,
138
- "id": "729a67c3",
139
  "metadata": {
140
  "execution": {
141
- "iopub.execute_input": "2023-02-27T14:15:54.835748Z",
142
- "iopub.status.busy": "2023-02-27T14:15:54.835484Z",
143
- "iopub.status.idle": "2023-02-27T14:15:54.882169Z",
144
- "shell.execute_reply": "2023-02-27T14:15:54.881546Z"
145
- },
146
- "tags": [
147
- "hide_inp"
148
- ]
149
- },
150
- "outputs": [
151
- {
152
- "data": {
153
- "text/html": [
154
- "\n",
155
- "<!-- <link rel=\"stylesheet\" href=\"https://cdn.rawgit.com/Chalarangelo/mini.css/v3.0.1/dist/mini-default.min.css\"> -->\n",
156
- " <main class=\"container\">\n",
157
- "\n",
158
- "<h3>PalPrompt</h3>\n",
159
- "\n",
160
- "<dl>\n",
161
- " <dt>Input:</dt>\n",
162
- " <dd>\n",
163
- "<div class=\"highlight\"><pre><span></span><span class=\"p\">{</span><span class=\"s1\">&#39;question&#39;</span><span class=\"p\">:</span> <span class=\"s1\">&#39;Joe has 10 cars and Bobby has 12. How many do they have together?&#39;</span><span class=\"p\">}</span>\n",
164
- "</pre></div>\n",
165
- "\n",
166
- "\n",
167
- " </dd>\n",
168
- "\n",
169
- " <dt> Full Prompt: </dt>\n",
170
- " <dd>\n",
171
- " <details>\n",
172
- " <summary>Prompt</summary>\n",
173
- " <p>Q: Olivia has $23. She bought five bagels for $3 each. How much money does she have left?<br><br># solution in Python:<br><br><br>def solution():<br> \"\"\"Olivia has $23. She bought five bagels for $3 each. How much money does she have left?\"\"\"<br> money_initial = 23<br> bagels = 5<br> bagel_cost = 3<br> money_spent = bagels * bagel_cost<br> money_left = money_initial - money_spent<br> result = money_left<br> return result<br><br><br><br><br><br>Q: Michael had 58 golf balls. On tuesday, he lost 23 golf balls. On wednesday, he lost 2 more. How many golf balls did he have at the end of wednesday?<br><br># solution in Python:<br><br><br>def solution():<br> \"\"\"Michael had 58 golf balls. On tuesday, he lost 23 golf balls. On wednesday, he lost 2 more. How many golf balls did he have at the end of wednesday?\"\"\"<br> golf_balls_initial = 58<br> golf_balls_lost_tuesday = 23<br> golf_balls_lost_wednesday = 2<br> golf_balls_left = golf_balls_initial - golf_balls_lost_tuesday - golf_balls_lost_wednesday<br> result = golf_balls_left<br> return result<br><br><br><br><br><br>Q: There were nine computers in the server room. Five more computers were installed each day, from monday to thursday. How many computers are now in the server room?<br><br># solution in Python:<br><br><br>def solution():<br> \"\"\"There were nine computers in the server room. Five more computers were installed each day, from monday to thursday. How many computers are now in the server room?\"\"\"<br> computers_initial = 9<br> computers_per_day = 5<br> num_days = 4 # 4 days between monday and thursday<br> computers_added = computers_per_day * num_days<br> computers_total = computers_initial + computers_added<br> result = computers_total<br> return result<br><br><br><br><br><br>Q: Shawn has five toys. For Christmas, he got two toys each from his mom and dad. How many toys does he have now?<br><br># solution in Python:<br><br><br>def solution():<br> \"\"\"Shawn has five toys. For Christmas, he got two toys each from his mom and dad. How many toys does he have now?\"\"\"<br> toys_initial = 5<br> mom_toys = 2<br> dad_toys = 2<br> total_received = mom_toys + dad_toys<br> total_toys = toys_initial + total_received<br> result = total_toys<br> return result<br><br><br><br><br><br>Q: Jason had 20 lollipops. He gave Denny some lollipops. Now Jason has 12 lollipops. How many lollipops did Jason give to Denny?<br><br># solution in Python:<br><br><br>def solution():<br> \"\"\"Jason had 20 lollipops. He gave Denny some lollipops. Now Jason has 12 lollipops. How many lollipops did Jason give to Denny?\"\"\"<br> jason_lollipops_initial = 20<br> jason_lollipops_after = 12<br> denny_lollipops = jason_lollipops_initial - jason_lollipops_after<br> result = denny_lollipops<br> return result<br><br><br><br><br><br>Q: Leah had 32 chocolates and her sister had 42. If they ate 35, how many pieces do they have left in total?<br><br># solution in Python:<br><br><br>def solution():<br> \"\"\"Leah had 32 chocolates and her sister had 42. If they ate 35, how many pieces do they have left in total?\"\"\"<br> leah_chocolates = 32<br> sister_chocolates = 42<br> total_chocolates = leah_chocolates + sister_chocolates<br> chocolates_eaten = 35<br> chocolates_left = total_chocolates - chocolates_eaten<br> result = chocolates_left<br> return result<br><br><br><br><br><br>Q: If there are 3 cars in the parking lot and 2 more cars arrive, how many cars are in the parking lot?<br><br># solution in Python:<br><br><br>def solution():<br> \"\"\"If there are 3 cars in the parking lot and 2 more cars arrive, how many cars are in the parking lot?\"\"\"<br> cars_initial = 3<br> cars_arrived = 2<br> total_cars = cars_initial + cars_arrived<br> result = total_cars<br> return result<br><br><br><br><br><br>Q: There are 15 trees in the grove. Grove workers will plant trees in the grove today. After they are done, there will be 21 trees. How many trees did the grove workers plant today?<br><br># solution in Python:<br><br><br>def solution():<br> \"\"\"There are 15 trees in the grove. Grove workers will plant trees in the grove today. After they are done, there will be 21 trees. How many trees did the grove workers plant today?\"\"\"<br> trees_initial = 15<br> trees_after = 21<br> trees_added = trees_after - trees_initial<br> result = trees_added<br> return result<br><br><br><br><br><br>Q: <div style='color:red'>Joe has 10 cars and Bobby has 12. How many do they have together?</div><br><br># solution in Python:</p>\n",
174
- " </details>\n",
175
- " </dd>\n",
176
- "\n",
177
- " <dt> Response: </dt>\n",
178
- " <dd>\n",
179
- " def solution():<br>\treturn 10 + 12\n",
180
- " </dd>\n",
181
- "\n",
182
- " <dt>Value:</dt>\n",
183
- " <dd>\n",
184
- "<div class=\"highlight\"><pre><span></span><span class=\"k\">def</span> <span class=\"nf\">solution</span><span class=\"p\">():</span>\n",
185
- "\t<span class=\"k\">return</span> <span class=\"mi\">10</span> <span class=\"o\">+</span> <span class=\"mi\">12</span>\n",
186
- "</pre></div>\n",
187
- "\n",
188
- " </dd>\n",
189
- "</main>\n"
190
- ],
191
- "text/plain": [
192
- "HTML(html='\\n<!-- <link rel=\"stylesheet\" href=\"https://cdn.rawgit.com/Chalarangelo/mini.css/v3.0.1/dist/mini-default.min.css\"> -->\\n <main class=\"container\">\\n\\n<h3>PalPrompt</h3>\\n\\n<dl>\\n <dt>Input:</dt>\\n <dd>\\n<div class=\"highlight\"><pre><span></span><span class=\"p\">{</span><span class=\"s1\">&#39;question&#39;</span><span class=\"p\">:</span> <span class=\"s1\">&#39;Joe has 10 cars and Bobby has 12. How many do they have together?&#39;</span><span class=\"p\">}</span>\\n</pre></div>\\n\\n\\n </dd>\\n\\n <dt> Full Prompt: </dt>\\n <dd>\\n <details>\\n <summary>Prompt</summary>\\n <p>Q: Olivia has $23. She bought five bagels for $3 each. How much money does she have left?<br><br># solution in Python:<br><br><br>def solution():<br> \"\"\"Olivia has $23. She bought five bagels for $3 each. How much money does she have left?\"\"\"<br> money_initial = 23<br> bagels = 5<br> bagel_cost = 3<br> money_spent = bagels * bagel_cost<br> money_left = money_initial - money_spent<br> result = money_left<br> return result<br><br><br><br><br><br>Q: Michael had 58 golf balls. On tuesday, he lost 23 golf balls. On wednesday, he lost 2 more. How many golf balls did he have at the end of wednesday?<br><br># solution in Python:<br><br><br>def solution():<br> \"\"\"Michael had 58 golf balls. On tuesday, he lost 23 golf balls. On wednesday, he lost 2 more. How many golf balls did he have at the end of wednesday?\"\"\"<br> golf_balls_initial = 58<br> golf_balls_lost_tuesday = 23<br> golf_balls_lost_wednesday = 2<br> golf_balls_left = golf_balls_initial - golf_balls_lost_tuesday - golf_balls_lost_wednesday<br> result = golf_balls_left<br> return result<br><br><br><br><br><br>Q: There were nine computers in the server room. Five more computers were installed each day, from monday to thursday. How many computers are now in the server room?<br><br># solution in Python:<br><br><br>def solution():<br> \"\"\"There were nine computers in the server room. Five more computers were installed each day, from monday to thursday. How many computers are now in the server room?\"\"\"<br> computers_initial = 9<br> computers_per_day = 5<br> num_days = 4 # 4 days between monday and thursday<br> computers_added = computers_per_day * num_days<br> computers_total = computers_initial + computers_added<br> result = computers_total<br> return result<br><br><br><br><br><br>Q: Shawn has five toys. For Christmas, he got two toys each from his mom and dad. How many toys does he have now?<br><br># solution in Python:<br><br><br>def solution():<br> \"\"\"Shawn has five toys. For Christmas, he got two toys each from his mom and dad. How many toys does he have now?\"\"\"<br> toys_initial = 5<br> mom_toys = 2<br> dad_toys = 2<br> total_received = mom_toys + dad_toys<br> total_toys = toys_initial + total_received<br> result = total_toys<br> return result<br><br><br><br><br><br>Q: Jason had 20 lollipops. He gave Denny some lollipops. Now Jason has 12 lollipops. How many lollipops did Jason give to Denny?<br><br># solution in Python:<br><br><br>def solution():<br> \"\"\"Jason had 20 lollipops. He gave Denny some lollipops. Now Jason has 12 lollipops. How many lollipops did Jason give to Denny?\"\"\"<br> jason_lollipops_initial = 20<br> jason_lollipops_after = 12<br> denny_lollipops = jason_lollipops_initial - jason_lollipops_after<br> result = denny_lollipops<br> return result<br><br><br><br><br><br>Q: Leah had 32 chocolates and her sister had 42. If they ate 35, how many pieces do they have left in total?<br><br># solution in Python:<br><br><br>def solution():<br> \"\"\"Leah had 32 chocolates and her sister had 42. If they ate 35, how many pieces do they have left in total?\"\"\"<br> leah_chocolates = 32<br> sister_chocolates = 42<br> total_chocolates = leah_chocolates + sister_chocolates<br> chocolates_eaten = 35<br> chocolates_left = total_chocolates - chocolates_eaten<br> result = chocolates_left<br> return result<br><br><br><br><br><br>Q: If there are 3 cars in the parking lot and 2 more cars arrive, how many cars are in the parking lot?<br><br># solution in Python:<br><br><br>def solution():<br> \"\"\"If there are 3 cars in the parking lot and 2 more cars arrive, how many cars are in the parking lot?\"\"\"<br> cars_initial = 3<br> cars_arrived = 2<br> total_cars = cars_initial + cars_arrived<br> result = total_cars<br> return result<br><br><br><br><br><br>Q: There are 15 trees in the grove. Grove workers will plant trees in the grove today. After they are done, there will be 21 trees. How many trees did the grove workers plant today?<br><br># solution in Python:<br><br><br>def solution():<br> \"\"\"There are 15 trees in the grove. Grove workers will plant trees in the grove today. After they are done, there will be 21 trees. How many trees did the grove workers plant today?\"\"\"<br> trees_initial = 15<br> trees_after = 21<br> trees_added = trees_after - trees_initial<br> result = trees_added<br> return result<br><br><br><br><br><br>Q: <div style=\\'color:red\\'>Joe has 10 cars and Bobby has 12. How many do they have together?</div><br><br># solution in Python:</p>\\n </details>\\n </dd>\\n\\n <dt> Response: </dt>\\n <dd>\\n def solution():<br>\\treturn 10 + 12\\n </dd>\\n\\n <dt>Value:</dt>\\n <dd>\\n<div class=\"highlight\"><pre><span></span><span class=\"k\">def</span> <span class=\"nf\">solution</span><span class=\"p\">():</span>\\n\\t<span class=\"k\">return</span> <span class=\"mi\">10</span> <span class=\"o\">+</span> <span class=\"mi\">12</span>\\n</pre></div>\\n\\n </dd>\\n</main>\\n')"
193
- ]
194
- },
195
- "execution_count": 5,
196
- "metadata": {},
197
- "output_type": "execute_result"
198
  }
199
- ],
 
200
  "source": [
201
- "PalPrompt().show(\n",
202
- " {\"question\": \"Joe has 10 cars and Bobby has 12. How many do they have together?\"},\n",
203
- " \"def solution():\\n\\treturn 10 + 12\",\n",
204
- ")"
205
  ]
206
  },
207
  {
208
  "cell_type": "code",
209
- "execution_count": 6,
210
- "id": "616a782d",
211
  "metadata": {
212
  "execution": {
213
- "iopub.execute_input": "2023-02-27T14:15:54.884523Z",
214
- "iopub.status.busy": "2023-02-27T14:15:54.884246Z",
215
- "iopub.status.idle": "2023-02-27T14:15:54.889558Z",
216
- "shell.execute_reply": "2023-02-27T14:15:54.889097Z"
217
- },
218
- "tags": [
219
- "hide_inp"
220
- ]
221
- },
222
- "outputs": [
223
- {
224
- "data": {
225
- "text/html": [
226
- "\n",
227
- "<!-- <link rel=\"stylesheet\" href=\"https://cdn.rawgit.com/Chalarangelo/mini.css/v3.0.1/dist/mini-default.min.css\"> -->\n",
228
- " <main class=\"container\">\n",
229
- "\n",
230
- "<h3>PyPrompt</h3>\n",
231
- "\n",
232
- "<dl>\n",
233
- " <dt>Input:</dt>\n",
234
- " <dd>\n",
235
- "<div class=\"highlight\"><pre><span></span><span class=\"k\">def</span> <span class=\"nf\">solution</span><span class=\"p\">():</span>\n",
236
- "\t<span class=\"k\">return</span> <span class=\"mi\">10</span> <span class=\"o\">+</span> <span class=\"mi\">12</span>\n",
237
- "</pre></div>\n",
238
- "\n",
239
- "\n",
240
- " </dd>\n",
241
- "\n",
242
- " <dt> Full Prompt: </dt>\n",
243
- " <dd>\n",
244
- " <details>\n",
245
- " <summary>Prompt</summary>\n",
246
- " <p>def solution():<br>\treturn 10 + 12<br>print(solution())</p>\n",
247
- " </details>\n",
248
- " </dd>\n",
249
- "\n",
250
- " <dt> Response: </dt>\n",
251
- " <dd>\n",
252
- " 22\n",
253
- " </dd>\n",
254
- "\n",
255
- " <dt>Value:</dt>\n",
256
- " <dd>\n",
257
- "<div class=\"highlight\"><pre><span></span><span class=\"mi\">22</span>\n",
258
- "</pre></div>\n",
259
- "\n",
260
- " </dd>\n",
261
- "</main>\n"
262
- ],
263
- "text/plain": [
264
- "HTML(html='\\n<!-- <link rel=\"stylesheet\" href=\"https://cdn.rawgit.com/Chalarangelo/mini.css/v3.0.1/dist/mini-default.min.css\"> -->\\n <main class=\"container\">\\n\\n<h3>PyPrompt</h3>\\n\\n<dl>\\n <dt>Input:</dt>\\n <dd>\\n<div class=\"highlight\"><pre><span></span><span class=\"k\">def</span> <span class=\"nf\">solution</span><span class=\"p\">():</span>\\n\\t<span class=\"k\">return</span> <span class=\"mi\">10</span> <span class=\"o\">+</span> <span class=\"mi\">12</span>\\n</pre></div>\\n\\n\\n </dd>\\n\\n <dt> Full Prompt: </dt>\\n <dd>\\n <details>\\n <summary>Prompt</summary>\\n <p>def solution():<br>\\treturn 10 + 12<br>print(solution())</p>\\n </details>\\n </dd>\\n\\n <dt> Response: </dt>\\n <dd>\\n 22\\n </dd>\\n\\n <dt>Value:</dt>\\n <dd>\\n<div class=\"highlight\"><pre><span></span><span class=\"mi\">22</span>\\n</pre></div>\\n\\n </dd>\\n</main>\\n')"
265
- ]
266
- },
267
- "execution_count": 6,
268
- "metadata": {},
269
- "output_type": "execute_result"
270
  }
271
- ],
272
- "source": [
273
- "PyPrompt().show(\"def solution():\\n\\treturn 10 + 12\", \"22\")"
274
- ]
275
- },
276
- {
277
- "cell_type": "markdown",
278
- "id": "5aad5ea7",
279
- "metadata": {},
280
  "source": [
281
- "View the log."
 
 
 
 
 
282
  ]
283
  },
284
  {
285
  "cell_type": "code",
286
- "execution_count": 7,
287
- "id": "a4fb48ac",
288
  "metadata": {
289
  "execution": {
290
- "iopub.execute_input": "2023-02-27T14:15:54.892000Z",
291
- "iopub.status.busy": "2023-02-27T14:15:54.891678Z",
292
- "iopub.status.idle": "2023-02-27T14:15:54.914877Z",
293
- "shell.execute_reply": "2023-02-27T14:15:54.914134Z"
294
  }
295
  },
296
  "outputs": [
297
  {
298
- "name": "stderr",
299
  "output_type": "stream",
300
  "text": [
301
- "\u001b[38;5;15m28b775fd-0862-4c8f-aada-b6158be3b664\u001b[1m\u001b[0m\n",
302
- "└── \u001b[38;5;5m<class '__main__.PalPrompt'>\u001b[0m/1\u001b[0m ⇒ \u001b[38;5;2mstarted\u001b[0m \u001b[38;5;15m2023-02-27 14:15:44Z\u001b[2m\u001b[0m ⧖ \u001b[38;5;4m10.739s\u001b[2m\u001b[0m\n",
303
- " ├── \u001b[38;5;5mInput Function\u001b[0m/2/1\u001b[0m ⇒ \u001b[38;5;2mstarted\u001b[0m \u001b[38;5;15m2023-02-27 14:15:44Z\u001b[2m\u001b[0m ⧖ \u001b[38;5;4m0.003s\u001b[2m\u001b[0m\n",
304
- " │ ├── \u001b[38;5;4minput\u001b[0m: \u001b[0m\n",
305
- " │ │ └── \u001b[38;5;4mquestion\u001b[0m: Melanie is a door-to-door saleswoman. She sold a third of her ' 'vacuum cleaners at the green house, 2 more to the red house, and half of ' 'what was left at the orange house. If Melanie has 5 vacuum cleaners left, ' 'how many did she start with?'\u001b[0m\n",
306
- " │ └── \u001b[38;5;5mInput Function\u001b[0m/2/2\u001b[0m ⇒ \u001b[38;5;2msucceeded\u001b[0m \u001b[38;5;15m2023-02-27 14:15:44Z\u001b[2m\u001b[0m\n",
307
- " ├── \u001b[38;5;5mPrompted\u001b[0m/3/1\u001b[0m ⇒ \u001b[38;5;2mstarted\u001b[0m \u001b[38;5;15m2023-02-27 14:15:44Z\u001b[2m\u001b[0m ⧖ \u001b[38;5;4m10.736s\u001b[2m\u001b[0m\n",
308
- " │ ├── \u001b[38;5;4mprompt\u001b[0m: Q: Olivia has $23. She bought five bagels for $3 each. How much money does she have left?⏎\n",
309
- " │ │ ⏎\n",
310
- " │ │ # solution in Python:⏎\n",
311
- " │ │ ⏎\n",
312
- " │ │ ⏎\n",
313
- " │ │ def solution():⏎\n",
314
- " │ │ \"\"\"Olivia has $23. She bought five bagels for $3 each. How much money does she have left?\"\"\"⏎\n",
315
- " │ │ money_initial = 23⏎\n",
316
- " │ │ bagels = 5⏎\n",
317
- " │ │ bagel_cost = 3⏎\n",
318
- " │ │ money_spent = bagels * bagel_cost⏎\n",
319
- " │ │ money_left = money_initial - money_spent⏎\n",
320
- " │ │ result = money_left⏎\n",
321
- " │ │ return result⏎\n",
322
- " │ │ ⏎\n",
323
- " │ │ ⏎\n",
324
- " │ │ ⏎\n",
325
- " │ │ ⏎\n",
326
- " │ │ ⏎\n",
327
- " │ │ Q: Michael had 58 golf balls. On tuesday, he lost 23 golf balls. On wednesday, he lost 2 more. How many golf balls did he have at the end of wednesday?⏎\n",
328
- " │ │ ⏎\n",
329
- " │ │ # solution in Python:⏎\n",
330
- " │ │ ⏎\n",
331
- " │ │ ⏎\n",
332
- " │ │ def solution():⏎\n",
333
- " │ │ \"\"\"Michael had 58 golf balls. On tuesday, he lost 23 golf balls. On wednesday, he lost 2 more. How many golf balls did he have at the end of wednesday?\"\"\"⏎\n",
334
- " │ │ golf_balls_initial = 58⏎\n",
335
- " │ │ golf_balls_lost_tuesday = 23⏎\n",
336
- " │ │ golf_balls_lost_wednesday = 2⏎\n",
337
- " │ │ golf_balls_left = golf_balls_initial - golf_balls_lost_tuesday - golf_balls_lost_wednesday⏎\n",
338
- " │ │ result = golf_balls_left⏎\n",
339
- " │ │ return result⏎\n",
340
- " │ │ ⏎\n",
341
- " │ │ ⏎\n",
342
- " │ │ ⏎\n",
343
- " │ │ ⏎\n",
344
- " │ │ ⏎\n",
345
- " │ │ Q: There were nine computers in the server room. Five more computers were installed each day, from monday to thursday. How many computers are now in the server room?⏎\n",
346
- " │ │ ⏎\n",
347
- " │ │ # solution in Python:⏎\n",
348
- " │ │ ⏎\n",
349
- " │ │ ⏎\n",
350
- " │ │ def solution():⏎\n",
351
- " │ │ \"\"\"There were nine computers in the server room. Five more computers were installed each day, from monday to thursday. How many computers are now in the server room?\"\"\"⏎\n",
352
- " │ │ computers_initial = 9⏎\n",
353
- " │ │ computers_per_day = 5⏎\n",
354
- " │ │ num_days = 4 # 4 days between monday and thursday⏎\n",
355
- " │ │ computers_added = computers_per_day * num_days⏎\n",
356
- " │ │ computers_total = computers_initial + computers_added⏎\n",
357
- " │ │ result = computers_total⏎\n",
358
- " │ │ return result⏎\n",
359
- " │ │ ⏎\n",
360
- " │ │ ⏎\n",
361
- " │ │ ⏎\n",
362
- " │ │ ⏎\n",
363
- " │ │ ⏎\n",
364
- " │ │ Q: Shawn has five toys. For Christmas, he got two toys each from his mom and dad. How many toys does he have now?⏎\n",
365
- " │ │ ⏎\n",
366
- " │ │ # solution in Python:⏎\n",
367
- " │ │ ⏎\n",
368
- " │ │ ⏎\n",
369
- " │ │ def solution():⏎\n",
370
- " │ │ \"\"\"Shawn has five toys. For Christmas, he got two toys each from his mom and dad. How many toys does he have now?\"\"\"⏎\n",
371
- " │ │ toys_initial = 5⏎\n",
372
- " │ │ mom_toys = 2⏎\n",
373
- " │ │ dad_toys = 2⏎\n",
374
- " │ │ total_received = mom_toys + dad_toys⏎\n",
375
- " │ │ total_toys = toys_initial + total_received⏎\n",
376
- " │ │ result = total_toys⏎\n",
377
- " │ │ return result⏎\n",
378
- " │ │ ⏎\n",
379
- " │ │ ⏎\n",
380
- " │ │ ⏎\n",
381
- " │ │ ⏎\n",
382
- " │ │ ⏎\n",
383
- " │ │ Q: Jason had 20 lollipops. He gave Denny some lollipops. Now Jason has 12 lollipops. How many lollipops did Jason give to Denny?⏎\n",
384
- " │ │ ⏎\n",
385
- " │ │ # solution in Python:⏎\n",
386
- " │ │ ⏎\n",
387
- " │ │ ⏎\n",
388
- " │ │ def solution():⏎\n",
389
- " │ │ \"\"\"Jason had 20 lollipops. He gave Denny some lollipops. Now Jason has 12 lollipops. How many lollipops did Jason give to Denny?\"\"\"⏎\n",
390
- " │ │ jason_lollipops_initial = 20⏎\n",
391
- " │ │ jason_lollipops_after = 12⏎\n",
392
- " │ │ denny_lollipops = jason_lollipops_initial - jason_lollipops_after⏎\n",
393
- " │ │ result = denny_lollipops⏎\n",
394
- " │ │ return result⏎\n",
395
- " │ │ ⏎\n",
396
- " │ │ ⏎\n",
397
- " │ │ ⏎\n",
398
- " │ │ ⏎\n",
399
- " │ │ ⏎\n",
400
- " │ │ Q: Leah had 32 chocolates and her sister had 42. If they ate 35, how many pieces do they have left in total?⏎\n",
401
- " │ │ ⏎\n",
402
- " │ │ # solution in Python:⏎\n",
403
- " │ │ ⏎\n",
404
- " │ │ ⏎\n",
405
- " │ │ def solution():⏎\n",
406
- " │ │ \"\"\"Leah had 32 chocolates and her sister had 42. If they ate 35, how many pieces do they have left in total?\"\"\"⏎\n",
407
- " │ │ leah_chocolates = 32⏎\n",
408
- " │ │ sister_chocolates = 42⏎\n",
409
- " │ │ total_chocolates = leah_chocolates + sister_chocolates⏎\n",
410
- " │ │ chocolates_eaten = 35⏎\n",
411
- " │ │ chocolates_left = total_chocolates - chocolates_eaten⏎\n",
412
- " │ │ result = chocolates_left⏎\n",
413
- " │ │ return result⏎\n",
414
- " │ │ ⏎\n",
415
- " │ │ ⏎\n",
416
- " │ │ ⏎\n",
417
- " │ │ ⏎\n",
418
- " │ │ ⏎\n",
419
- " │ │ Q: If there are 3 cars in the parking lot and 2 more cars arrive, how many cars are in the parking lot?⏎\n",
420
- " │ │ ⏎\n",
421
- " │ │ # solution in Python:⏎\n",
422
- " │ │ ⏎\n",
423
- " │ │ ⏎\n",
424
- " │ │ def solution():⏎\n",
425
- " │ │ \"\"\"If there are 3 cars in the parking lot and 2 more cars arrive, how many cars are in the parking lot?\"\"\"⏎\n",
426
- " │ │ cars_initial = 3⏎\n",
427
- " │ │ cars_arrived = 2⏎\n",
428
- " │ │ total_cars = cars_initial + cars_arrived⏎\n",
429
- " │ │ result = total_cars⏎\n",
430
- " │ │ return result⏎\n",
431
- " │ │ ⏎\n",
432
- " │ │ ⏎\n",
433
- " │ │ ⏎\n",
434
- " │ │ ⏎\n",
435
- " │ │ ⏎\n",
436
- " │ │ Q: There are 15 trees in the grove. Grove workers will plant trees in the grove today. After they are done, there will be 21 trees. How many trees did the grove workers plant today?⏎\n",
437
- " │ │ ⏎\n",
438
- " │ │ # solution in Python:⏎\n",
439
- " │ │ ⏎\n",
440
- " │ │ ⏎\n",
441
- " │ │ def solution():⏎\n",
442
- " │ │ \"\"\"There are 15 trees in the grove. Grove workers will plant trees in the grove today. After they are done, there will be 21 trees. How many trees did the grove workers plant today?\"\"\"⏎\n",
443
- " │ │ trees_initial = 15⏎\n",
444
- " │ │ trees_after = 21⏎\n",
445
- " │ │ trees_added = trees_after - trees_initial⏎\n",
446
- " │ │ result = trees_added⏎\n",
447
- " │ │ return result⏎\n",
448
- " │ │ ⏎\n",
449
- " │ │ ⏎\n",
450
- " │ │ ⏎\n",
451
- " │ │ ⏎\n",
452
- " │ │ ⏎\n",
453
- " │ │ Q: Melanie is a door-to-door saleswoman. She sold a third of her ' 'vacuum cleaners at the green house, 2 more to the red house, and half of ' 'what was left at the orange house. If Melanie has 5 vacuum cleaners left, ' 'how many did she start with?'⏎\n",
454
- " │ │ ⏎\n",
455
- " │ │ # solution in Python:\u001b[0m\n",
456
- " │ └── \u001b[38;5;5mPrompted\u001b[0m/3/2\u001b[0m ⇒ \u001b[38;5;2msucceeded\u001b[0m \u001b[38;5;15m2023-02-27 14:15:54Z\u001b[2m\u001b[0m\n",
457
- " ├── \u001b[38;5;5mResult\u001b[0m/4/1\u001b[0m ⇒ \u001b[38;5;2mstarted\u001b[0m \u001b[38;5;15m2023-02-27 14:15:54Z\u001b[2m\u001b[0m ⧖ \u001b[38;5;4m0.000s\u001b[2m\u001b[0m\n",
458
- " │ ├── \u001b[38;5;4mresult\u001b[0m: ⏎\n",
459
- " │ │ ⏎\n",
460
- " │ │ ⏎\n",
461
- " │ │ def solution():⏎\n",
462
- " │ │ \"\"\"Melanie is a door-to-door saleswoman. She sold a third of her vacuum cleaners at the green house, 2 more to the red house, and half of what was left at the orange house. If Melanie has 5 vacuum cleaners left, how many did she start with?\"\"\"⏎\n",
463
- " │ │ vacuum_cleaners_left = 5⏎\n",
464
- " │ │ vacuum_cleaners_sold_green = vacuum_cleaners_left // 3⏎\n",
465
- " │ │ vacuum_cleaners_sold_red = 2⏎\n",
466
- " │ │ vacuum_cleaners_sold_orange = (vacuum_cleaners_left - vacuum_cleaners_sold_green - vacuum_cleaners_sold_red) // 2⏎\n",
467
- " │ │ vacuum_cleaners_initial = vacuum_cleaners_left + vacuum_cleaners_sold_green + vacuum_cleaners_sold_red + vacuum_cleaners_sold_orange⏎\n",
468
- " │ │ result = vacuum_cleaners_initial⏎\n",
469
- " │ │ return result\u001b[0m\n",
470
- " │ └── \u001b[38;5;5mResult\u001b[0m/4/2\u001b[0m ⇒ \u001b[38;5;2msucceeded\u001b[0m \u001b[38;5;15m2023-02-27 14:15:54Z\u001b[2m\u001b[0m\n",
471
- " └── \u001b[38;5;5m<class '__main__.PalPrompt'>\u001b[0m/5\u001b[0m ⇒ \u001b[38;5;2msucceeded\u001b[0m \u001b[38;5;15m2023-02-27 14:15:54Z\u001b[2m\u001b[0m\n",
472
- "\n",
473
- "\u001b[38;5;15mf2a0c10a-9d37-45b0-af51-bc18b0da6877\u001b[1m\u001b[0m\n",
474
- "└── \u001b[38;5;5m<class '__main__.PyPrompt'>\u001b[0m/1\u001b[0m ⇒ \u001b[38;5;2mstarted\u001b[0m \u001b[38;5;15m2023-02-27 14:15:54Z\u001b[2m\u001b[0m ⧖ \u001b[38;5;4m0.000s\u001b[2m\u001b[0m\n",
475
- " ├── \u001b[38;5;5mInput Function\u001b[0m/2/1\u001b[0m ⇒ \u001b[38;5;2mstarted\u001b[0m \u001b[38;5;15m2023-02-27 14:15:54Z\u001b[2m\u001b[0m ⧖ \u001b[38;5;4m0.000s\u001b[2m\u001b[0m\n",
476
- " │ ├── \u001b[38;5;4minput\u001b[0m: ⏎\n",
477
- " │ │ ⏎\n",
478
- " │ │ ⏎\n",
479
- " │ │ def solution():⏎\n",
480
- " │ │ \"\"\"Melanie is a door-to-door saleswoman. She sold a third of her vacuum cleaners at the green house, 2 more to the red house, and half of what was left at the orange house. If Melanie has 5 vacuum cleaners left, how many did she start with?\"\"\"⏎\n",
481
- " │ │ vacuum_cleaners_left = 5⏎\n",
482
- " │ │ vacuum_cleaners_sold_green = vacuum_cleaners_left // 3⏎\n",
483
- " │ │ vacuum_cleaners_sold_red = 2⏎\n",
484
- " │ │ vacuum_cleaners_sold_orange = (vacuum_cleaners_left - vacuum_cleaners_sold_green - vacuum_cleaners_sold_red) // 2⏎\n",
485
- " │ │ vacuum_cleaners_initial = vacuum_cleaners_left + vacuum_cleaners_sold_green + vacuum_cleaners_sold_red + vacuum_cleaners_sold_orange⏎\n",
486
- " │ │ result = vacuum_cleaners_initial⏎\n",
487
- " │ │ return result\u001b[0m\n",
488
- " │ └── \u001b[38;5;5mInput Function\u001b[0m/2/2\u001b[0m ⇒ \u001b[38;5;2msucceeded\u001b[0m \u001b[38;5;15m2023-02-27 14:15:54Z\u001b[2m\u001b[0m\n",
489
- " ├── \u001b[38;5;5mPrompted\u001b[0m/3/1\u001b[0m ⇒ \u001b[38;5;2mstarted\u001b[0m \u001b[38;5;15m2023-02-27 14:15:54Z\u001b[2m\u001b[0m ⧖ \u001b[38;5;4m0.000s\u001b[2m\u001b[0m\n",
490
- " │ ├── \u001b[38;5;4mprompt\u001b[0m: ⏎\n",
491
- " │ │ ⏎\n",
492
- " │ │ ⏎\n",
493
- " │ │ def solution():⏎\n",
494
- " │ │ \"\"\"Melanie is a door-to-door saleswoman. She sold a third of her vacuum cleaners at the green house, 2 more to the red house, and half of what was left at the orange house. If Melanie has 5 vacuum cleaners left, how many did she start with?\"\"\"⏎\n",
495
- " │ │ vacuum_cleaners_left = 5⏎\n",
496
- " │ │ vacuum_cleaners_sold_green = vacuum_cleaners_left // 3⏎\n",
497
- " │ │ vacuum_cleaners_sold_red = 2⏎\n",
498
- " │ │ vacuum_cleaners_sold_orange = (vacuum_cleaners_left - vacuum_cleaners_sold_green - vacuum_cleaners_sold_red) // 2⏎\n",
499
- " │ │ vacuum_cleaners_initial = vacuum_cleaners_left + vacuum_cleaners_sold_green + vacuum_cleaners_sold_red + vacuum_cleaners_sold_orange⏎\n",
500
- " │ │ result = vacuum_cleaners_initial⏎\n",
501
- " │ │ return result⏎\n",
502
- " │ │ print(solution())\u001b[0m\n",
503
- " │ └── \u001b[38;5;5mPrompted\u001b[0m/3/2\u001b[0m ⇒ \u001b[38;5;2msucceeded\u001b[0m \u001b[38;5;15m2023-02-27 14:15:54Z\u001b[2m\u001b[0m\n",
504
- " ├── \u001b[38;5;5mResult\u001b[0m/4/1\u001b[0m ⇒ \u001b[38;5;2mstarted\u001b[0m \u001b[38;5;15m2023-02-27 14:15:54Z\u001b[2m\u001b[0m ⧖ \u001b[38;5;4m0.000s\u001b[2m\u001b[0m\n",
505
- " │ ├── \u001b[38;5;4mresult\u001b[0m: 9⏎\n",
506
- " │ │ \u001b[0m\n",
507
- " │ └── \u001b[38;5;5mResult\u001b[0m/4/2\u001b[0m ⇒ \u001b[38;5;2msucceeded\u001b[0m \u001b[38;5;15m2023-02-27 14:15:54Z\u001b[2m\u001b[0m\n",
508
- " └── \u001b[38;5;5m<class '__main__.PyPrompt'>\u001b[0m/5\u001b[0m ⇒ \u001b[38;5;2msucceeded\u001b[0m \u001b[38;5;15m2023-02-27 14:15:54Z\u001b[2m\u001b[0m\n",
509
  "\n",
510
- "\u001b[38;5;15m18cad0c1-8de2-4459-af6c-fd8426cdacad\u001b[1m\u001b[0m\n",
511
- "└── \u001b[38;5;5mpal\u001b[0m/1\u001b[0m ⇒ \u001b[38;5;2mstarted\u001b[0m \u001b[38;5;15m2023-02-27 14:15:43Z\u001b[2m\u001b[0m ⧖ \u001b[38;5;4m11.063s\u001b[2m\u001b[0m\n",
512
- " └── \u001b[38;5;5mpal\u001b[0m/2\u001b[0m ⇒ \u001b[38;5;2msucceeded\u001b[0m \u001b[38;5;15m2023-02-27 14:15:54Z\u001b[2m\u001b[0m\n",
513
- "\n"
514
  ]
 
 
 
 
 
 
 
 
 
 
 
 
515
  }
516
  ],
517
  "source": [
518
- "minichain.show_log(\"pal.log\")"
 
519
  ]
520
  }
521
  ],
522
  "metadata": {
523
  "jupytext": {
524
- "cell_metadata_filter": "tags,-all"
525
  },
526
  "kernelspec": {
527
  "display_name": "minichain",
 
1
  {
2
  "cells": [
 
 
 
 
 
 
 
 
3
  {
4
  "cell_type": "code",
5
  "execution_count": 1,
6
+ "id": "c38ce0f6",
7
  "metadata": {
8
  "execution": {
9
+ "iopub.execute_input": "2023-03-22T17:00:50.962288Z",
10
+ "iopub.status.busy": "2023-03-22T17:00:50.961690Z",
11
+ "iopub.status.idle": "2023-03-22T17:00:50.980672Z",
12
+ "shell.execute_reply": "2023-03-22T17:00:50.978710Z"
13
+ }
 
14
  },
15
  "outputs": [],
16
  "source": [
17
+ "desc = \"\"\"\n",
18
+ "### Prompt-aided Language Models\n",
19
+ "\n",
20
+ "Chain for answering complex problems by code generation and execution. [[Code](https://github.com/srush/MiniChain/blob/main/examples/pal.py)]\n",
21
+ "\n",
22
+ "(Adapted from Prompt-aided Language Models [PAL](https://arxiv.org/pdf/2211.10435.pdf)).\n",
23
+ "\"\"\""
24
  ]
25
  },
26
  {
27
  "cell_type": "markdown",
28
+ "id": "feae8a53",
29
  "metadata": {},
30
  "source": [
31
+ "$"
32
  ]
33
  },
34
  {
35
  "cell_type": "code",
36
  "execution_count": 2,
37
+ "id": "50b61935",
38
  "metadata": {
39
  "execution": {
40
+ "iopub.execute_input": "2023-03-22T17:00:50.988390Z",
41
+ "iopub.status.busy": "2023-03-22T17:00:50.987754Z",
42
+ "iopub.status.idle": "2023-03-22T17:00:52.281141Z",
43
+ "shell.execute_reply": "2023-03-22T17:00:52.280472Z"
44
  },
45
  "lines_to_next_cell": 1
46
  },
47
  "outputs": [],
48
  "source": [
49
+ "from minichain import prompt, show, OpenAI, Python"
 
 
 
 
 
 
 
 
 
50
  ]
51
  },
52
  {
53
  "cell_type": "code",
54
  "execution_count": 3,
55
+ "id": "a924b4d1",
56
  "metadata": {
57
  "execution": {
58
+ "iopub.execute_input": "2023-03-22T17:00:52.283783Z",
59
+ "iopub.status.busy": "2023-03-22T17:00:52.283453Z",
60
+ "iopub.status.idle": "2023-03-22T17:00:52.286846Z",
61
+ "shell.execute_reply": "2023-03-22T17:00:52.286410Z"
62
  },
63
  "lines_to_next_cell": 1
64
  },
65
  "outputs": [],
66
  "source": [
67
+ "@prompt(OpenAI(), template_file=\"pal.pmpt.tpl\")\n",
68
+ "def pal_prompt(model, question):\n",
69
+ " return model(dict(question=question))"
 
 
 
70
  ]
71
  },
72
  {
73
+ "cell_type": "code",
74
+ "execution_count": 4,
75
+ "id": "0033b792",
76
+ "metadata": {
77
+ "execution": {
78
+ "iopub.execute_input": "2023-03-22T17:00:52.288978Z",
79
+ "iopub.status.busy": "2023-03-22T17:00:52.288707Z",
80
+ "iopub.status.idle": "2023-03-22T17:00:52.291754Z",
81
+ "shell.execute_reply": "2023-03-22T17:00:52.291315Z"
82
+ },
83
+ "lines_to_next_cell": 1
84
+ },
85
+ "outputs": [],
86
  "source": [
87
+ "@prompt(Python())\n",
88
+ "def python(model, inp):\n",
89
+ " return int(model(inp + \"\\nprint(solution())\"))"
90
  ]
91
  },
92
  {
93
  "cell_type": "code",
94
+ "execution_count": 5,
95
+ "id": "60a5ddf7",
96
  "metadata": {
97
  "execution": {
98
+ "iopub.execute_input": "2023-03-22T17:00:52.294112Z",
99
+ "iopub.status.busy": "2023-03-22T17:00:52.293670Z",
100
+ "iopub.status.idle": "2023-03-22T17:00:52.296744Z",
101
+ "shell.execute_reply": "2023-03-22T17:00:52.296171Z"
102
+ },
103
+ "lines_to_next_cell": 1
104
  },
105
+ "outputs": [],
 
 
 
 
 
 
 
 
106
  "source": [
107
+ "def pal(question):\n",
108
+ " return python(pal_prompt(question))"
 
 
 
 
 
 
109
  ]
110
  },
111
  {
112
  "cell_type": "markdown",
113
+ "id": "c75fead5",
114
  "metadata": {},
115
  "source": [
116
+ "$"
117
  ]
118
  },
119
  {
120
  "cell_type": "code",
121
+ "execution_count": 6,
122
+ "id": "b0d40bd2",
123
  "metadata": {
124
  "execution": {
125
+ "iopub.execute_input": "2023-03-22T17:00:52.298984Z",
126
+ "iopub.status.busy": "2023-03-22T17:00:52.298796Z",
127
+ "iopub.status.idle": "2023-03-22T17:00:52.301777Z",
128
+ "shell.execute_reply": "2023-03-22T17:00:52.301305Z"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
  }
130
+ },
131
+ "outputs": [],
132
  "source": [
133
+ "question = \"Melanie is a door-to-door saleswoman. She sold a third of her \" \\\n",
134
+ " \"vacuum cleaners at the green house, 2 more to the red house, and half of \" \\\n",
135
+ " \"what was left at the orange house. If Melanie has 5 vacuum cleaners left, \" \\\n",
136
+ " \"how many did she start with?\""
137
  ]
138
  },
139
  {
140
  "cell_type": "code",
141
+ "execution_count": 7,
142
+ "id": "3c4485a4",
143
  "metadata": {
144
  "execution": {
145
+ "iopub.execute_input": "2023-03-22T17:00:52.304005Z",
146
+ "iopub.status.busy": "2023-03-22T17:00:52.303713Z",
147
+ "iopub.status.idle": "2023-03-22T17:00:52.573239Z",
148
+ "shell.execute_reply": "2023-03-22T17:00:52.572557Z"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
  }
150
+ },
151
+ "outputs": [],
 
 
 
 
 
 
 
152
  "source": [
153
+ "gradio = show(pal,\n",
154
+ " examples=[question],\n",
155
+ " subprompts=[pal_prompt, python],\n",
156
+ " description=desc,\n",
157
+ " code=open(\"pal.py\", \"r\").read().split(\"$\")[1].strip().strip(\"#\").strip(),\n",
158
+ " )"
159
  ]
160
  },
161
  {
162
  "cell_type": "code",
163
+ "execution_count": 8,
164
+ "id": "a5bebdcc",
165
  "metadata": {
166
  "execution": {
167
+ "iopub.execute_input": "2023-03-22T17:00:52.575840Z",
168
+ "iopub.status.busy": "2023-03-22T17:00:52.575635Z",
169
+ "iopub.status.idle": "2023-03-22T17:00:52.646986Z",
170
+ "shell.execute_reply": "2023-03-22T17:00:52.646403Z"
171
  }
172
  },
173
  "outputs": [
174
  {
175
+ "name": "stdout",
176
  "output_type": "stream",
177
  "text": [
178
+ "Running on local URL: http://127.0.0.1:7861\n",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
  "\n",
180
+ "To create a public link, set `share=True` in `launch()`.\n"
 
 
 
181
  ]
182
+ },
183
+ {
184
+ "data": {
185
+ "text/html": [
186
+ "<div><iframe src=\"http://127.0.0.1:7861/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
187
+ ],
188
+ "text/plain": [
189
+ "<IPython.core.display.HTML object>"
190
+ ]
191
+ },
192
+ "metadata": {},
193
+ "output_type": "display_data"
194
  }
195
  ],
196
  "source": [
197
+ "if __name__ == \"__main__\":\n",
198
+ " gradio.launch()"
199
  ]
200
  }
201
  ],
202
  "metadata": {
203
  "jupytext": {
204
+ "cell_metadata_filter": "-all"
205
  },
206
  "kernelspec": {
207
  "display_name": "minichain",
pal.py CHANGED
@@ -8,56 +8,32 @@ Chain for answering complex problems by code generation and execution. [[Code](h
8
 
9
  # $
10
 
11
- import minichain
12
 
13
- # PAL Prompt
 
 
14
 
15
- class PalPrompt(minichain.TemplatePrompt):
16
- template_file = "pal.pmpt.tpl"
 
17
 
18
- # Prompt to run and print python code.
 
19
 
20
- class PyPrompt(minichain.Prompt):
21
- def prompt(self, inp):
22
- return inp + "\nprint(solution())"
23
-
24
- def parse(self, response, inp):
25
- return int(response)
26
-
27
- # Chain the prompts.
28
-
29
- with minichain.start_chain("pal") as backend:
30
- prompt = PalPrompt(backend.OpenAI()).chain(PyPrompt(backend.Python()))
31
-
32
  # $
33
-
34
  question = "Melanie is a door-to-door saleswoman. She sold a third of her " \
35
  "vacuum cleaners at the green house, 2 more to the red house, and half of " \
36
  "what was left at the orange house. If Melanie has 5 vacuum cleaners left, " \
37
  "how many did she start with?"
38
-
39
- gradio = prompt.to_gradio(fields =["question"],
40
- examples=[question],
41
- description=desc,
42
- code=open("pal.py", "r").read().split("$")[1].strip().strip("#").strip(),
43
- templates=[open("pal.pmpt.tpl")]
44
- )
45
- if __name__ == "__main__":
46
- gradio.launch()
47
 
48
- # View prompt examples.
 
 
 
 
 
49
 
50
- # # + tags=["hide_inp"]
51
- # PalPrompt().show(
52
- # {"question": "Joe has 10 cars and Bobby has 12. How many do they have together?"},
53
- # "def solution():\n\treturn 10 + 12",
54
- # )
55
- # # -
56
-
57
- # # + tags=["hide_inp"]
58
- # PyPrompt().show("def solution():\n\treturn 10 + 12", "22")
59
- # # -
60
-
61
- # # View the log.
62
-
63
- # minichain.show_log("pal.log")
 
8
 
9
  # $
10
 
11
+ from minichain import prompt, show, OpenAI, Python
12
 
13
+ @prompt(OpenAI(), template_file="pal.pmpt.tpl")
14
+ def pal_prompt(model, question):
15
+ return model(dict(question=question))
16
 
17
+ @prompt(Python())
18
+ def python(model, inp):
19
+ return int(model(inp + "\nprint(solution())"))
20
 
21
+ def pal(question):
22
+ return python(pal_prompt(question))
23
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  # $
25
+
26
  question = "Melanie is a door-to-door saleswoman. She sold a third of her " \
27
  "vacuum cleaners at the green house, 2 more to the red house, and half of " \
28
  "what was left at the orange house. If Melanie has 5 vacuum cleaners left, " \
29
  "how many did she start with?"
 
 
 
 
 
 
 
 
 
30
 
31
+ gradio = show(pal,
32
+ examples=[question],
33
+ subprompts=[pal_prompt, python],
34
+ description=desc,
35
+ code=open("pal.py", "r").read().split("$")[1].strip().strip("#").strip(),
36
+ )
37
 
38
+ if __name__ == "__main__":
39
+ gradio.launch()
 
 
 
 
 
 
 
 
 
 
 
 
qa.ipynb CHANGED
The diff for this file is too large to render. See raw diff
 
qa.log CHANGED
@@ -1,10 +1,8 @@
1
- {"action_status": "started", "timestamp": 1678804794.7338963, "task_uuid": "dc9993f0-9c8a-42a8-8f7e-bc4b40be1a1e", "action_type": "qa", "task_level": [1]}
2
- {"action_status": "succeeded", "timestamp": 1678804794.7341123, "task_uuid": "dc9993f0-9c8a-42a8-8f7e-bc4b40be1a1e", "action_type": "qa", "task_level": [2]}
3
- {"action_status": "started", "timestamp": 1678804794.8375309, "task_uuid": "dd1251af-7770-460d-ac61-85db28fd24df", "action_type": "stats", "task_level": [1]}
4
- {"action_status": "succeeded", "timestamp": 1678804794.8376832, "task_uuid": "dd1251af-7770-460d-ac61-85db28fd24df", "action_type": "stats", "task_level": [2]}
5
- {"action_status": "started", "timestamp": 1678804807.8764367, "task_uuid": "3130f0e2-8d6f-4992-9e12-8f90e9aa96c4", "action_type": "<class 'math_demo.MathPrompt'>", "task_level": [1]}
6
- {"input": {"question": "What is the sum of the powers of 3 (3^i) that are smaller than 100?"}, "action_status": "started", "timestamp": 1678804807.876612, "task_uuid": "3130f0e2-8d6f-4992-9e12-8f90e9aa96c4", "action_type": "Input Function", "task_level": [2, 1]}
7
- {"action_status": "succeeded", "timestamp": 1678804807.8774285, "task_uuid": "3130f0e2-8d6f-4992-9e12-8f90e9aa96c4", "action_type": "Input Function", "task_level": [2, 2]}
8
- {"prompt": "#### Question:\n\n* What is 37593 * 67?\n\n#### Code:\n\n```python\nprint(37593 * 67)\n```\n\n#### Question:\n\n* Janet's ducks lay 16 eggs per day. She eats three for breakfast every morning and bakes muffins for her friends every day with four. She sells the remainder at the farmers' market daily for $2 per fresh duck egg. How much in dollars does she make every day at the farmers' market?\n\n#### Code:\n\n```python\nprint((16-3-4)*2)\n```\n\n#### Question:\n\n* How many of the integers between 0 and 99 inclusive are divisible by 8?\n\n#### Code:\n\n```python\ncount = 0\nfor i in range(0, 99+1):\n if i % 8 == 0: count += 1\nprint(count)\n```\n\n#### Question:\n\n* A robe takes 2 bolts of blue fiber and half that much white fiber. How many bolts in total does it take?\n\n#### Code:\n\n```python\nprint(2 + 2/2)\n```\n\n#### Question:\n\n* What is the sum of the powers of 3 (3^i) that are smaller than 100?\n\n#### Code:", "action_status": "started", "timestamp": 1678804807.877532, "task_uuid": "3130f0e2-8d6f-4992-9e12-8f90e9aa96c4", "action_type": "Prompted", "task_level": [3, 1]}
9
- {"exception": "builtins.AssertionError", "reason": "Need an OPENAI_KEY. Get one here https://openai.com/api/", "action_status": "failed", "timestamp": 1678804807.8874092, "task_uuid": "3130f0e2-8d6f-4992-9e12-8f90e9aa96c4", "action_type": "Prompted", "task_level": [3, 2]}
10
- {"exception": "builtins.AssertionError", "reason": "Need an OPENAI_KEY. Get one here https://openai.com/api/", "action_status": "failed", "timestamp": 1678804807.8875778, "task_uuid": "3130f0e2-8d6f-4992-9e12-8f90e9aa96c4", "action_type": "<class 'math_demo.MathPrompt'>", "task_level": [4]}
 
1
+ {"action_status": "started", "timestamp": 1679155951.6284053, "task_uuid": "1145ccf3-d2cd-4c63-acea-8c3131442596", "action_type": "qa", "task_level": [1]}
2
+ {"action_status": "succeeded", "timestamp": 1679155951.6284745, "task_uuid": "1145ccf3-d2cd-4c63-acea-8c3131442596", "action_type": "qa", "task_level": [2]}
3
+ {"action_status": "started", "timestamp": 1679155957.2591064, "task_uuid": "b2e93b45-c99c-4cb4-8280-53873547c18e", "action_type": "<class '__main__.KNNPrompt'>", "task_level": [1]}
4
+ {"input": {"query": "What is the total number of medals won by France?"}, "action_status": "started", "timestamp": 1679155957.2591872, "task_uuid": "b2e93b45-c99c-4cb4-8280-53873547c18e", "action_type": "Input Function", "task_level": [2, 1]}
5
+ {"action_status": "succeeded", "timestamp": 1679155957.2592237, "task_uuid": "b2e93b45-c99c-4cb4-8280-53873547c18e", "action_type": "Input Function", "task_level": [2, 2]}
6
+ {"prompt": "{'query': 'What is the total number of medals won by France?'}", "action_status": "started", "timestamp": 1679155957.2592478, "task_uuid": "b2e93b45-c99c-4cb4-8280-53873547c18e", "action_type": "Prompted", "task_level": [3, 1]}
7
+ {"exception": "builtins.AssertionError", "reason": "Need an OPENAI_KEY. Get one here https://openai.com/api/", "action_status": "failed", "timestamp": 1679155957.2703598, "task_uuid": "b2e93b45-c99c-4cb4-8280-53873547c18e", "action_type": "Prompted", "task_level": [3, 2]}
8
+ {"exception": "builtins.AssertionError", "reason": "Need an OPENAI_KEY. Get one here https://openai.com/api/", "action_status": "failed", "timestamp": 1679155957.2704325, "task_uuid": "b2e93b45-c99c-4cb4-8280-53873547c18e", "action_type": "<class '__main__.KNNPrompt'>", "task_level": [4]}
 
 
qa.pmpt.tpl CHANGED
@@ -8,5 +8,5 @@ Context:
8
 
9
  Q: {{question}}
10
 
11
- A:
12
 
 
8
 
9
  Q: {{question}}
10
 
11
+ A:
12
 
qa.py CHANGED
@@ -12,7 +12,8 @@ Chain that answers questions with embeedding based retrieval. [[Code](https://gi
12
 
13
  import datasets
14
  import numpy as np
15
- from minichain import EmbeddingPrompt, TemplatePrompt, show_log, start_chain
 
16
 
17
  # We use Hugging Face Datasets as the database by assigning
18
  # a FAISS index.
@@ -23,37 +24,36 @@ olympics.add_faiss_index("embeddings")
23
 
24
  # Fast KNN retieval prompt
25
 
 
 
 
 
 
26
 
27
- class KNNPrompt(EmbeddingPrompt):
28
- def find(self, out, inp):
29
- res = olympics.get_nearest_examples("embeddings", np.array(out), 3)
30
- return {"question": inp, "docs": res.examples["content"]}
31
 
32
-
33
- # QA prompt to ask question with examples
34
-
35
- class QAPrompt(TemplatePrompt):
36
- template_file = "qa.pmpt.tpl"
37
-
38
-
39
- with start_chain("qa") as backend:
40
- prompt = KNNPrompt(backend.OpenAIEmbed()).chain(QAPrompt(backend.OpenAI()))
41
 
42
  # $
43
 
44
-
45
  questions = ["Who won the 2020 Summer Olympics men's high jump?",
46
  "Why was the 2020 Summer Olympics originally postponed?",
47
  "In the 2020 Summer Olympics, how many gold medals did the country which won the most medals win?",
48
  "What is the total number of medals won by France?",
49
  "What is the tallest mountain in the world?"]
50
 
51
- gradio = prompt.to_gradio(fields=["query"],
52
- examples=questions,
53
- description=desc,
54
- code=open("qa.py", "r").read().split("$")[1].strip().strip("#").strip(),
55
- templates=[open("qa.pmpt.tpl")]
56
- )
57
  if __name__ == "__main__":
58
  gradio.launch()
59
 
 
12
 
13
  import datasets
14
  import numpy as np
15
+ from minichain import prompt, show, OpenAIEmbed, OpenAI
16
+ from manifest import Manifest
17
 
18
  # We use Hugging Face Datasets as the database by assigning
19
  # a FAISS index.
 
24
 
25
  # Fast KNN retieval prompt
26
 
27
+ @prompt(OpenAIEmbed())
28
+ def get_neighbors(model, inp, k):
29
+ embedding = model(inp)
30
+ res = olympics.get_nearest_examples("embeddings", np.array(embedding), k)
31
+ return res.examples["content"]
32
 
33
+ @prompt(OpenAI(),
34
+ template_file="qa.pmpt.tpl")
35
+ def get_result(model, query, neighbors):
36
+ return model(dict(question=query, docs=neighbors))
37
 
38
+ def qa(query):
39
+ n = get_neighbors(query, 3)
40
+ return get_result(query, n)
 
 
 
 
 
 
41
 
42
  # $
43
 
44
+
45
  questions = ["Who won the 2020 Summer Olympics men's high jump?",
46
  "Why was the 2020 Summer Olympics originally postponed?",
47
  "In the 2020 Summer Olympics, how many gold medals did the country which won the most medals win?",
48
  "What is the total number of medals won by France?",
49
  "What is the tallest mountain in the world?"]
50
 
51
+ gradio = show(qa,
52
+ examples=questions,
53
+ subprompts=[get_neighbors, get_result],
54
+ description=desc,
55
+ code=open("qa.py", "r").read().split("$")[1].strip().strip("#").strip(),
56
+ )
57
  if __name__ == "__main__":
58
  gradio.launch()
59
 
selfask.ipynb CHANGED
@@ -1,188 +1,180 @@
1
  {
2
  "cells": [
3
  {
4
- "cell_type": "markdown",
5
- "id": "75955211",
6
- "metadata": {},
7
- "source": [
8
- "Notebook implementation of the self-ask + Google tool use prompt.\n",
9
- "Adapted from https://github.com/ofirpress/self-ask"
10
- ]
 
11
  },
12
  {
13
  "cell_type": "code",
14
  "execution_count": 1,
15
- "id": "169ca46b",
16
  "metadata": {
17
  "execution": {
18
- "iopub.execute_input": "2023-02-27T14:18:09.920122Z",
19
- "iopub.status.busy": "2023-02-27T14:18:09.919101Z",
20
- "iopub.status.idle": "2023-02-27T14:18:10.134246Z",
21
- "shell.execute_reply": "2023-02-27T14:18:10.133531Z"
22
  }
23
  },
24
  "outputs": [],
25
  "source": [
26
- "from dataclasses import dataclass\n",
27
- "from parsita import *\n",
28
- "import minichain"
 
 
 
 
29
  ]
30
  },
31
  {
32
  "cell_type": "markdown",
33
- "id": "2fe40b57",
34
  "metadata": {},
35
  "source": [
36
- "Define the state of the bot."
37
  ]
38
  },
39
  {
40
  "cell_type": "code",
41
  "execution_count": 2,
42
- "id": "8ddc7e21",
43
  "metadata": {
44
  "execution": {
45
- "iopub.execute_input": "2023-02-27T14:18:10.138241Z",
46
- "iopub.status.busy": "2023-02-27T14:18:10.137766Z",
47
- "iopub.status.idle": "2023-02-27T14:18:10.142368Z",
48
- "shell.execute_reply": "2023-02-27T14:18:10.141610Z"
49
- },
50
- "lines_to_next_cell": 1
51
  },
52
  "outputs": [],
53
  "source": [
54
- "@dataclass\n",
55
- "class IntermediateState:\n",
56
- " s: str"
57
  ]
58
  },
59
  {
60
  "cell_type": "code",
61
  "execution_count": 3,
62
- "id": "54712784",
63
  "metadata": {
64
  "execution": {
65
- "iopub.execute_input": "2023-02-27T14:18:10.147601Z",
66
- "iopub.status.busy": "2023-02-27T14:18:10.146906Z",
67
- "iopub.status.idle": "2023-02-27T14:18:10.151336Z",
68
- "shell.execute_reply": "2023-02-27T14:18:10.150687Z"
69
- },
70
- "lines_to_next_cell": 1
71
  },
72
  "outputs": [],
73
  "source": [
74
  "@dataclass\n",
75
- "class FinalState:\n",
76
- " s: str"
 
 
 
77
  ]
78
  },
79
  {
80
  "cell_type": "code",
81
  "execution_count": 4,
82
- "id": "73090cad",
83
  "metadata": {
84
  "execution": {
85
- "iopub.execute_input": "2023-02-27T14:18:10.154745Z",
86
- "iopub.status.busy": "2023-02-27T14:18:10.154227Z",
87
- "iopub.status.idle": "2023-02-27T14:18:10.159429Z",
88
- "shell.execute_reply": "2023-02-27T14:18:10.158706Z"
89
- }
 
90
  },
91
  "outputs": [],
92
  "source": [
93
- "@dataclass\n",
94
- "class Out:\n",
95
- " echo: str\n",
96
- " state: FinalState | IntermediateState"
97
- ]
98
- },
99
- {
100
- "cell_type": "markdown",
101
- "id": "32806a89",
102
- "metadata": {},
103
- "source": [
104
- "Self Ask Prompt"
105
  ]
106
  },
107
  {
108
  "cell_type": "code",
109
  "execution_count": 5,
110
- "id": "df10486c",
111
  "metadata": {
112
  "execution": {
113
- "iopub.execute_input": "2023-02-27T14:18:10.163227Z",
114
- "iopub.status.busy": "2023-02-27T14:18:10.162804Z",
115
- "iopub.status.idle": "2023-02-27T14:18:10.169291Z",
116
- "shell.execute_reply": "2023-02-27T14:18:10.168542Z"
117
  },
118
  "lines_to_next_cell": 1
119
  },
120
  "outputs": [],
121
  "source": [
122
- "class SelfAsk(minichain.TemplatePrompt[Out]):\n",
123
- " template_file = \"selfask.pmpt.tpl\"\n",
124
- " stop_template = \"\\nIntermediate answer:\"\n",
125
- "\n",
126
- " # Parsita parser.\n",
127
- " class Parser(TextParsers):\n",
128
- " follow = (lit(\"Follow up:\") >> reg(r\".*\")) > IntermediateState\n",
129
- " finish = (lit(\"So the final answer is: \") >> reg(r\".*\")) > FinalState\n",
130
- " response = follow | finish\n",
131
- "\n",
132
- " def parse(self, response: str, inp) -> Out:\n",
133
- " return Out(\n",
134
- " self.prompt(inp).prompt + response,\n",
135
- " self.Parser.response.parse(response).or_die(),\n",
136
- " )"
137
- ]
138
- },
139
- {
140
- "cell_type": "markdown",
141
- "id": "dc1d64e4",
142
- "metadata": {},
143
- "source": [
144
- "Runtime loop"
145
  ]
146
  },
147
  {
148
  "cell_type": "code",
149
  "execution_count": 6,
150
- "id": "4e6cbde7",
151
  "metadata": {
152
  "execution": {
153
- "iopub.execute_input": "2023-02-27T14:18:10.173090Z",
154
- "iopub.status.busy": "2023-02-27T14:18:10.172615Z",
155
- "iopub.status.idle": "2023-02-27T14:18:10.177647Z",
156
- "shell.execute_reply": "2023-02-27T14:18:10.177069Z"
157
- }
 
158
  },
159
  "outputs": [],
160
  "source": [
161
- "def selfask(inp: str, openai, google) -> str:\n",
162
- " prompt1 = SelfAsk(openai)\n",
163
- " prompt2 = minichain.SimplePrompt(google)\n",
164
- " suffix = \"\"\n",
165
  " for i in range(3):\n",
166
- " out = prompt1(dict(input=inp, suffix=suffix, agent_scratchpad=True))\n",
167
- "\n",
168
- " if isinstance(out.state, FinalState):\n",
169
- " break\n",
170
- " suffix += out.echo\n",
171
- " out2 = prompt2(out.state.s)\n",
172
- " suffix += \"\\nIntermediate answer: \" + out2 + \"\\n\"\n",
173
- " return out.state.s"
 
 
 
174
  ]
175
  },
176
  {
177
  "cell_type": "code",
178
  "execution_count": 7,
179
- "id": "3c63885f",
180
  "metadata": {
181
  "execution": {
182
- "iopub.execute_input": "2023-02-27T14:18:10.180368Z",
183
- "iopub.status.busy": "2023-02-27T14:18:10.180071Z",
184
- "iopub.status.idle": "2023-02-27T14:18:28.393212Z",
185
- "shell.execute_reply": "2023-02-27T14:18:28.390894Z"
186
  }
187
  },
188
  "outputs": [
@@ -190,664 +182,48 @@
190
  "name": "stdout",
191
  "output_type": "stream",
192
  "text": [
193
- "https://serpapi.com/search\n"
194
- ]
195
- },
196
- {
197
- "name": "stdout",
198
- "output_type": "stream",
199
- "text": [
200
- "https://serpapi.com/search\n"
201
  ]
202
  },
203
- {
204
- "name": "stdout",
205
- "output_type": "stream",
206
- "text": [
207
- "22443, 22520, 22469, 22488, 22442, 22524, 22529, 22558\n"
208
- ]
209
- }
210
- ],
211
- "source": [
212
- "with minichain.start_chain(\"selfask\") as backend:\n",
213
- " result = selfask(\n",
214
- " \"What is the zip code of the city where George Washington was born?\",\n",
215
- " backend.OpenAI(),\n",
216
- " backend.Google(),\n",
217
- " )\n",
218
- " print(result)"
219
- ]
220
- },
221
- {
222
- "cell_type": "markdown",
223
- "id": "05aacb6b",
224
- "metadata": {},
225
- "source": [
226
- "View prompt examples."
227
- ]
228
- },
229
- {
230
- "cell_type": "code",
231
- "execution_count": 8,
232
- "id": "a32b72d9",
233
- "metadata": {
234
- "execution": {
235
- "iopub.execute_input": "2023-02-27T14:18:28.402802Z",
236
- "iopub.status.busy": "2023-02-27T14:18:28.401742Z",
237
- "iopub.status.idle": "2023-02-27T14:18:28.460279Z",
238
- "shell.execute_reply": "2023-02-27T14:18:28.459814Z"
239
- },
240
- "tags": [
241
- "hide_inp"
242
- ]
243
- },
244
- "outputs": [
245
  {
246
  "data": {
247
  "text/html": [
248
- "\n",
249
- "<!-- <link rel=\"stylesheet\" href=\"https://cdn.rawgit.com/Chalarangelo/mini.css/v3.0.1/dist/mini-default.min.css\"> -->\n",
250
- " <main class=\"container\">\n",
251
- "\n",
252
- "<h3>SelfAsk</h3>\n",
253
- "\n",
254
- "<dl>\n",
255
- " <dt>Input:</dt>\n",
256
- " <dd>\n",
257
- "<div class=\"highlight\"><pre><span></span><span class=\"p\">{</span><span class=\"s1\">&#39;input&#39;</span><span class=\"p\">:</span> <span class=\"s1\">&#39;What is the zip code of the city where George Washington was born?&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;agent_scratchpad&#39;</span><span class=\"p\">:</span> <span class=\"kc\">True</span><span class=\"p\">}</span>\n",
258
- "</pre></div>\n",
259
- "\n",
260
- "\n",
261
- " </dd>\n",
262
- "\n",
263
- " <dt> Full Prompt: </dt>\n",
264
- " <dd>\n",
265
- " <details>\n",
266
- " <summary>Prompt</summary>\n",
267
- " <p>Question: Who lived longer, Muhammad Ali or Alan Turing?<br>Are follow up questions needed here: Yes.<br>Follow up: How old was Muhammad Ali when he died?<br>Intermediate answer: Muhammad Ali was 74 years old when he died.<br>Follow up: How old was Alan Turing when he died?<br>Intermediate answer: Alan Turing was 41 years old when he died.<br>So the final answer is: Muhammad Ali<br><br>Question: When was the founder of craigslist born?<br>Are follow up questions needed here: Yes.<br>Follow up: Who was the founder of craigslist?<br>Intermediate answer: Craigslist was founded by Craig Newmark.<br>Follow up: When was Craig Newmark born?<br>Intermediate answer: Craig Newmark was born on December 6, 1952.<br>So the final answer is: December 6, 1952<br><br>Question: Who was the maternal grandfather of George Washington?<br>Are follow up questions needed here: Yes.<br>Follow up: Who was the mother of George Washington?<br>Intermediate answer: The mother of George Washington was Mary Ball Washington.<br>Follow up: Who was the father of Mary Ball Washington?<br>Intermediate answer: The father of Mary Ball Washington was Joseph Ball.<br>So the final answer is: Joseph Ball<br><br>Question: Are both the directors of Jaws and Casino Royale from the same country?<br>Are follow up questions needed here: Yes.<br>Follow up: Who is the director of Jaws?<br>Intermediate answer: The director of Jaws is Steven Spielberg.<br>Follow up: Where is Steven Spielberg from?<br>Intermediate answer: The United States.<br>Follow up: Who is the director of Casino Royale?<br>Intermediate answer: The director of Casino Royale is Martin Campbell.<br>Follow up: Where is Martin Campbell from?<br>Intermediate answer: New Zealand.<br>So the final answer is: No<br><br>Question: <div style='color:red'>What is the zip code of the city where George Washington was born?</div><br>Are followup questions needed here: Yes.<br></p>\n",
268
- " </details>\n",
269
- " </dd>\n",
270
- "\n",
271
- " <dt> Response: </dt>\n",
272
- " <dd>\n",
273
- " Follow up: Where was George Washington born?\n",
274
- " </dd>\n",
275
- "\n",
276
- " <dt>Value:</dt>\n",
277
- " <dd>\n",
278
- "<div class=\"highlight\"><pre><span></span><span class=\"n\">Out</span><span class=\"p\">(</span><span class=\"n\">echo</span><span class=\"o\">=</span><span class=\"s1\">&#39;Question: Who lived longer, Muhammad Ali or Alan Turing?</span><span class=\"se\">\\n</span><span class=\"s1\">Are follow up questions needed here: Yes.</span><span class=\"se\">\\n</span><span class=\"s1\">Follow up: How old was Muhammad Ali when he died?</span><span class=\"se\">\\n</span><span class=\"s1\">Intermediate answer: Muhammad Ali was 74 years old when he died.</span><span class=\"se\">\\n</span><span class=\"s1\">Follow up: How old was Alan Turing when he died?</span><span class=\"se\">\\n</span><span class=\"s1\">Intermediate answer: Alan Turing was 41 years old when he died.</span><span class=\"se\">\\n</span><span class=\"s1\">So the final answer is: Muhammad Ali</span><span class=\"se\">\\n\\n</span><span class=\"s1\">Question: When was the founder of craigslist born?</span><span class=\"se\">\\n</span><span class=\"s1\">Are follow up questions needed here: Yes.</span><span class=\"se\">\\n</span><span class=\"s1\">Follow up: Who was the founder of craigslist?</span><span class=\"se\">\\n</span><span class=\"s1\">Intermediate answer: Craigslist was founded by Craig Newmark.</span><span class=\"se\">\\n</span><span class=\"s1\">Follow up: When was Craig Newmark born?</span><span class=\"se\">\\n</span><span class=\"s1\">Intermediate answer: Craig Newmark was born on December 6, 1952.</span><span class=\"se\">\\n</span><span class=\"s1\">So the final answer is: December 6, 1952</span><span class=\"se\">\\n\\n</span><span class=\"s1\">Question: Who was the maternal grandfather of George Washington?</span><span class=\"se\">\\n</span><span class=\"s1\">Are follow up questions needed here: Yes.</span><span class=\"se\">\\n</span><span class=\"s1\">Follow up: Who was the mother of George Washington?</span><span class=\"se\">\\n</span><span class=\"s1\">Intermediate answer: The mother of George Washington was Mary Ball Washington.</span><span class=\"se\">\\n</span><span class=\"s1\">Follow up: Who was the father of Mary Ball Washington?</span><span class=\"se\">\\n</span><span class=\"s1\">Intermediate answer: The father of Mary Ball Washington was Joseph Ball.</span><span class=\"se\">\\n</span><span class=\"s1\">So the final answer is: Joseph Ball</span><span class=\"se\">\\n\\n</span><span class=\"s1\">Question: Are both the directors of Jaws and Casino Royale from the same country?</span><span class=\"se\">\\n</span><span class=\"s1\">Are follow up questions needed here: Yes.</span><span class=\"se\">\\n</span><span class=\"s1\">Follow up: Who is the director of Jaws?</span><span class=\"se\">\\n</span><span class=\"s1\">Intermediate answer: The director of Jaws is Steven Spielberg.</span><span class=\"se\">\\n</span><span class=\"s1\">Follow up: Where is Steven Spielberg from?</span><span class=\"se\">\\n</span><span class=\"s1\">Intermediate answer: The United States.</span><span class=\"se\">\\n</span><span class=\"s1\">Follow up: Who is the director of Casino Royale?</span><span class=\"se\">\\n</span><span class=\"s1\">Intermediate answer: The director of Casino Royale is Martin Campbell.</span><span class=\"se\">\\n</span><span class=\"s1\">Follow up: Where is Martin Campbell from?</span><span class=\"se\">\\n</span><span class=\"s1\">Intermediate answer: New Zealand.</span><span class=\"se\">\\n</span><span class=\"s1\">So the final answer is: No</span><span class=\"se\">\\n\\n</span><span class=\"s1\">Question: What is the zip code of the city where George Washington was born?</span><span class=\"se\">\\n</span><span class=\"s1\">Are followup questions needed here: Yes.</span><span class=\"se\">\\n</span><span class=\"s1\">Follow up: Where was George Washington born?&#39;</span><span class=\"p\">,</span> <span class=\"n\">state</span><span class=\"o\">=</span><span class=\"n\">IntermediateState</span><span class=\"p\">(</span><span class=\"n\">s</span><span class=\"o\">=</span><span class=\"s1\">&#39;Where was George Washington born?&#39;</span><span class=\"p\">))</span>\n",
279
- "</pre></div>\n",
280
- "\n",
281
- " </dd>\n",
282
- "</main>\n"
283
  ],
284
  "text/plain": [
285
- "HTML(html='\\n<!-- <link rel=\"stylesheet\" href=\"https://cdn.rawgit.com/Chalarangelo/mini.css/v3.0.1/dist/mini-default.min.css\"> -->\\n <main class=\"container\">\\n\\n<h3>SelfAsk</h3>\\n\\n<dl>\\n <dt>Input:</dt>\\n <dd>\\n<div class=\"highlight\"><pre><span></span><span class=\"p\">{</span><span class=\"s1\">&#39;input&#39;</span><span class=\"p\">:</span> <span class=\"s1\">&#39;What is the zip code of the city where George Washington was born?&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;agent_scratchpad&#39;</span><span class=\"p\">:</span> <span class=\"kc\">True</span><span class=\"p\">}</span>\\n</pre></div>\\n\\n\\n </dd>\\n\\n <dt> Full Prompt: </dt>\\n <dd>\\n <details>\\n <summary>Prompt</summary>\\n <p>Question: Who lived longer, Muhammad Ali or Alan Turing?<br>Are follow up questions needed here: Yes.<br>Follow up: How old was Muhammad Ali when he died?<br>Intermediate answer: Muhammad Ali was 74 years old when he died.<br>Follow up: How old was Alan Turing when he died?<br>Intermediate answer: Alan Turing was 41 years old when he died.<br>So the final answer is: Muhammad Ali<br><br>Question: When was the founder of craigslist born?<br>Are follow up questions needed here: Yes.<br>Follow up: Who was the founder of craigslist?<br>Intermediate answer: Craigslist was founded by Craig Newmark.<br>Follow up: When was Craig Newmark born?<br>Intermediate answer: Craig Newmark was born on December 6, 1952.<br>So the final answer is: December 6, 1952<br><br>Question: Who was the maternal grandfather of George Washington?<br>Are follow up questions needed here: Yes.<br>Follow up: Who was the mother of George Washington?<br>Intermediate answer: The mother of George Washington was Mary Ball Washington.<br>Follow up: Who was the father of Mary Ball Washington?<br>Intermediate answer: The father of Mary Ball Washington was Joseph Ball.<br>So the final answer is: Joseph Ball<br><br>Question: Are both the directors of Jaws and Casino Royale from the same country?<br>Are follow up questions needed here: Yes.<br>Follow up: Who is the director of Jaws?<br>Intermediate answer: The director of Jaws is Steven Spielberg.<br>Follow up: Where is Steven Spielberg from?<br>Intermediate answer: The United States.<br>Follow up: Who is the director of Casino Royale?<br>Intermediate answer: The director of Casino Royale is Martin Campbell.<br>Follow up: Where is Martin Campbell from?<br>Intermediate answer: New Zealand.<br>So the final answer is: No<br><br>Question: <div style=\\'color:red\\'>What is the zip code of the city where George Washington was born?</div><br>Are followup questions needed here: Yes.<br></p>\\n </details>\\n </dd>\\n\\n <dt> Response: </dt>\\n <dd>\\n Follow up: Where was George Washington born?\\n </dd>\\n\\n <dt>Value:</dt>\\n <dd>\\n<div class=\"highlight\"><pre><span></span><span class=\"n\">Out</span><span class=\"p\">(</span><span class=\"n\">echo</span><span class=\"o\">=</span><span class=\"s1\">&#39;Question: Who lived longer, Muhammad Ali or Alan Turing?</span><span class=\"se\">\\\\n</span><span class=\"s1\">Are follow up questions needed here: Yes.</span><span class=\"se\">\\\\n</span><span class=\"s1\">Follow up: How old was Muhammad Ali when he died?</span><span class=\"se\">\\\\n</span><span class=\"s1\">Intermediate answer: Muhammad Ali was 74 years old when he died.</span><span class=\"se\">\\\\n</span><span class=\"s1\">Follow up: How old was Alan Turing when he died?</span><span class=\"se\">\\\\n</span><span class=\"s1\">Intermediate answer: Alan Turing was 41 years old when he died.</span><span class=\"se\">\\\\n</span><span class=\"s1\">So the final answer is: Muhammad Ali</span><span class=\"se\">\\\\n\\\\n</span><span class=\"s1\">Question: When was the founder of craigslist born?</span><span class=\"se\">\\\\n</span><span class=\"s1\">Are follow up questions needed here: Yes.</span><span class=\"se\">\\\\n</span><span class=\"s1\">Follow up: Who was the founder of craigslist?</span><span class=\"se\">\\\\n</span><span class=\"s1\">Intermediate answer: Craigslist was founded by Craig Newmark.</span><span class=\"se\">\\\\n</span><span class=\"s1\">Follow up: When was Craig Newmark born?</span><span class=\"se\">\\\\n</span><span class=\"s1\">Intermediate answer: Craig Newmark was born on December 6, 1952.</span><span class=\"se\">\\\\n</span><span class=\"s1\">So the final answer is: December 6, 1952</span><span class=\"se\">\\\\n\\\\n</span><span class=\"s1\">Question: Who was the maternal grandfather of George Washington?</span><span class=\"se\">\\\\n</span><span class=\"s1\">Are follow up questions needed here: Yes.</span><span class=\"se\">\\\\n</span><span class=\"s1\">Follow up: Who was the mother of George Washington?</span><span class=\"se\">\\\\n</span><span class=\"s1\">Intermediate answer: The mother of George Washington was Mary Ball Washington.</span><span class=\"se\">\\\\n</span><span class=\"s1\">Follow up: Who was the father of Mary Ball Washington?</span><span class=\"se\">\\\\n</span><span class=\"s1\">Intermediate answer: The father of Mary Ball Washington was Joseph Ball.</span><span class=\"se\">\\\\n</span><span class=\"s1\">So the final answer is: Joseph Ball</span><span class=\"se\">\\\\n\\\\n</span><span class=\"s1\">Question: Are both the directors of Jaws and Casino Royale from the same country?</span><span class=\"se\">\\\\n</span><span class=\"s1\">Are follow up questions needed here: Yes.</span><span class=\"se\">\\\\n</span><span class=\"s1\">Follow up: Who is the director of Jaws?</span><span class=\"se\">\\\\n</span><span class=\"s1\">Intermediate answer: The director of Jaws is Steven Spielberg.</span><span class=\"se\">\\\\n</span><span class=\"s1\">Follow up: Where is Steven Spielberg from?</span><span class=\"se\">\\\\n</span><span class=\"s1\">Intermediate answer: The United States.</span><span class=\"se\">\\\\n</span><span class=\"s1\">Follow up: Who is the director of Casino Royale?</span><span class=\"se\">\\\\n</span><span class=\"s1\">Intermediate answer: The director of Casino Royale is Martin Campbell.</span><span class=\"se\">\\\\n</span><span class=\"s1\">Follow up: Where is Martin Campbell from?</span><span class=\"se\">\\\\n</span><span class=\"s1\">Intermediate answer: New Zealand.</span><span class=\"se\">\\\\n</span><span class=\"s1\">So the final answer is: No</span><span class=\"se\">\\\\n\\\\n</span><span class=\"s1\">Question: What is the zip code of the city where George Washington was born?</span><span class=\"se\">\\\\n</span><span class=\"s1\">Are followup questions needed here: Yes.</span><span class=\"se\">\\\\n</span><span class=\"s1\">Follow up: Where was George Washington born?&#39;</span><span class=\"p\">,</span> <span class=\"n\">state</span><span class=\"o\">=</span><span class=\"n\">IntermediateState</span><span class=\"p\">(</span><span class=\"n\">s</span><span class=\"o\">=</span><span class=\"s1\">&#39;Where was George Washington born?&#39;</span><span class=\"p\">))</span>\\n</pre></div>\\n\\n </dd>\\n</main>\\n')"
286
  ]
287
  },
288
- "execution_count": 8,
289
  "metadata": {},
290
- "output_type": "execute_result"
291
  }
292
  ],
293
  "source": [
294
- "SelfAsk().show(\n",
295
- " {\n",
296
- " \"input\": \"What is the zip code of the city where George Washington was born?\",\n",
297
- " \"agent_scratchpad\": True,\n",
298
- " },\n",
299
- " \"Follow up: Where was George Washington born?\",\n",
300
- ")"
301
- ]
302
- },
303
- {
304
- "cell_type": "markdown",
305
- "id": "d69d913c",
306
- "metadata": {},
307
- "source": [
308
- "View log."
309
  ]
310
  },
311
  {
312
  "cell_type": "code",
313
- "execution_count": 9,
314
- "id": "2ce2a55a",
315
- "metadata": {
316
- "execution": {
317
- "iopub.execute_input": "2023-02-27T14:18:28.488652Z",
318
- "iopub.status.busy": "2023-02-27T14:18:28.486297Z",
319
- "iopub.status.idle": "2023-02-27T14:18:28.551300Z",
320
- "shell.execute_reply": "2023-02-27T14:18:28.550712Z"
321
- }
322
- },
323
- "outputs": [
324
- {
325
- "name": "stderr",
326
- "output_type": "stream",
327
- "text": [
328
- "\u001b[38;5;15ma1394473-6f63-4eda-a13c-b04d79cc2ad4\u001b[1m\u001b[0m\n",
329
- "└── \u001b[38;5;5m<class '__main__.SelfAsk'>\u001b[0m/1\u001b[0m ⇒ \u001b[38;5;2mstarted\u001b[0m \u001b[38;5;15m2023-02-27 14:18:10Z\u001b[2m\u001b[0m ⧖ \u001b[38;5;4m1.268s\u001b[2m\u001b[0m\n",
330
- " ├── \u001b[38;5;5mInput Function\u001b[0m/2/1\u001b[0m ⇒ \u001b[38;5;2mstarted\u001b[0m \u001b[38;5;15m2023-02-27 14:18:10Z\u001b[2m\u001b[0m ⧖ \u001b[38;5;4m0.004s\u001b[2m\u001b[0m\n",
331
- " │ ├── \u001b[38;5;4minput\u001b[0m: \u001b[0m\n",
332
- " │ │ ├── \u001b[38;5;4magent_scratchpad\u001b[0m: True\u001b[0m\n",
333
- " │ │ ├── \u001b[38;5;4minput\u001b[0m: What is the zip code of the city where George Washington was born?\u001b[0m\n",
334
- " │ │ └── \u001b[38;5;4msuffix\u001b[0m: \u001b[0m\n",
335
- " │ └── \u001b[38;5;5mInput Function\u001b[0m/2/2\u001b[0m ⇒ \u001b[38;5;2msucceeded\u001b[0m \u001b[38;5;15m2023-02-27 14:18:10Z\u001b[2m\u001b[0m\n",
336
- " ├── \u001b[38;5;5mPrompted\u001b[0m/3/1\u001b[0m ⇒ \u001b[38;5;2mstarted\u001b[0m \u001b[38;5;15m2023-02-27 14:18:10Z\u001b[2m\u001b[0m ⧖ \u001b[38;5;4m1.258s\u001b[2m\u001b[0m\n",
337
- " │ ├── \u001b[38;5;4mprompt\u001b[0m: Question: Who lived longer, Muhammad Ali or Alan Turing?⏎\n",
338
- " │ │ Are follow up questions needed here: Yes.⏎\n",
339
- " │ │ Follow up: How old was Muhammad Ali when he died?⏎\n",
340
- " │ │ Intermediate answer: Muhammad Ali was 74 years old when he died.⏎\n",
341
- " │ │ Follow up: How old was Alan Turing when he died?⏎\n",
342
- " │ │ Intermediate answer: Alan Turing was 41 years old when he died.⏎\n",
343
- " │ │ So the final answer is: Muhammad Ali⏎\n",
344
- " │ │ ⏎\n",
345
- " │ │ Question: When was the founder of craigslist born?⏎\n",
346
- " │ │ Are follow up questions needed here: Yes.⏎\n",
347
- " │ │ Follow up: Who was the founder of craigslist?⏎\n",
348
- " │ │ Intermediate answer: Craigslist was founded by Craig Newmark.⏎\n",
349
- " │ │ Follow up: When was Craig Newmark born?⏎\n",
350
- " │ │ Intermediate answer: Craig Newmark was born on December 6, 1952.⏎\n",
351
- " │ │ So the final answer is: December 6, 1952⏎\n",
352
- " │ │ ⏎\n",
353
- " │ │ Question: Who was the maternal grandfather of George Washington?⏎\n",
354
- " │ │ Are follow up questions needed here: Yes.⏎\n",
355
- " │ │ Follow up: Who was the mother of George Washington?⏎\n",
356
- " │ │ Intermediate answer: The mother of George Washington was Mary Ball Washington.⏎\n",
357
- " │ │ Follow up: Who was the father of Mary Ball Washington?⏎\n",
358
- " │ │ Intermediate answer: The father of Mary Ball Washington was Joseph Ball.⏎\n",
359
- " │ │ So the final answer is: Joseph Ball⏎\n",
360
- " │ │ ⏎\n",
361
- " │ │ Question: Are both the directors of Jaws and Casino Royale from the same country?⏎\n",
362
- " │ │ Are follow up questions needed here: Yes.⏎\n",
363
- " │ │ Follow up: Who is the director of Jaws?⏎\n",
364
- " │ │ Intermediate answer: The director of Jaws is Steven Spielberg.⏎\n",
365
- " │ │ Follow up: Where is Steven Spielberg from?⏎\n",
366
- " │ │ Intermediate answer: The United States.⏎\n",
367
- " │ │ Follow up: Who is the director of Casino Royale?⏎\n",
368
- " │ │ Intermediate answer: The director of Casino Royale is Martin Campbell.⏎\n",
369
- " │ │ Follow up: Where is Martin Campbell from?⏎\n",
370
- " │ │ Intermediate answer: New Zealand.⏎\n",
371
- " │ │ So the final answer is: No⏎\n",
372
- " │ │ ⏎\n",
373
- " │ │ Question: What is the zip code of the city where George Washington was born?⏎\n",
374
- " │ │ Are followup questions needed here: Yes.⏎\n",
375
- " │ │ \u001b[0m\n",
376
- " │ └── \u001b[38;5;5mPrompted\u001b[0m/3/2\u001b[0m ⇒ \u001b[38;5;2msucceeded\u001b[0m \u001b[38;5;15m2023-02-27 14:18:11Z\u001b[2m\u001b[0m\n",
377
- " ├── \u001b[38;5;5mResult\u001b[0m/4/1\u001b[0m ⇒ \u001b[38;5;2mstarted\u001b[0m \u001b[38;5;15m2023-02-27 14:18:11Z\u001b[2m\u001b[0m ⧖ \u001b[38;5;4m0.006s\u001b[2m\u001b[0m\n",
378
- " │ ├── \u001b[38;5;4mresult\u001b[0m: Follow up: What city was George Washington born in?\u001b[0m\n",
379
- " │ └── \u001b[38;5;5mResult\u001b[0m/4/2\u001b[0m ⇒ \u001b[38;5;2msucceeded\u001b[0m \u001b[38;5;15m2023-02-27 14:18:11Z\u001b[2m\u001b[0m\n",
380
- " └── \u001b[38;5;5m<class '__main__.SelfAsk'>\u001b[0m/5\u001b[0m ⇒ \u001b[38;5;2msucceeded\u001b[0m \u001b[38;5;15m2023-02-27 14:18:11Z\u001b[2m\u001b[0m\n",
381
- "\n",
382
- "\u001b[38;5;15mffe25034-5698-4de3-9cea-dc45d7c5bbbb\u001b[1m\u001b[0m\n",
383
- "└── \u001b[38;5;5m<class 'minichain.prompts.SimplePrompt'>\u001b[0m/1\u001b[0m ⇒ \u001b[38;5;2mstarted\u001b[0m \u001b[38;5;15m2023-02-27 14:18:11Z\u001b[2m\u001b[0m ⧖ \u001b[38;5;4m6.168s\u001b[2m\u001b[0m\n",
384
- " ├── \u001b[38;5;5mInput Function\u001b[0m/2/1\u001b[0m ⇒ \u001b[38;5;2mstarted\u001b[0m \u001b[38;5;15m2023-02-27 14:18:11Z\u001b[2m\u001b[0m ⧖ \u001b[38;5;4m0.000s\u001b[2m\u001b[0m\n",
385
- " │ ├── \u001b[38;5;4minput\u001b[0m: What city was George Washington born in?\u001b[0m\n",
386
- " │ └── \u001b[38;5;5mInput Function\u001b[0m/2/2\u001b[0m ⇒ \u001b[38;5;2msucceeded\u001b[0m \u001b[38;5;15m2023-02-27 14:18:11Z\u001b[2m\u001b[0m\n",
387
- " ├── \u001b[38;5;5mPrompted\u001b[0m/3/1\u001b[0m ⇒ \u001b[38;5;2mstarted\u001b[0m \u001b[38;5;15m2023-02-27 14:18:11Z\u001b[2m\u001b[0m ⧖ \u001b[38;5;4m6.167s\u001b[2m\u001b[0m\n",
388
- " │ ├── \u001b[38;5;4mprompt\u001b[0m: What city was George Washington born in?\u001b[0m\n",
389
- " │ └── \u001b[38;5;5mPrompted\u001b[0m/3/2\u001b[0m ⇒ \u001b[38;5;2msucceeded\u001b[0m \u001b[38;5;15m2023-02-27 14:18:17Z\u001b[2m\u001b[0m\n",
390
- " ├── \u001b[38;5;5mResult\u001b[0m/4/1\u001b[0m ⇒ \u001b[38;5;2mstarted\u001b[0m \u001b[38;5;15m2023-02-27 14:18:17Z\u001b[2m\u001b[0m ⧖ \u001b[38;5;4m0.000s\u001b[2m\u001b[0m\n",
391
- " │ ├── \u001b[38;5;4mresult\u001b[0m: Westmoreland County, VA\u001b[0m\n",
392
- " │ └── \u001b[38;5;5mResult\u001b[0m/4/2\u001b[0m ⇒ \u001b[38;5;2msucceeded\u001b[0m \u001b[38;5;15m2023-02-27 14:18:17Z\u001b[2m\u001b[0m\n",
393
- " └── \u001b[38;5;5m<class 'minichain.prompts.SimplePrompt'>\u001b[0m/5\u001b[0m ⇒ \u001b[38;5;2msucceeded\u001b[0m \u001b[38;5;15m2023-02-27 14:18:17Z\u001b[2m\u001b[0m\n",
394
- "\n",
395
- "\u001b[38;5;15mbb2f39a3-d025-4c15-a564-f2c33f48d14f\u001b[1m\u001b[0m\n",
396
- "└── \u001b[38;5;5m<class '__main__.SelfAsk'>\u001b[0m/1\u001b[0m ⇒ \u001b[38;5;2mstarted\u001b[0m \u001b[38;5;15m2023-02-27 14:18:17Z\u001b[2m\u001b[0m ⧖ \u001b[38;5;4m1.734s\u001b[2m\u001b[0m\n",
397
- " ├── \u001b[38;5;5mInput Function\u001b[0m/2/1\u001b[0m ⇒ \u001b[38;5;2mstarted\u001b[0m \u001b[38;5;15m2023-02-27 14:18:17Z\u001b[2m\u001b[0m ⧖ \u001b[38;5;4m0.006s\u001b[2m\u001b[0m\n",
398
- " │ ├── \u001b[38;5;4minput\u001b[0m: \u001b[0m\n",
399
- " │ │ ├── \u001b[38;5;4magent_scratchpad\u001b[0m: True\u001b[0m\n",
400
- " │ │ ├── \u001b[38;5;4minput\u001b[0m: What is the zip code of the city where George Washington was born?\u001b[0m\n",
401
- " │ │ └── \u001b[38;5;4msuffix\u001b[0m: Question: Who lived longer, Muhammad Ali or Alan Turing?⏎\n",
402
- " │ │ Are follow up questions needed here: Yes.⏎\n",
403
- " │ │ Follow up: How old was Muhammad Ali when he died?⏎\n",
404
- " │ │ Intermediate answer: Muhammad Ali was 74 years old when he died.⏎\n",
405
- " │ │ Follow up: How old was Alan Turing when he died?⏎\n",
406
- " │ │ Intermediate answer: Alan Turing was 41 years old when he died.⏎\n",
407
- " │ │ So the final answer is: Muhammad Ali⏎\n",
408
- " │ │ ⏎\n",
409
- " │ │ Question: When was the founder of craigslist born?⏎\n",
410
- " │ │ Are follow up questions needed here: Yes.⏎\n",
411
- " │ │ Follow up: Who was the founder of craigslist?⏎\n",
412
- " │ │ Intermediate answer: Craigslist was founded by Craig Newmark.⏎\n",
413
- " │ │ Follow up: When was Craig Newmark born?⏎\n",
414
- " │ │ Intermediate answer: Craig Newmark was born on December 6, 1952.⏎\n",
415
- " │ │ So the final answer is: December 6, 1952⏎\n",
416
- " │ │ ⏎\n",
417
- " │ │ Question: Who was the maternal grandfather of George Washington?⏎\n",
418
- " │ │ Are follow up questions needed here: Yes.⏎\n",
419
- " │ │ Follow up: Who was the mother of George Washington?⏎\n",
420
- " │ │ Intermediate answer: The mother of George Washington was Mary Ball Washington.⏎\n",
421
- " │ │ Follow up: Who was the father of Mary Ball Washington?⏎\n",
422
- " │ │ Intermediate answer: The father of Mary Ball Washington was Joseph Ball.⏎\n",
423
- " │ │ So the final answer is: Joseph Ball⏎\n",
424
- " │ │ ⏎\n",
425
- " │ │ Question: Are both the directors of Jaws and Casino Royale from the same country?⏎\n",
426
- " │ │ Are follow up questions needed here: Yes.⏎\n",
427
- " │ │ Follow up: Who is the director of Jaws?⏎\n",
428
- " │ │ Intermediate answer: The director of Jaws is Steven Spielberg.⏎\n",
429
- " │ │ Follow up: Where is Steven Spielberg from?⏎\n",
430
- " │ │ Intermediate answer: The United States.⏎\n",
431
- " │ │ Follow up: Who is the director of Casino Royale?⏎\n",
432
- " │ │ Intermediate answer: The director of Casino Royale is Martin Campbell.⏎\n",
433
- " │ │ Follow up: Where is Martin Campbell from?⏎\n",
434
- " │ │ Intermediate answer: New Zealand.⏎\n",
435
- " │ │ So the final answer is: No⏎\n",
436
- " │ │ ⏎\n",
437
- " │ │ Question: What is the zip code of the city where George Washington was born?⏎\n",
438
- " │ │ Are followup questions needed here: Yes.⏎\n",
439
- " │ │ Follow up: What city was George Washington born in?⏎\n",
440
- " │ │ Intermediate answer: Westmoreland County, VA⏎\n",
441
- " │ │ \u001b[0m\n",
442
- " │ └── \u001b[38;5;5mInput Function\u001b[0m/2/2\u001b[0m ⇒ \u001b[38;5;2msucceeded\u001b[0m \u001b[38;5;15m2023-02-27 14:18:17Z\u001b[2m\u001b[0m\n",
443
- " ├── \u001b[38;5;5mPrompted\u001b[0m/3/1\u001b[0m ⇒ \u001b[38;5;2mstarted\u001b[0m \u001b[38;5;15m2023-02-27 14:18:17Z\u001b[2m\u001b[0m ⧖ \u001b[38;5;4m1.725s\u001b[2m\u001b[0m\n",
444
- " │ ├── \u001b[38;5;4mprompt\u001b[0m: Question: Who lived longer, Muhammad Ali or Alan Turing?⏎\n",
445
- " │ │ Are follow up questions needed here: Yes.⏎\n",
446
- " │ │ Follow up: How old was Muhammad Ali when he died?⏎\n",
447
- " │ │ Intermediate answer: Muhammad Ali was 74 years old when he died.⏎\n",
448
- " │ │ Follow up: How old was Alan Turing when he died?⏎\n",
449
- " │ │ Intermediate answer: Alan Turing was 41 years old when he died.⏎\n",
450
- " │ │ So the final answer is: Muhammad Ali⏎\n",
451
- " │ │ ⏎\n",
452
- " │ │ Question: When was the founder of craigslist born?⏎\n",
453
- " │ │ Are follow up questions needed here: Yes.⏎\n",
454
- " │ │ Follow up: Who was the founder of craigslist?⏎\n",
455
- " │ │ Intermediate answer: Craigslist was founded by Craig Newmark.⏎\n",
456
- " │ │ Follow up: When was Craig Newmark born?⏎\n",
457
- " │ │ Intermediate answer: Craig Newmark was born on December 6, 1952.⏎\n",
458
- " │ │ So the final answer is: December 6, 1952⏎\n",
459
- " │ │ ⏎\n",
460
- " │ │ Question: Who was the maternal grandfather of George Washington?⏎\n",
461
- " │ │ Are follow up questions needed here: Yes.⏎\n",
462
- " │ │ Follow up: Who was the mother of George Washington?⏎\n",
463
- " │ │ Intermediate answer: The mother of George Washington was Mary Ball Washington.⏎\n",
464
- " │ │ Follow up: Who was the father of Mary Ball Washington?⏎\n",
465
- " │ │ Intermediate answer: The father of Mary Ball Washington was Joseph Ball.⏎\n",
466
- " │ │ So the final answer is: Joseph Ball⏎\n",
467
- " │ │ ⏎\n",
468
- " │ │ Question: Are both the directors of Jaws and Casino Royale from the same country?⏎\n",
469
- " │ │ Are follow up questions needed here: Yes.⏎\n",
470
- " │ │ Follow up: Who is the director of Jaws?⏎\n",
471
- " │ │ Intermediate answer: The director of Jaws is Steven Spielberg.⏎\n",
472
- " │ │ Follow up: Where is Steven Spielberg from?⏎\n",
473
- " │ │ Intermediate answer: The United States.⏎\n",
474
- " │ │ Follow up: Who is the director of Casino Royale?⏎\n",
475
- " │ │ Intermediate answer: The director of Casino Royale is Martin Campbell.⏎\n",
476
- " │ │ Follow up: Where is Martin Campbell from?⏎\n",
477
- " │ │ Intermediate answer: New Zealand.⏎\n",
478
- " │ │ So the final answer is: No⏎\n",
479
- " │ │ ⏎\n",
480
- " │ │ Question: What is the zip code of the city where George Washington was born?⏎\n",
481
- " │ │ Are followup questions needed here: Yes.⏎\n",
482
- " │ │ Question: Who lived longer, Muhammad Ali or Alan Turing?⏎\n",
483
- " │ │ Are follow up questions needed here: Yes.⏎\n",
484
- " │ │ Follow up: How old was Muhammad Ali when he died?⏎\n",
485
- " │ │ Intermediate answer: Muhammad Ali was 74 years old when he died.⏎\n",
486
- " │ │ Follow up: How old was Alan Turing when he died?⏎\n",
487
- " │ │ Intermediate answer: Alan Turing was 41 years old when he died.⏎\n",
488
- " │ │ So the final answer is: Muhammad Ali⏎\n",
489
- " │ │ ⏎\n",
490
- " │ │ Question: When was the founder of craigslist born?⏎\n",
491
- " │ │ Are follow up questions needed here: Yes.⏎\n",
492
- " │ │ Follow up: Who was the founder of craigslist?⏎\n",
493
- " │ │ Intermediate answer: Craigslist was founded by Craig Newmark.⏎\n",
494
- " │ │ Follow up: When was Craig Newmark born?⏎\n",
495
- " │ │ Intermediate answer: Craig Newmark was born on December 6, 1952.⏎\n",
496
- " │ │ So the final answer is: December 6, 1952⏎\n",
497
- " │ │ ⏎\n",
498
- " │ │ Question: Who was the maternal grandfather of George Washington?⏎\n",
499
- " │ │ Are follow up questions needed here: Yes.⏎\n",
500
- " │ │ Follow up: Who was the mother of George Washington?⏎\n",
501
- " │ │ Intermediate answer: The mother of George Washington was Mary Ball Washington.⏎\n",
502
- " │ │ Follow up: Who was the father of Mary Ball Washington?⏎\n",
503
- " │ │ Intermediate answer: The father of Mary Ball Washington was Joseph Ball.⏎\n",
504
- " │ │ So the final answer is: Joseph Ball⏎\n",
505
- " │ │ ⏎\n",
506
- " │ │ Question: Are both the directors of Jaws and Casino Royale from the same country?⏎\n",
507
- " │ │ Are follow up questions needed here: Yes.⏎\n",
508
- " │ │ Follow up: Who is the director of Jaws?⏎\n",
509
- " │ │ Intermediate answer: The director of Jaws is Steven Spielberg.⏎\n",
510
- " │ │ Follow up: Where is Steven Spielberg from?⏎\n",
511
- " │ │ Intermediate answer: The United States.⏎\n",
512
- " │ │ Follow up: Who is the director of Casino Royale?⏎\n",
513
- " │ │ Intermediate answer: The director of Casino Royale is Martin Campbell.⏎\n",
514
- " │ │ Follow up: Where is Martin Campbell from?⏎\n",
515
- " │ │ Intermediate answer: New Zealand.⏎\n",
516
- " │ │ So the final answer is: No⏎\n",
517
- " │ │ ⏎\n",
518
- " │ │ Question: What is the zip code of the city where George Washington was born?⏎\n",
519
- " │ │ Are followup questions needed here: Yes.⏎\n",
520
- " │ │ Follow up: What city was George Washington born in?⏎\n",
521
- " │ │ Intermediate answer: Westmoreland County, VA⏎\n",
522
- " │ │ \u001b[0m\n",
523
- " │ └── \u001b[38;5;5mPrompted\u001b[0m/3/2\u001b[0m ⇒ \u001b[38;5;2msucceeded\u001b[0m \u001b[38;5;15m2023-02-27 14:18:19Z\u001b[2m\u001b[0m\n",
524
- " ├── \u001b[38;5;5mResult\u001b[0m/4/1\u001b[0m ⇒ \u001b[38;5;2mstarted\u001b[0m \u001b[38;5;15m2023-02-27 14:18:19Z\u001b[2m\u001b[0m ⧖ \u001b[38;5;4m0.002s\u001b[2m\u001b[0m\n",
525
- " │ ├── \u001b[38;5;4mresult\u001b[0m: Follow up: What is the zip code of Westmoreland County, VA?\u001b[0m\n",
526
- " │ └── \u001b[38;5;5mResult\u001b[0m/4/2\u001b[0m ⇒ \u001b[38;5;2msucceeded\u001b[0m \u001b[38;5;15m2023-02-27 14:18:19Z\u001b[2m\u001b[0m\n",
527
- " └── \u001b[38;5;5m<class '__main__.SelfAsk'>\u001b[0m/5\u001b[0m ⇒ \u001b[38;5;2msucceeded\u001b[0m \u001b[38;5;15m2023-02-27 14:18:19Z\u001b[2m\u001b[0m\n",
528
- "\n",
529
- "\u001b[38;5;15ma350a6f0-d210-474f-bc35-30326fba706d\u001b[1m\u001b[0m\n",
530
- "└── \u001b[38;5;5m<class 'minichain.prompts.SimplePrompt'>\u001b[0m/1\u001b[0m ⇒ \u001b[38;5;2mstarted\u001b[0m \u001b[38;5;15m2023-02-27 14:18:19Z\u001b[2m\u001b[0m ⧖ \u001b[38;5;4m6.291s\u001b[2m\u001b[0m\n",
531
- " ├── \u001b[38;5;5mInput Function\u001b[0m/2/1\u001b[0m ⇒ \u001b[38;5;2mstarted\u001b[0m \u001b[38;5;15m2023-02-27 14:18:19Z\u001b[2m\u001b[0m ⧖ \u001b[38;5;4m0.000s\u001b[2m\u001b[0m\n",
532
- " │ ├── \u001b[38;5;4minput\u001b[0m: What is the zip code of Westmoreland County, VA?\u001b[0m\n",
533
- " │ └── \u001b[38;5;5mInput Function\u001b[0m/2/2\u001b[0m ⇒ \u001b[38;5;2msucceeded\u001b[0m \u001b[38;5;15m2023-02-27 14:18:19Z\u001b[2m\u001b[0m\n",
534
- " ├── \u001b[38;5;5mPrompted\u001b[0m/3/1\u001b[0m ⇒ \u001b[38;5;2mstarted\u001b[0m \u001b[38;5;15m2023-02-27 14:18:19Z\u001b[2m\u001b[0m ⧖ \u001b[38;5;4m6.290s\u001b[2m\u001b[0m\n",
535
- " │ ├── \u001b[38;5;4mprompt\u001b[0m: What is the zip code of Westmoreland County, VA?\u001b[0m\n",
536
- " │ └── \u001b[38;5;5mPrompted\u001b[0m/3/2\u001b[0m ⇒ \u001b[38;5;2msucceeded\u001b[0m \u001b[38;5;15m2023-02-27 14:18:25Z\u001b[2m\u001b[0m\n",
537
- " ├── \u001b[38;5;5mResult\u001b[0m/4/1\u001b[0m ⇒ \u001b[38;5;2mstarted\u001b[0m \u001b[38;5;15m2023-02-27 14:18:25Z\u001b[2m\u001b[0m ⧖ \u001b[38;5;4m0.000s\u001b[2m\u001b[0m\n",
538
- " │ ├── \u001b[38;5;4mresult\u001b[0m: ZIP Codes in Westmoreland County VA · 22443 · 22520 · 22469 · 22488 · 22442 · 22524 · 22529 · 22558 ...\u001b[0m\n",
539
- " │ └── \u001b[38;5;5mResult\u001b[0m/4/2\u001b[0m ⇒ \u001b[38;5;2msucceeded\u001b[0m \u001b[38;5;15m2023-02-27 14:18:25Z\u001b[2m\u001b[0m\n",
540
- " └── \u001b[38;5;5m<class 'minichain.prompts.SimplePrompt'>\u001b[0m/5\u001b[0m ⇒ \u001b[38;5;2msucceeded\u001b[0m \u001b[38;5;15m2023-02-27 14:18:25Z\u001b[2m\u001b[0m\n",
541
- "\n",
542
- "\u001b[38;5;15m76cb4bce-847c-4867-ad34-804cbf25324f\u001b[1m\u001b[0m\n",
543
- "└── \u001b[38;5;5m<class '__main__.SelfAsk'>\u001b[0m/1\u001b[0m ⇒ \u001b[38;5;2mstarted\u001b[0m \u001b[38;5;15m2023-02-27 14:18:25Z\u001b[2m\u001b[0m ⧖ \u001b[38;5;4m2.419s\u001b[2m\u001b[0m\n",
544
- " ├── \u001b[38;5;5mInput Function\u001b[0m/2/1\u001b[0m ⇒ \u001b[38;5;2mstarted\u001b[0m \u001b[38;5;15m2023-02-27 14:18:25Z\u001b[2m\u001b[0m ⧖ \u001b[38;5;4m0.006s\u001b[2m\u001b[0m\n",
545
- " │ ├── \u001b[38;5;4minput\u001b[0m: \u001b[0m\n",
546
- " │ │ ├── \u001b[38;5;4magent_scratchpad\u001b[0m: True\u001b[0m\n",
547
- " │ │ ├── \u001b[38;5;4minput\u001b[0m: What is the zip code of the city where George Washington was born?\u001b[0m\n",
548
- " │ │ └── \u001b[38;5;4msuffix\u001b[0m: Question: Who lived longer, Muhammad Ali or Alan Turing?⏎\n",
549
- " │ │ Are follow up questions needed here: Yes.⏎\n",
550
- " │ │ Follow up: How old was Muhammad Ali when he died?⏎\n",
551
- " │ │ Intermediate answer: Muhammad Ali was 74 years old when he died.⏎\n",
552
- " │ │ Follow up: How old was Alan Turing when he died?⏎\n",
553
- " │ │ Intermediate answer: Alan Turing was 41 years old when he died.⏎\n",
554
- " │ │ So the final answer is: Muhammad Ali⏎\n",
555
- " │ │ ⏎\n",
556
- " │ │ Question: When was the founder of craigslist born?⏎\n",
557
- " │ │ Are follow up questions needed here: Yes.⏎\n",
558
- " │ │ Follow up: Who was the founder of craigslist?⏎\n",
559
- " │ │ Intermediate answer: Craigslist was founded by Craig Newmark.⏎\n",
560
- " │ │ Follow up: When was Craig Newmark born?⏎\n",
561
- " │ │ Intermediate answer: Craig Newmark was born on December 6, 1952.⏎\n",
562
- " │ │ So the final answer is: December 6, 1952⏎\n",
563
- " │ │ ⏎\n",
564
- " │ │ Question: Who was the maternal grandfather of George Washington?⏎\n",
565
- " │ │ Are follow up questions needed here: Yes.⏎\n",
566
- " │ │ Follow up: Who was the mother of George Washington?⏎\n",
567
- " │ │ Intermediate answer: The mother of George Washington was Mary Ball Washington.⏎\n",
568
- " │ │ Follow up: Who was the father of Mary Ball Washington?⏎\n",
569
- " │ │ Intermediate answer: The father of Mary Ball Washington was Joseph Ball.⏎\n",
570
- " │ │ So the final answer is: Joseph Ball⏎\n",
571
- " │ │ ⏎\n",
572
- " │ │ Question: Are both the directors of Jaws and Casino Royale from the same country?⏎\n",
573
- " │ │ Are follow up questions needed here: Yes.⏎\n",
574
- " │ │ Follow up: Who is the director of Jaws?⏎\n",
575
- " │ │ Intermediate answer: The director of Jaws is Steven Spielberg.⏎\n",
576
- " │ │ Follow up: Where is Steven Spielberg from?⏎\n",
577
- " │ │ Intermediate answer: The United States.⏎\n",
578
- " │ │ Follow up: Who is the director of Casino Royale?⏎\n",
579
- " │ │ Intermediate answer: The director of Casino Royale is Martin Campbell.⏎\n",
580
- " │ │ Follow up: Where is Martin Campbell from?⏎\n",
581
- " │ │ Intermediate answer: New Zealand.⏎\n",
582
- " │ │ So the final answer is: No⏎\n",
583
- " │ │ ⏎\n",
584
- " │ │ Question: What is the zip code of the city where George Washington was born?⏎\n",
585
- " │ │ Are followup questions needed here: Yes.⏎\n",
586
- " │ │ Follow up: What city was George Washington born in?⏎\n",
587
- " │ │ Intermediate answer: Westmoreland County, VA⏎\n",
588
- " │ │ Question: Who lived longer, Muhammad Ali or Alan Turing?⏎\n",
589
- " │ │ Are follow up questions needed here: Yes.⏎\n",
590
- " │ │ Follow up: How old was Muhammad Ali when he died?⏎\n",
591
- " │ │ Intermediate answer: Muhammad Ali was 74 years old when he died.⏎\n",
592
- " │ │ Follow up: How old was Alan Turing when he died?⏎\n",
593
- " │ │ Intermediate answer: Alan Turing was 41 years old when he died.⏎\n",
594
- " │ │ So the final answer is: Muhammad Ali⏎\n",
595
- " │ │ ⏎\n",
596
- " │ │ Question: When was the founder of craigslist born?⏎\n",
597
- " │ │ Are follow up questions needed here: Yes.⏎\n",
598
- " │ │ Follow up: Who was the founder of craigslist?⏎\n",
599
- " │ │ Intermediate answer: Craigslist was founded by Craig Newmark.⏎\n",
600
- " │ │ Follow up: When was Craig Newmark born?⏎\n",
601
- " │ │ Intermediate answer: Craig Newmark was born on December 6, 1952.⏎\n",
602
- " │ │ So the final answer is: December 6, 1952⏎\n",
603
- " │ │ ⏎\n",
604
- " │ │ Question: Who was the maternal grandfather of George Washington?⏎\n",
605
- " │ │ Are follow up questions needed here: Yes.⏎\n",
606
- " │ │ Follow up: Who was the mother of George Washington?⏎\n",
607
- " │ │ Intermediate answer: The mother of George Washington was Mary Ball Washington.⏎\n",
608
- " │ │ Follow up: Who was the father of Mary Ball Washington?⏎\n",
609
- " │ │ Intermediate answer: The father of Mary Ball Washington was Joseph Ball.⏎\n",
610
- " │ │ So the final answer is: Joseph Ball⏎\n",
611
- " │ │ ⏎\n",
612
- " │ │ Question: Are both the directors of Jaws and Casino Royale from the same country?⏎\n",
613
- " │ │ Are follow up questions needed here: Yes.⏎\n",
614
- " │ │ Follow up: Who is the director of Jaws?⏎\n",
615
- " │ │ Intermediate answer: The director of Jaws is Steven Spielberg.⏎\n",
616
- " │ │ Follow up: Where is Steven Spielberg from?⏎\n",
617
- " │ │ Intermediate answer: The United States.⏎\n",
618
- " │ │ Follow up: Who is the director of Casino Royale?⏎\n",
619
- " │ │ Intermediate answer: The director of Casino Royale is Martin Campbell.⏎\n",
620
- " │ │ Follow up: Where is Martin Campbell from?⏎\n",
621
- " │ │ Intermediate answer: New Zealand.⏎\n",
622
- " │ │ So the final answer is: No⏎\n",
623
- " │ │ ⏎\n",
624
- " │ │ Question: What is the zip code of the city where George Washington was born?⏎\n",
625
- " │ │ Are followup questions needed here: Yes.⏎\n",
626
- " │ │ Question: Who lived longer, Muhammad Ali or Alan Turing?⏎\n",
627
- " │ │ Are follow up questions needed here: Yes.⏎\n",
628
- " │ │ Follow up: How old was Muhammad Ali when he died?⏎\n",
629
- " │ │ Intermediate answer: Muhammad Ali was 74 years old when he died.⏎\n",
630
- " │ │ Follow up: How old was Alan Turing when he died?⏎\n",
631
- " │ │ Intermediate answer: Alan Turing was 41 years old when he died.⏎\n",
632
- " │ │ So the final answer is: Muhammad Ali⏎\n",
633
- " │ │ ⏎\n",
634
- " │ │ Question: When was the founder of craigslist born?⏎\n",
635
- " │ │ Are follow up questions needed here: Yes.⏎\n",
636
- " │ │ Follow up: Who was the founder of craigslist?⏎\n",
637
- " │ │ Intermediate answer: Craigslist was founded by Craig Newmark.⏎\n",
638
- " │ │ Follow up: When was Craig Newmark born?⏎\n",
639
- " │ │ Intermediate answer: Craig Newmark was born on December 6, 1952.⏎\n",
640
- " │ │ So the final answer is: December 6, 1952⏎\n",
641
- " │ │ ⏎\n",
642
- " │ │ Question: Who was the maternal grandfather of George Washington?⏎\n",
643
- " │ │ Are follow up questions needed here: Yes.⏎\n",
644
- " │ │ Follow up: Who was the mother of George Washington?⏎\n",
645
- " │ │ Intermediate answer: The mother of George Washington was Mary Ball Washington.⏎\n",
646
- " │ │ Follow up: Who was the father of Mary Ball Washington?⏎\n",
647
- " │ │ Intermediate answer: The father of Mary Ball Washington was Joseph Ball.⏎\n",
648
- " │ │ So the final answer is: Joseph Ball⏎\n",
649
- " │ │ ⏎\n",
650
- " │ │ Question: Are both the directors of Jaws and Casino Royale from the same country?⏎\n",
651
- " │ │ Are follow up questions needed here: Yes.⏎\n",
652
- " │ │ Follow up: Who is the director of Jaws?⏎\n",
653
- " │ │ Intermediate answer: The director of Jaws is Steven Spielberg.⏎\n",
654
- " │ │ Follow up: Where is Steven Spielberg from?⏎\n",
655
- " │ │ Intermediate answer: The United States.⏎\n",
656
- " │ │ Follow up: Who is the director of Casino Royale?⏎\n",
657
- " │ │ Intermediate answer: The director of Casino Royale is Martin Campbell.⏎\n",
658
- " │ │ Follow up: Where is Martin Campbell from?⏎\n",
659
- " │ │ Intermediate answer: New Zealand.⏎\n",
660
- " │ │ So the final answer is: No⏎\n",
661
- " │ │ ⏎\n",
662
- " │ │ Question: What is the zip code of the city where George Washington was born?⏎\n",
663
- " │ │ Are followup questions needed here: Yes.⏎\n",
664
- " │ │ Follow up: What city was George Washington born in?⏎\n",
665
- " │ │ Intermediate answer: Westmoreland County, VA⏎\n",
666
- " │ │ Follow up: What is the zip code of Westmoreland County, VA?⏎\n",
667
- " │ │ Intermediate answer: ZIP Codes in Westmoreland County VA · 22443 · 22520 · 22469 · 22488 · 22442 · 22524 · 22529 · 22558 ...⏎\n",
668
- " │ │ \u001b[0m\n",
669
- " │ └── \u001b[38;5;5mInput Function\u001b[0m/2/2\u001b[0m ⇒ \u001b[38;5;2msucceeded\u001b[0m \u001b[38;5;15m2023-02-27 14:18:25Z\u001b[2m\u001b[0m\n",
670
- " ├── \u001b[38;5;5mPrompted\u001b[0m/3/1\u001b[0m ⇒ \u001b[38;5;2mstarted\u001b[0m \u001b[38;5;15m2023-02-27 14:18:25Z\u001b[2m\u001b[0m ⧖ \u001b[38;5;4m2.407s\u001b[2m\u001b[0m\n",
671
- " │ ├── \u001b[38;5;4mprompt\u001b[0m: Question: Who lived longer, Muhammad Ali or Alan Turing?⏎\n",
672
- " │ │ Are follow up questions needed here: Yes.⏎\n",
673
- " │ │ Follow up: How old was Muhammad Ali when he died?⏎\n",
674
- " │ │ Intermediate answer: Muhammad Ali was 74 years old when he died.⏎\n",
675
- " │ │ Follow up: How old was Alan Turing when he died?⏎\n",
676
- " │ │ Intermediate answer: Alan Turing was 41 years old when he died.⏎\n",
677
- " │ │ So the final answer is: Muhammad Ali⏎\n",
678
- " │ │ ⏎\n",
679
- " │ │ Question: When was the founder of craigslist born?⏎\n",
680
- " │ │ Are follow up questions needed here: Yes.⏎\n",
681
- " │ │ Follow up: Who was the founder of craigslist?⏎\n",
682
- " │ │ Intermediate answer: Craigslist was founded by Craig Newmark.⏎\n",
683
- " │ │ Follow up: When was Craig Newmark born?⏎\n",
684
- " │ │ Intermediate answer: Craig Newmark was born on December 6, 1952.⏎\n",
685
- " │ │ So the final answer is: December 6, 1952⏎\n",
686
- " │ │ ⏎\n",
687
- " │ │ Question: Who was the maternal grandfather of George Washington?⏎\n",
688
- " │ │ Are follow up questions needed here: Yes.⏎\n",
689
- " │ │ Follow up: Who was the mother of George Washington?⏎\n",
690
- " │ │ Intermediate answer: The mother of George Washington was Mary Ball Washington.⏎\n",
691
- " │ │ Follow up: Who was the father of Mary Ball Washington?⏎\n",
692
- " │ │ Intermediate answer: The father of Mary Ball Washington was Joseph Ball.⏎\n",
693
- " │ │ So the final answer is: Joseph Ball⏎\n",
694
- " │ │ ⏎\n",
695
- " │ │ Question: Are both the directors of Jaws and Casino Royale from the same country?⏎\n",
696
- " │ │ Are follow up questions needed here: Yes.⏎\n",
697
- " │ │ Follow up: Who is the director of Jaws?⏎\n",
698
- " │ │ Intermediate answer: The director of Jaws is Steven Spielberg.⏎\n",
699
- " │ │ Follow up: Where is Steven Spielberg from?⏎\n",
700
- " │ │ Intermediate answer: The United States.⏎\n",
701
- " │ │ Follow up: Who is the director of Casino Royale?⏎\n",
702
- " │ │ Intermediate answer: The director of Casino Royale is Martin Campbell.⏎\n",
703
- " │ │ Follow up: Where is Martin Campbell from?⏎\n",
704
- " │ │ Intermediate answer: New Zealand.⏎\n",
705
- " │ │ So the final answer is: No⏎\n",
706
- " │ │ ⏎\n",
707
- " │ │ Question: What is the zip code of the city where George Washington was born?⏎\n",
708
- " │ │ Are followup questions needed here: Yes.⏎\n",
709
- " │ │ Question: Who lived longer, Muhammad Ali or Alan Turing?⏎\n",
710
- " │ │ Are follow up questions needed here: Yes.⏎\n",
711
- " │ │ Follow up: How old was Muhammad Ali when he died?⏎\n",
712
- " │ │ Intermediate answer: Muhammad Ali was 74 years old when he died.⏎\n",
713
- " │ │ Follow up: How old was Alan Turing when he died?⏎\n",
714
- " │ │ Intermediate answer: Alan Turing was 41 years old when he died.⏎\n",
715
- " │ │ So the final answer is: Muhammad Ali⏎\n",
716
- " │ │ ⏎\n",
717
- " │ │ Question: When was the founder of craigslist born?⏎\n",
718
- " │ │ Are follow up questions needed here: Yes.⏎\n",
719
- " │ │ Follow up: Who was the founder of craigslist?⏎\n",
720
- " │ │ Intermediate answer: Craigslist was founded by Craig Newmark.⏎\n",
721
- " │ │ Follow up: When was Craig Newmark born?⏎\n",
722
- " │ │ Intermediate answer: Craig Newmark was born on December 6, 1952.⏎\n",
723
- " │ │ So the final answer is: December 6, 1952⏎\n",
724
- " │ │ ⏎\n",
725
- " │ │ Question: Who was the maternal grandfather of George Washington?⏎\n",
726
- " │ │ Are follow up questions needed here: Yes.⏎\n",
727
- " │ │ Follow up: Who was the mother of George Washington?⏎\n",
728
- " │ │ Intermediate answer: The mother of George Washington was Mary Ball Washington.⏎\n",
729
- " │ │ Follow up: Who was the father of Mary Ball Washington?⏎\n",
730
- " │ │ Intermediate answer: The father of Mary Ball Washington was Joseph Ball.⏎\n",
731
- " │ │ So the final answer is: Joseph Ball⏎\n",
732
- " │ │ ⏎\n",
733
- " │ │ Question: Are both the directors of Jaws and Casino Royale from the same country?⏎\n",
734
- " │ │ Are follow up questions needed here: Yes.⏎\n",
735
- " │ │ Follow up: Who is the director of Jaws?⏎\n",
736
- " │ │ Intermediate answer: The director of Jaws is Steven Spielberg.⏎\n",
737
- " │ │ Follow up: Where is Steven Spielberg from?⏎\n",
738
- " │ │ Intermediate answer: The United States.⏎\n",
739
- " │ │ Follow up: Who is the director of Casino Royale?⏎\n",
740
- " │ │ Intermediate answer: The director of Casino Royale is Martin Campbell.⏎\n",
741
- " │ │ Follow up: Where is Martin Campbell from?⏎\n",
742
- " │ │ Intermediate answer: New Zealand.⏎\n",
743
- " │ │ So the final answer is: No⏎\n",
744
- " │ │ ⏎\n",
745
- " │ │ Question: What is the zip code of the city where George Washington was born?⏎\n",
746
- " │ │ Are followup questions needed here: Yes.⏎\n",
747
- " │ │ Follow up: What city was George Washington born in?⏎\n",
748
- " │ │ Intermediate answer: Westmoreland County, VA⏎\n",
749
- " │ │ Question: Who lived longer, Muhammad Ali or Alan Turing?⏎\n",
750
- " │ │ Are follow up questions needed here: Yes.⏎\n",
751
- " │ │ Follow up: How old was Muhammad Ali when he died?⏎\n",
752
- " │ │ Intermediate answer: Muhammad Ali was 74 years old when he died.⏎\n",
753
- " │ │ Follow up: How old was Alan Turing when he died?⏎\n",
754
- " │ │ Intermediate answer: Alan Turing was 41 years old when he died.⏎\n",
755
- " │ │ So the final answer is: Muhammad Ali⏎\n",
756
- " │ │ ⏎\n",
757
- " │ │ Question: When was the founder of craigslist born?⏎\n",
758
- " │ │ Are follow up questions needed here: Yes.⏎\n",
759
- " │ │ Follow up: Who was the founder of craigslist?⏎\n",
760
- " │ │ Intermediate answer: Craigslist was founded by Craig Newmark.⏎\n",
761
- " │ │ Follow up: When was Craig Newmark born?⏎\n",
762
- " │ │ Intermediate answer: Craig Newmark was born on December 6, 1952.⏎\n",
763
- " │ │ So the final answer is: December 6, 1952⏎\n",
764
- " │ │ ⏎\n",
765
- " │ │ Question: Who was the maternal grandfather of George Washington?⏎\n",
766
- " │ │ Are follow up questions needed here: Yes.⏎\n",
767
- " │ │ Follow up: Who was the mother of George Washington?⏎\n",
768
- " │ │ Intermediate answer: The mother of George Washington was Mary Ball Washington.⏎\n",
769
- " │ │ Follow up: Who was the father of Mary Ball Washington?⏎\n",
770
- " │ │ Intermediate answer: The father of Mary Ball Washington was Joseph Ball.⏎\n",
771
- " │ �� So the final answer is: Joseph Ball⏎\n",
772
- " │ │ ⏎\n",
773
- " │ │ Question: Are both the directors of Jaws and Casino Royale from the same country?⏎\n",
774
- " │ │ Are follow up questions needed here: Yes.⏎\n",
775
- " │ │ Follow up: Who is the director of Jaws?⏎\n",
776
- " │ │ Intermediate answer: The director of Jaws is Steven Spielberg.⏎\n",
777
- " │ │ Follow up: Where is Steven Spielberg from?⏎\n",
778
- " │ │ Intermediate answer: The United States.⏎\n",
779
- " │ │ Follow up: Who is the director of Casino Royale?⏎\n",
780
- " │ │ Intermediate answer: The director of Casino Royale is Martin Campbell.⏎\n",
781
- " │ │ Follow up: Where is Martin Campbell from?⏎\n",
782
- " │ │ Intermediate answer: New Zealand.⏎\n",
783
- " │ │ So the final answer is: No⏎\n",
784
- " │ │ ⏎\n",
785
- " │ │ Question: What is the zip code of the city where George Washington was born?⏎\n",
786
- " │ │ Are followup questions needed here: Yes.⏎\n",
787
- " │ │ Question: Who lived longer, Muhammad Ali or Alan Turing?⏎\n",
788
- " │ │ Are follow up questions needed here: Yes.⏎\n",
789
- " │ │ Follow up: How old was Muhammad Ali when he died?⏎\n",
790
- " │ │ Intermediate answer: Muhammad Ali was 74 years old when he died.⏎\n",
791
- " │ │ Follow up: How old was Alan Turing when he died?⏎\n",
792
- " │ │ Intermediate answer: Alan Turing was 41 years old when he died.⏎\n",
793
- " │ │ So the final answer is: Muhammad Ali⏎\n",
794
- " │ │ ⏎\n",
795
- " │ │ Question: When was the founder of craigslist born?⏎\n",
796
- " │ │ Are follow up questions needed here: Yes.⏎\n",
797
- " │ │ Follow up: Who was the founder of craigslist?⏎\n",
798
- " │ │ Intermediate answer: Craigslist was founded by Craig Newmark.⏎\n",
799
- " │ │ Follow up: When was Craig Newmark born?⏎\n",
800
- " │ │ Intermediate answer: Craig Newmark was born on December 6, 1952.⏎\n",
801
- " │ │ So the final answer is: December 6, 1952⏎\n",
802
- " │ │ ⏎\n",
803
- " │ │ Question: Who was the maternal grandfather of George Washington?⏎\n",
804
- " │ │ Are follow up questions needed here: Yes.⏎\n",
805
- " │ │ Follow up: Who was the mother of George Washington?⏎\n",
806
- " │ │ Intermediate answer: The mother of George Washington was Mary Ball Washington.⏎\n",
807
- " │ │ Follow up: Who was the father of Mary Ball Washington?⏎\n",
808
- " │ │ Intermediate answer: The father of Mary Ball Washington was Joseph Ball.⏎\n",
809
- " │ │ So the final answer is: Joseph Ball⏎\n",
810
- " │ │ ⏎\n",
811
- " │ │ Question: Are both the directors of Jaws and Casino Royale from the same country?⏎\n",
812
- " │ │ Are follow up questions needed here: Yes.⏎\n",
813
- " │ │ Follow up: Who is the director of Jaws?⏎\n",
814
- " │ │ Intermediate answer: The director of Jaws is Steven Spielberg.⏎\n",
815
- " │ │ Follow up: Where is Steven Spielberg from?⏎\n",
816
- " │ │ Intermediate answer: The United States.⏎\n",
817
- " │ │ Follow up: Who is the director of Casino Royale?⏎\n",
818
- " │ │ Intermediate answer: The director of Casino Royale is Martin Campbell.⏎\n",
819
- " │ │ Follow up: Where is Martin Campbell from?⏎\n",
820
- " │ │ Intermediate answer: New Zealand.⏎\n",
821
- " │ │ So the final answer is: No⏎\n",
822
- " │ │ ⏎\n",
823
- " │ │ Question: What is the zip code of the city where George Washington was born?⏎\n",
824
- " │ │ Are followup questions needed here: Yes.⏎\n",
825
- " │ │ Follow up: What city was George Washington born in?⏎\n",
826
- " │ │ Intermediate answer: Westmoreland County, VA⏎\n",
827
- " │ │ Follow up: What is the zip code of Westmoreland County, VA?⏎\n",
828
- " │ │ Intermediate answer: ZIP Codes in Westmoreland County VA · 22443 · 22520 · 22469 · 22488 · 22442 · 22524 · 22529 · 22558 ...⏎\n",
829
- " │ │ \u001b[0m\n",
830
- " │ └── \u001b[38;5;5mPrompted\u001b[0m/3/2\u001b[0m ⇒ \u001b[38;5;2msucceeded\u001b[0m \u001b[38;5;15m2023-02-27 14:18:28Z\u001b[2m\u001b[0m\n",
831
- " ├── \u001b[38;5;5mResult\u001b[0m/4/1\u001b[0m ⇒ \u001b[38;5;2mstarted\u001b[0m \u001b[38;5;15m2023-02-27 14:18:28Z\u001b[2m\u001b[0m ⧖ \u001b[38;5;4m0.006s\u001b[2m\u001b[0m\n",
832
- " │ ├── \u001b[38;5;4mresult\u001b[0m: So the final answer is: 22443, 22520, 22469, 22488, 22442, 22524, 22529, 22558\u001b[0m\n",
833
- " │ └── \u001b[38;5;5mResult\u001b[0m/4/2\u001b[0m ⇒ \u001b[38;5;2msucceeded\u001b[0m \u001b[38;5;15m2023-02-27 14:18:28Z\u001b[2m\u001b[0m\n",
834
- " └── \u001b[38;5;5m<class '__main__.SelfAsk'>\u001b[0m/5\u001b[0m ⇒ \u001b[38;5;2msucceeded\u001b[0m \u001b[38;5;15m2023-02-27 14:18:28Z\u001b[2m\u001b[0m\n",
835
- "\n",
836
- "\u001b[38;5;15m17a9eb4a-7068-479d-a6f5-3204940ce3f6\u001b[1m\u001b[0m\n",
837
- "└── \u001b[38;5;5mselfask\u001b[0m/1\u001b[0m ⇒ \u001b[38;5;2mstarted\u001b[0m \u001b[38;5;15m2023-02-27 14:18:10Z\u001b[2m\u001b[0m ⧖ \u001b[38;5;4m18.204s\u001b[2m\u001b[0m\n",
838
- " └── \u001b[38;5;5mselfask\u001b[0m/2\u001b[0m ⇒ \u001b[38;5;2msucceeded\u001b[0m \u001b[38;5;15m2023-02-27 14:18:28Z\u001b[2m\u001b[0m\n",
839
- "\n"
840
- ]
841
- }
842
- ],
843
- "source": [
844
- "minichain.show_log(\"selfask.log\")"
845
- ]
846
  }
847
  ],
848
  "metadata": {
849
  "jupytext": {
850
- "cell_metadata_filter": "tags,-all"
851
  },
852
  "kernelspec": {
853
  "display_name": "minichain",
 
1
  {
2
  "cells": [
3
  {
4
+ "cell_type": "code",
5
+ "execution_count": null,
6
+ "id": "12eeb7f2",
7
+ "metadata": {
8
+ "lines_to_next_cell": 0
9
+ },
10
+ "outputs": [],
11
+ "source": []
12
  },
13
  {
14
  "cell_type": "code",
15
  "execution_count": 1,
16
+ "id": "0290a7f2",
17
  "metadata": {
18
  "execution": {
19
+ "iopub.execute_input": "2023-03-22T17:00:59.828303Z",
20
+ "iopub.status.busy": "2023-03-22T17:00:59.827586Z",
21
+ "iopub.status.idle": "2023-03-22T17:00:59.836907Z",
22
+ "shell.execute_reply": "2023-03-22T17:00:59.836357Z"
23
  }
24
  },
25
  "outputs": [],
26
  "source": [
27
+ "desc = \"\"\"\n",
28
+ "### Self-Ask\n",
29
+ "\n",
30
+ " Notebook implementation of the self-ask + Google tool use prompt.\n",
31
+ "\n",
32
+ " (Adapted from [Self-Ask repo](https://github.com/ofirpress/self-ask))\n",
33
+ "\"\"\""
34
  ]
35
  },
36
  {
37
  "cell_type": "markdown",
38
+ "id": "29b0fe2a",
39
  "metadata": {},
40
  "source": [
41
+ "$"
42
  ]
43
  },
44
  {
45
  "cell_type": "code",
46
  "execution_count": 2,
47
+ "id": "f3544dba",
48
  "metadata": {
49
  "execution": {
50
+ "iopub.execute_input": "2023-03-22T17:00:59.839279Z",
51
+ "iopub.status.busy": "2023-03-22T17:00:59.839084Z",
52
+ "iopub.status.idle": "2023-03-22T17:01:01.144851Z",
53
+ "shell.execute_reply": "2023-03-22T17:01:01.144194Z"
54
+ }
 
55
  },
56
  "outputs": [],
57
  "source": [
58
+ "from dataclasses import dataclass, replace\n",
59
+ "from typing import Optional\n",
60
+ "from minichain import prompt, show, OpenAI, Google"
61
  ]
62
  },
63
  {
64
  "cell_type": "code",
65
  "execution_count": 3,
66
+ "id": "a89961cf",
67
  "metadata": {
68
  "execution": {
69
+ "iopub.execute_input": "2023-03-22T17:01:01.147570Z",
70
+ "iopub.status.busy": "2023-03-22T17:01:01.147250Z",
71
+ "iopub.status.idle": "2023-03-22T17:01:01.151110Z",
72
+ "shell.execute_reply": "2023-03-22T17:01:01.150563Z"
73
+ }
 
74
  },
75
  "outputs": [],
76
  "source": [
77
  "@dataclass\n",
78
+ "class State:\n",
79
+ " question: str\n",
80
+ " history: str = \"\"\n",
81
+ " next_query: Optional[str] = None\n",
82
+ " final_answer: Optional[str] = None"
83
  ]
84
  },
85
  {
86
  "cell_type": "code",
87
  "execution_count": 4,
88
+ "id": "0ebdb069",
89
  "metadata": {
90
  "execution": {
91
+ "iopub.execute_input": "2023-03-22T17:01:01.153276Z",
92
+ "iopub.status.busy": "2023-03-22T17:01:01.152995Z",
93
+ "iopub.status.idle": "2023-03-22T17:01:01.156865Z",
94
+ "shell.execute_reply": "2023-03-22T17:01:01.156229Z"
95
+ },
96
+ "lines_to_next_cell": 1
97
  },
98
  "outputs": [],
99
  "source": [
100
+ "@prompt(OpenAI(),\n",
101
+ " template_file = \"selfask.pmpt.tpl\",\n",
102
+ " stop_template = \"\\nIntermediate answer:\")\n",
103
+ "def self_ask(model, state):\n",
104
+ " out = model(state)\n",
105
+ " res = out.split(\":\", 1)[1]\n",
106
+ " if out.startswith(\"Follow up:\"):\n",
107
+ " return replace(state, next_query=res)\n",
108
+ " elif out.startswith(\"So the final answer is:\"):\n",
109
+ " return replace(state, final_answer=res)"
 
 
110
  ]
111
  },
112
  {
113
  "cell_type": "code",
114
  "execution_count": 5,
115
+ "id": "a8fdbdcf",
116
  "metadata": {
117
  "execution": {
118
+ "iopub.execute_input": "2023-03-22T17:01:01.159342Z",
119
+ "iopub.status.busy": "2023-03-22T17:01:01.159137Z",
120
+ "iopub.status.idle": "2023-03-22T17:01:01.162472Z",
121
+ "shell.execute_reply": "2023-03-22T17:01:01.162014Z"
122
  },
123
  "lines_to_next_cell": 1
124
  },
125
  "outputs": [],
126
  "source": [
127
+ "@prompt(Google())\n",
128
+ "def google(model, state):\n",
129
+ " if state.next_query is None:\n",
130
+ " return state\n",
131
+ " \n",
132
+ " result = model(state.next_query)\n",
133
+ " return State(state.question,\n",
134
+ " state.history + \"\\nIntermediate answer: \" + result + \"\\n\")"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
  ]
136
  },
137
  {
138
  "cell_type": "code",
139
  "execution_count": 6,
140
+ "id": "82883cd6",
141
  "metadata": {
142
  "execution": {
143
+ "iopub.execute_input": "2023-03-22T17:01:01.164441Z",
144
+ "iopub.status.busy": "2023-03-22T17:01:01.164266Z",
145
+ "iopub.status.idle": "2023-03-22T17:01:01.167251Z",
146
+ "shell.execute_reply": "2023-03-22T17:01:01.166820Z"
147
+ },
148
+ "lines_to_next_cell": 1
149
  },
150
  "outputs": [],
151
  "source": [
152
+ "def selfask(question):\n",
153
+ " state = State(question)\n",
 
 
154
  " for i in range(3):\n",
155
+ " state = self_ask(state)\n",
156
+ " state = google(state)\n",
157
+ " return state"
158
+ ]
159
+ },
160
+ {
161
+ "cell_type": "markdown",
162
+ "id": "4f9bf472",
163
+ "metadata": {},
164
+ "source": [
165
+ "$"
166
  ]
167
  },
168
  {
169
  "cell_type": "code",
170
  "execution_count": 7,
171
+ "id": "20e37090",
172
  "metadata": {
173
  "execution": {
174
+ "iopub.execute_input": "2023-03-22T17:01:01.169337Z",
175
+ "iopub.status.busy": "2023-03-22T17:01:01.169152Z",
176
+ "iopub.status.idle": "2023-03-22T17:01:01.506567Z",
177
+ "shell.execute_reply": "2023-03-22T17:01:01.505941Z"
178
  }
179
  },
180
  "outputs": [
 
182
  "name": "stdout",
183
  "output_type": "stream",
184
  "text": [
185
+ "Running on local URL: http://127.0.0.1:7861\n",
186
+ "\n",
187
+ "To create a public link, set `share=True` in `launch()`.\n"
 
 
 
 
 
188
  ]
189
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
190
  {
191
  "data": {
192
  "text/html": [
193
+ "<div><iframe src=\"http://127.0.0.1:7861/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
194
  ],
195
  "text/plain": [
196
+ "<IPython.core.display.HTML object>"
197
  ]
198
  },
 
199
  "metadata": {},
200
+ "output_type": "display_data"
201
  }
202
  ],
203
  "source": [
204
+ "gradio = show(selfask,\n",
205
+ " examples=[\"What is the zip code of the city where George Washington was born?\"],\n",
206
+ " subprompts=[self_ask, google] * 3,\n",
207
+ " description=desc,\n",
208
+ " code=open(\"selfask.py\", \"r\").read().split(\"$\")[1].strip().strip(\"#\").strip(),\n",
209
+ " out_type=\"json\"\n",
210
+ " )\n",
211
+ "if __name__ == \"__main__\":\n",
212
+ " gradio.launch()"
 
 
 
 
 
 
213
  ]
214
  },
215
  {
216
  "cell_type": "code",
217
+ "execution_count": null,
218
+ "id": "fdf780fc",
219
+ "metadata": {},
220
+ "outputs": [],
221
+ "source": []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
222
  }
223
  ],
224
  "metadata": {
225
  "jupytext": {
226
+ "cell_metadata_filter": "-all"
227
  },
228
  "kernelspec": {
229
  "display_name": "minichain",
selfask.pmpt.tpl CHANGED
@@ -34,6 +34,6 @@ Follow up: Where is Martin Campbell from?
34
  Intermediate answer: New Zealand.
35
  So the final answer is: No
36
 
37
- Question: {{input}}
38
- Are followup questions needed here: {% if agent_scratchpad %}Yes{%else%}No{% endif %}.
39
- {{suffix}}
 
34
  Intermediate answer: New Zealand.
35
  So the final answer is: No
36
 
37
+ Question: {{question}}
38
+ Are followup questions needed here: Yes
39
+ {{history}}
selfask.py CHANGED
@@ -1,83 +1,64 @@
1
- # Notebook implementation of the self-ask + Google tool use prompt.
2
- # Adapted from https://github.com/ofirpress/self-ask
3
 
4
- from dataclasses import dataclass
 
5
 
6
- from parsita import *
7
 
8
- import minichain
 
9
 
10
- # Define the state of the bot.
11
 
12
- @dataclass
13
- class IntermediateState:
14
- s: str
15
 
16
- @dataclass
17
- class FinalState:
18
- s: str
19
 
20
  @dataclass
21
- class Out:
22
- echo: str
23
- state: FinalState | IntermediateState
24
-
25
-
26
- # Self Ask Prompt
27
-
28
- class SelfAsk(minichain.TemplatePrompt[Out]):
29
- template_file = "selfask.pmpt.tpl"
30
- stop_template = "\nIntermediate answer:"
31
-
32
- # Parsita parser.
33
- class Parser(TextParsers):
34
- follow = (lit("Follow up:") >> reg(r".*")) > IntermediateState
35
- finish = (lit("So the final answer is: ") >> reg(r".*")) > FinalState
36
- response = follow | finish
37
-
38
- def parse(self, response: str, inp) -> Out:
39
- return Out(
40
- self.prompt(inp).prompt + response,
41
- self.Parser.response.parse(response).or_die(),
42
- )
43
-
44
- # Runtime loop
45
-
46
- def selfask(inp: str, openai, google) -> str:
47
- prompt1 = SelfAsk(openai)
48
- prompt2 = minichain.SimplePrompt(google)
49
- suffix = ""
50
  for i in range(3):
51
- out = prompt1(dict(input=inp, suffix=suffix, agent_scratchpad=True))
52
-
53
- if isinstance(out.state, FinalState):
54
- break
55
- suffix += out.echo
56
- out2 = prompt2(out.state.s)
57
- suffix += "\nIntermediate answer: " + out2 + "\n"
58
- return out.state.s
59
-
60
-
61
- with minichain.start_chain("selfask") as backend:
62
- result = selfask(
63
- "What is the zip code of the city where George Washington was born?",
64
- backend.OpenAI(),
65
- backend.Google(),
66
- )
67
- print(result)
68
 
69
- # View prompt examples.
70
 
71
- # + tags=["hide_inp"]
72
- SelfAsk().show(
73
- {
74
- "input": "What is the zip code of the city where George Washington was born?",
75
- "agent_scratchpad": True,
76
- },
77
- "Follow up: Where was George Washington born?",
78
- )
79
- # -
80
 
81
- # View log.
82
 
83
- minichain.show_log("selfask.log")
 
 
 
1
 
2
+ desc = """
3
+ ### Self-Ask
4
 
5
+ Notebook implementation of the self-ask + Google tool use prompt.
6
 
7
+ (Adapted from [Self-Ask repo](https://github.com/ofirpress/self-ask))
8
+ """
9
 
10
+ # $
11
 
12
+ from dataclasses import dataclass, replace
13
+ from typing import Optional
14
+ from minichain import prompt, show, OpenAI, Google
15
 
 
 
 
16
 
17
  @dataclass
18
+ class State:
19
+ question: str
20
+ history: str = ""
21
+ next_query: Optional[str] = None
22
+ final_answer: Optional[str] = None
23
+
24
+
25
+ @prompt(OpenAI(),
26
+ template_file = "selfask.pmpt.tpl",
27
+ stop_template = "\nIntermediate answer:")
28
+ def self_ask(model, state):
29
+ out = model(state)
30
+ res = out.split(":", 1)[1]
31
+ if out.startswith("Follow up:"):
32
+ return replace(state, next_query=res)
33
+ elif out.startswith("So the final answer is:"):
34
+ return replace(state, final_answer=res)
35
+
36
+ @prompt(Google())
37
+ def google(model, state):
38
+ if state.next_query is None:
39
+ return state
40
+
41
+ result = model(state.next_query)
42
+ return State(state.question,
43
+ state.history + "\nIntermediate answer: " + result + "\n")
44
+
45
+ def selfask(question):
46
+ state = State(question)
47
  for i in range(3):
48
+ state = self_ask(state)
49
+ state = google(state)
50
+ return state
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
 
52
+ # $
53
 
54
+ gradio = show(selfask,
55
+ examples=["What is the zip code of the city where George Washington was born?"],
56
+ subprompts=[self_ask, google] * 3,
57
+ description=desc,
58
+ code=open("selfask.py", "r").read().split("$")[1].strip().strip("#").strip(),
59
+ out_type="json"
60
+ )
61
+ if __name__ == "__main__":
62
+ gradio.launch()
63
 
 
64
 
 
stats.ipynb CHANGED
@@ -1,29 +1,62 @@
1
  {
2
  "cells": [
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  {
4
  "cell_type": "markdown",
5
- "id": "92d83adc",
6
  "metadata": {},
7
  "source": [
8
- "Information extraction from a typed data specification."
9
  ]
10
  },
11
  {
12
  "cell_type": "code",
13
- "execution_count": 1,
14
- "id": "1616bc41",
15
  "metadata": {
16
  "execution": {
17
- "iopub.execute_input": "2023-03-02T14:15:54.551033Z",
18
- "iopub.status.busy": "2023-03-02T14:15:54.550855Z",
19
- "iopub.status.idle": "2023-03-02T14:15:54.747988Z",
20
- "shell.execute_reply": "2023-03-02T14:15:54.747137Z"
21
  },
22
  "lines_to_next_cell": 1
23
  },
24
  "outputs": [],
25
  "source": [
26
- "import minichain\n",
27
  "from dataclasses import dataclass\n",
28
  "from typing import List\n",
29
  "from enum import Enum"
@@ -31,7 +64,7 @@
31
  },
32
  {
33
  "cell_type": "markdown",
34
- "id": "e514df46",
35
  "metadata": {},
36
  "source": [
37
  "Data specification"
@@ -39,14 +72,14 @@
39
  },
40
  {
41
  "cell_type": "code",
42
- "execution_count": 2,
43
- "id": "715ea26d",
44
  "metadata": {
45
  "execution": {
46
- "iopub.execute_input": "2023-03-02T14:15:54.753667Z",
47
- "iopub.status.busy": "2023-03-02T14:15:54.752198Z",
48
- "iopub.status.idle": "2023-03-02T14:15:54.760779Z",
49
- "shell.execute_reply": "2023-03-02T14:15:54.760045Z"
50
  }
51
  },
52
  "outputs": [],
@@ -55,138 +88,100 @@
55
  " POINTS = 1\n",
56
  " REBOUNDS = 2\n",
57
  " ASSISTS = 3\n",
58
- " \n",
59
  "@dataclass\n",
60
  "class Stat:\n",
61
  " value: int\n",
62
  " stat: StatType\n",
63
- " \n",
64
  "@dataclass\n",
65
  "class Player:\n",
66
  " player: str\n",
67
  " stats: List[Stat]"
68
  ]
69
  },
70
- {
71
- "cell_type": "markdown",
72
- "id": "ed9914df",
73
- "metadata": {},
74
- "source": [
75
- "Code"
76
- ]
77
- },
78
  {
79
  "cell_type": "code",
80
- "execution_count": 3,
81
- "id": "446120b3",
82
  "metadata": {
83
  "execution": {
84
- "iopub.execute_input": "2023-03-02T14:15:54.766815Z",
85
- "iopub.status.busy": "2023-03-02T14:15:54.765321Z",
86
- "iopub.status.idle": "2023-03-02T14:15:54.771533Z",
87
- "shell.execute_reply": "2023-03-02T14:15:54.770697Z"
88
- }
 
89
  },
90
  "outputs": [],
91
  "source": [
92
- "class ExtractionPrompt(minichain.TypedTemplatePrompt):\n",
93
- " template_file = \"stats.pmpt.tpl\"\n",
94
- " Out = Player"
 
95
  ]
96
  },
97
  {
98
- "cell_type": "code",
99
- "execution_count": 4,
100
- "id": "d8afe793",
101
- "metadata": {
102
- "execution": {
103
- "iopub.execute_input": "2023-03-02T14:15:54.777068Z",
104
- "iopub.status.busy": "2023-03-02T14:15:54.776037Z",
105
- "iopub.status.idle": "2023-03-02T14:16:00.217791Z",
106
- "shell.execute_reply": "2023-03-02T14:16:00.215586Z"
107
- }
108
- },
109
- "outputs": [
110
- {
111
- "name": "stdout",
112
- "output_type": "stream",
113
- "text": [
114
- "Player(player='Joel Embiid', stats=[{'value': 35, 'stat': 'POINTS'}, {'value': 8, 'stat': 'REBOUNDS'}])\n",
115
- "Player(player='James Harden', stats=[{'value': 29, 'stat': 'POINTS'}, {'value': 13, 'stat': 'ASSISTS'}])\n",
116
- "Player(player='Georges Niang', stats=[{'value': 16, 'stat': 'POINTS'}])\n",
117
- "Player(player='Julius Randle', stats=[{'value': 35, 'stat': 'POINTS'}])\n"
118
- ]
119
- }
120
- ],
121
  "source": [
122
- "with minichain.start_chain(\"stats\") as backend:\n",
123
- " p = ExtractionPrompt(backend.OpenAI(max_tokens=512))\n",
124
- " article = open(\"sixers.txt\").read()\n",
125
- " for player in p({\"passage\": article}):\n",
126
- " print(player)"
127
  ]
128
  },
129
  {
130
  "cell_type": "code",
131
  "execution_count": 5,
132
- "id": "b45c5e0b",
133
  "metadata": {
134
  "execution": {
135
- "iopub.execute_input": "2023-03-02T14:16:00.226271Z",
136
- "iopub.status.busy": "2023-03-02T14:16:00.225345Z",
137
- "iopub.status.idle": "2023-03-02T14:16:00.292224Z",
138
- "shell.execute_reply": "2023-03-02T14:16:00.291672Z"
139
- }
 
140
  },
141
  "outputs": [
 
 
 
 
 
 
 
 
 
142
  {
143
  "data": {
144
  "text/html": [
145
- "\n",
146
- "<!-- <link rel=\"stylesheet\" href=\"https://cdn.rawgit.com/Chalarangelo/mini.css/v3.0.1/dist/mini-default.min.css\"> -->\n",
147
- " <main class=\"container\">\n",
148
- "\n",
149
- "<h3>ExtractionPrompt</h3>\n",
150
- "\n",
151
- "<dl>\n",
152
- " <dt>Input:</dt>\n",
153
- " <dd>\n",
154
- "<div class=\"highlight\"><pre><span></span><span class=\"p\">{</span><span class=\"s1\">&#39;passage&#39;</span><span class=\"p\">:</span> <span class=\"s1\">&#39;Harden had 10 rebounds.&#39;</span><span class=\"p\">}</span>\n",
155
- "</pre></div>\n",
156
- "\n",
157
- "\n",
158
- " </dd>\n",
159
- "\n",
160
- " <dt> Full Prompt: </dt>\n",
161
- " <dd>\n",
162
- " <details>\n",
163
- " <summary>Prompt</summary>\n",
164
- " <p>You are a highly intelligent and accurate information extraction system. You take passage as input and your task is to find parts of the passage to answer questions.<br><br><br>You need to classify in to the following types for key: \"player\":<br>String<br><br><br>You need to classify in to the following types for key: \"stats\":<br><br>List<br>You need to classify in to the following types for key: \"value\":<br>Int <br><br>You need to classify in to the following types for key: \"stat\":<br><br><br><br>POINTS<br>REBOUNDS<br>ASSISTS<br><br><br>Only select from the above list.<br><br><br><br><br><br><br><br>[{ \"player\" : \"player\" , \"stats\" : [{ \"value\" : \"value\" , \"stat\" : \"stat\" }] }, ...]<br><br><br><br>Make sure every output is exactly seen in the document. Find as many as you can.<br>You need to output only JSON.<br><br><div style='color:red'>Harden had 10 rebounds.</div><br><br><br>JSON Output: </p>\n",
165
- " </details>\n",
166
- " </dd>\n",
167
- "\n",
168
- " <dt> Response: </dt>\n",
169
- " <dd>\n",
170
- " [{\"player\": \"Harden\", \"stats\": {\"value\": 10, \"stat\": 2}}]\n",
171
- " </dd>\n",
172
- "\n",
173
- " <dt>Value:</dt>\n",
174
- " <dd>\n",
175
- "<div class=\"highlight\"><pre><span></span><span class=\"p\">[</span><span class=\"n\">Player</span><span class=\"p\">(</span><span class=\"n\">player</span><span class=\"o\">=</span><span class=\"s1\">&#39;Harden&#39;</span><span class=\"p\">,</span> <span class=\"n\">stats</span><span class=\"o\">=</span><span class=\"p\">{</span><span class=\"s1\">&#39;value&#39;</span><span class=\"p\">:</span> <span class=\"mi\">10</span><span class=\"p\">,</span> <span class=\"s1\">&#39;stat&#39;</span><span class=\"p\">:</span> <span class=\"mi\">2</span><span class=\"p\">})]</span>\n",
176
- "</pre></div>\n",
177
- "\n",
178
- " </dd>\n",
179
- "</main>\n"
180
  ],
181
  "text/plain": [
182
- "HTML(html='\\n<!-- <link rel=\"stylesheet\" href=\"https://cdn.rawgit.com/Chalarangelo/mini.css/v3.0.1/dist/mini-default.min.css\"> -->\\n <main class=\"container\">\\n\\n<h3>ExtractionPrompt</h3>\\n\\n<dl>\\n <dt>Input:</dt>\\n <dd>\\n<div class=\"highlight\"><pre><span></span><span class=\"p\">{</span><span class=\"s1\">&#39;passage&#39;</span><span class=\"p\">:</span> <span class=\"s1\">&#39;Harden had 10 rebounds.&#39;</span><span class=\"p\">}</span>\\n</pre></div>\\n\\n\\n </dd>\\n\\n <dt> Full Prompt: </dt>\\n <dd>\\n <details>\\n <summary>Prompt</summary>\\n <p>You are a highly intelligent and accurate information extraction system. You take passage as input and your task is to find parts of the passage to answer questions.<br><br><br>You need to classify in to the following types for key: \"player\":<br>String<br><br><br>You need to classify in to the following types for key: \"stats\":<br><br>List<br>You need to classify in to the following types for key: \"value\":<br>Int <br><br>You need to classify in to the following types for key: \"stat\":<br><br><br><br>POINTS<br>REBOUNDS<br>ASSISTS<br><br><br>Only select from the above list.<br><br><br><br><br><br><br><br>[{ \"player\" : \"player\" , \"stats\" : [{ \"value\" : \"value\" , \"stat\" : \"stat\" }] }, ...]<br><br><br><br>Make sure every output is exactly seen in the document. Find as many as you can.<br>You need to output only JSON.<br><br><div style=\\'color:red\\'>Harden had 10 rebounds.</div><br><br><br>JSON Output: </p>\\n </details>\\n </dd>\\n\\n <dt> Response: </dt>\\n <dd>\\n [{\"player\": \"Harden\", \"stats\": {\"value\": 10, \"stat\": 2}}]\\n </dd>\\n\\n <dt>Value:</dt>\\n <dd>\\n<div class=\"highlight\"><pre><span></span><span class=\"p\">[</span><span class=\"n\">Player</span><span class=\"p\">(</span><span class=\"n\">player</span><span class=\"o\">=</span><span class=\"s1\">&#39;Harden&#39;</span><span class=\"p\">,</span> <span class=\"n\">stats</span><span class=\"o\">=</span><span class=\"p\">{</span><span class=\"s1\">&#39;value&#39;</span><span class=\"p\">:</span> <span class=\"mi\">10</span><span class=\"p\">,</span> <span class=\"s1\">&#39;stat&#39;</span><span class=\"p\">:</span> <span class=\"mi\">2</span><span class=\"p\">})]</span>\\n</pre></div>\\n\\n </dd>\\n</main>\\n')"
183
  ]
184
  },
185
- "execution_count": 5,
186
  "metadata": {},
187
- "output_type": "execute_result"
188
  }
189
  ],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
190
  "source": [
191
  "ExtractionPrompt().show({\"passage\": \"Harden had 10 rebounds.\"},\n",
192
  " '[{\"player\": \"Harden\", \"stats\": {\"value\": 10, \"stat\": 2}}]')"
@@ -194,96 +189,16 @@
194
  },
195
  {
196
  "cell_type": "markdown",
197
- "id": "b4528305",
198
  "metadata": {},
199
  "source": [
200
- "View the run log."
201
  ]
202
  },
203
  {
204
- "cell_type": "code",
205
- "execution_count": 6,
206
- "id": "9dd688de",
207
- "metadata": {
208
- "execution": {
209
- "iopub.execute_input": "2023-03-02T14:16:00.294622Z",
210
- "iopub.status.busy": "2023-03-02T14:16:00.294433Z",
211
- "iopub.status.idle": "2023-03-02T14:16:00.316409Z",
212
- "shell.execute_reply": "2023-03-02T14:16:00.315818Z"
213
- }
214
- },
215
- "outputs": [
216
- {
217
- "name": "stderr",
218
- "output_type": "stream",
219
- "text": [
220
- "\u001b[38;5;15mfc682a98-f50a-4837-8b6d-87e843c19732\u001b[1m\u001b[0m\n",
221
- "└── \u001b[38;5;5m<class '__main__.CLIPrompt'>\u001b[0m/1\u001b[0m ⇒ \u001b[38;5;2mstarted\u001b[0m \u001b[38;5;15m2023-02-27 14:12:18Z\u001b[2m\u001b[0m ⧖ \u001b[38;5;4m1.531s\u001b[2m\u001b[0m\n",
222
- " ├── \u001b[38;5;5mInput Function\u001b[0m/2/1\u001b[0m ⇒ \u001b[38;5;2mstarted\u001b[0m \u001b[38;5;15m2023-02-27 14:12:18Z\u001b[2m\u001b[0m ⧖ \u001b[38;5;4m0.003s\u001b[2m\u001b[0m\n",
223
- " │ ├── \u001b[38;5;4minput\u001b[0m: \u001b[0m\n",
224
- " │ │ └── \u001b[38;5;4mquestion\u001b[0m: \"go up one directory, and then into the minichain directory,and list the files in the directory\"\u001b[0m\n",
225
- " │ └── \u001b[38;5;5mInput Function\u001b[0m/2/2\u001b[0m ⇒ \u001b[38;5;2msucceeded\u001b[0m \u001b[38;5;15m2023-02-27 14:12:18Z\u001b[2m\u001b[0m\n",
226
- " ├── \u001b[38;5;5mPrompted\u001b[0m/3/1\u001b[0m ⇒ \u001b[38;5;2mstarted\u001b[0m \u001b[38;5;15m2023-02-27 14:12:18Z\u001b[2m\u001b[0m ⧖ \u001b[38;5;4m1.528s\u001b[2m\u001b[0m\n",
227
- " │ ├── \u001b[38;5;4mprompt\u001b[0m: If someone asks you to perform a task, your job is to come up with a series of bash commands that will perform the task. There is no need to put \"#!/bin/bash\" in your answer. Make sure to reason step by step, using this format:⏎\n",
228
- " │ │ ⏎\n",
229
- " │ │ Question: \"copy the files in the directory named 'target' into a new directory at the same level as target called 'myNewDirectory'\"⏎\n",
230
- " │ │ ⏎\n",
231
- " │ │ I need to take the following actions:⏎\n",
232
- " │ │ - List all files in the directory⏎\n",
233
- " │ │ - Create a new directory⏎\n",
234
- " │ │ - Copy the files from the first directory into the second directory⏎\n",
235
- " │ │ ```bash⏎\n",
236
- " │ │ ls⏎\n",
237
- " │ │ mkdir myNewDirectory⏎\n",
238
- " │ │ cp -r target/* myNewDirectory⏎\n",
239
- " │ │ ```⏎\n",
240
- " │ │ ⏎\n",
241
- " │ │ That is the format. Begin!⏎\n",
242
- " │ │ ⏎\n",
243
- " │ │ Question: \"go up one directory, and then into the minichain directory,and list the files in the directory\"\u001b[0m\n",
244
- " │ └── \u001b[38;5;5mPrompted\u001b[0m/3/2\u001b[0m ⇒ \u001b[38;5;2msucceeded\u001b[0m \u001b[38;5;15m2023-02-27 14:12:19Z\u001b[2m\u001b[0m\n",
245
- " ├── \u001b[38;5;5mResult\u001b[0m/4/1\u001b[0m ⇒ \u001b[38;5;2mstarted\u001b[0m \u001b[38;5;15m2023-02-27 14:12:19Z\u001b[2m\u001b[0m ⧖ \u001b[38;5;4m0.000s\u001b[2m\u001b[0m\n",
246
- " │ ├── \u001b[38;5;4mresult\u001b[0m: ⏎\n",
247
- " │ │ ⏎\n",
248
- " │ │ ```bash⏎\n",
249
- " │ │ cd ..⏎\n",
250
- " │ │ cd minichain⏎\n",
251
- " │ │ ls⏎\n",
252
- " │ │ ```\u001b[0m\n",
253
- " │ └── \u001b[38;5;5mResult\u001b[0m/4/2\u001b[0m ⇒ \u001b[38;5;2msucceeded\u001b[0m \u001b[38;5;15m2023-02-27 14:12:19Z\u001b[2m\u001b[0m\n",
254
- " └── \u001b[38;5;5m<class '__main__.CLIPrompt'>\u001b[0m/5\u001b[0m ⇒ \u001b[38;5;2msucceeded\u001b[0m \u001b[38;5;15m2023-02-27 14:12:19Z\u001b[2m\u001b[0m\n",
255
- "\n",
256
- "\u001b[38;5;15m328e2368-6c0f-4a03-ae78-26aa43a517e3\u001b[1m\u001b[0m\n",
257
- "└── \u001b[38;5;5m<class '__main__.BashPrompt'>\u001b[0m/1\u001b[0m ⇒ \u001b[38;5;2mstarted\u001b[0m \u001b[38;5;15m2023-02-27 14:12:19Z\u001b[2m\u001b[0m ⧖ \u001b[38;5;4m0.006s\u001b[2m\u001b[0m\n",
258
- " ├── \u001b[38;5;5mInput Function\u001b[0m/2/1\u001b[0m ⇒ \u001b[38;5;2mstarted\u001b[0m \u001b[38;5;15m2023-02-27 14:12:19Z\u001b[2m\u001b[0m ⧖ \u001b[38;5;4m0.000s\u001b[2m\u001b[0m\n",
259
- " │ ├── \u001b[38;5;4minput\u001b[0m: \u001b[0m\n",
260
- " │ │ ├── \u001b[38;5;4m0\u001b[0m: cd ..\u001b[0m\n",
261
- " │ │ ├── \u001b[38;5;4m1\u001b[0m: cd minichain\u001b[0m\n",
262
- " │ │ └── \u001b[38;5;4m2\u001b[0m: ls\u001b[0m\n",
263
- " │ └── \u001b[38;5;5mInput Function\u001b[0m/2/2\u001b[0m ⇒ \u001b[38;5;2msucceeded\u001b[0m \u001b[38;5;15m2023-02-27 14:12:19Z\u001b[2m\u001b[0m\n",
264
- " ├── \u001b[38;5;5mPrompted\u001b[0m/3/1\u001b[0m ⇒ \u001b[38;5;2mstarted\u001b[0m \u001b[38;5;15m2023-02-27 14:12:19Z\u001b[2m\u001b[0m ⧖ \u001b[38;5;4m0.005s\u001b[2m\u001b[0m\n",
265
- " │ ├── \u001b[38;5;4mprompt\u001b[0m: cd ..;cd minichain;ls\u001b[0m\n",
266
- " │ └── \u001b[38;5;5mPrompted\u001b[0m/3/2\u001b[0m ⇒ \u001b[38;5;2msucceeded\u001b[0m \u001b[38;5;15m2023-02-27 14:12:19Z\u001b[2m\u001b[0m\n",
267
- " ├── \u001b[38;5;5mResult\u001b[0m/4/1\u001b[0m ⇒ \u001b[38;5;2mstarted\u001b[0m \u001b[38;5;15m2023-02-27 14:12:19Z\u001b[2m\u001b[0m ⧖ \u001b[38;5;4m0.000s\u001b[2m\u001b[0m\n",
268
- " │ ├── \u001b[38;5;4mresult\u001b[0m: #backend.py#⏎\n",
269
- " │ │ backend.py⏎\n",
270
- " │ │ base.py⏎\n",
271
- " │ │ __init__.py⏎\n",
272
- " │ │ lang.py⏎\n",
273
- " │ │ prompts.py⏎\n",
274
- " │ │ __pycache__⏎\n",
275
- " │ │ templates⏎\n",
276
- " │ │ \u001b[0m\n",
277
- " │ └── \u001b[38;5;5mResult\u001b[0m/4/2\u001b[0m ⇒ \u001b[38;5;2msucceeded\u001b[0m \u001b[38;5;15m2023-02-27 14:12:19Z\u001b[2m\u001b[0m\n",
278
- " └── \u001b[38;5;5m<class '__main__.BashPrompt'>\u001b[0m/5\u001b[0m ⇒ \u001b[38;5;2msucceeded\u001b[0m \u001b[38;5;15m2023-02-27 14:12:19Z\u001b[2m\u001b[0m\n",
279
- "\n",
280
- "\u001b[38;5;15mca5f4b25-55ca-441d-a0d2-f39ad0bca2d0\u001b[1m\u001b[0m\n",
281
- "└── \u001b[38;5;5mbash\u001b[0m/1\u001b[0m ⇒ \u001b[38;5;2mstarted\u001b[0m \u001b[38;5;15m2023-02-27 14:12:17Z\u001b[2m\u001b[0m ⧖ \u001b[38;5;4m1.850s\u001b[2m\u001b[0m\n",
282
- " └── \u001b[38;5;5mbash\u001b[0m/2\u001b[0m ⇒ \u001b[38;5;2msucceeded\u001b[0m \u001b[38;5;15m2023-02-27 14:12:19Z\u001b[2m\u001b[0m\n",
283
- "\n"
284
- ]
285
- }
286
- ],
287
  "source": [
288
  "minichain.show_log(\"bash.log\")"
289
  ]
 
1
  {
2
  "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": null,
6
+ "id": "f34e932d",
7
+ "metadata": {
8
+ "lines_to_next_cell": 0
9
+ },
10
+ "outputs": [],
11
+ "source": []
12
+ },
13
+ {
14
+ "cell_type": "code",
15
+ "execution_count": 1,
16
+ "id": "12c38ff0",
17
+ "metadata": {
18
+ "execution": {
19
+ "iopub.execute_input": "2023-03-22T17:01:04.041687Z",
20
+ "iopub.status.busy": "2023-03-22T17:01:04.040967Z",
21
+ "iopub.status.idle": "2023-03-22T17:01:04.062830Z",
22
+ "shell.execute_reply": "2023-03-22T17:01:04.060675Z"
23
+ }
24
+ },
25
+ "outputs": [],
26
+ "source": [
27
+ "desc = \"\"\"\n",
28
+ "### Typed Extraction\n",
29
+ "\n",
30
+ "Information extraction that is automatically generated from a typed specification. [[Code](https://github.com/srush/MiniChain/blob/main/examples/stats.py)]\n",
31
+ "\n",
32
+ "(Novel to MiniChain)\n",
33
+ "\"\"\""
34
+ ]
35
+ },
36
  {
37
  "cell_type": "markdown",
38
+ "id": "7c3125d1",
39
  "metadata": {},
40
  "source": [
41
+ "$"
42
  ]
43
  },
44
  {
45
  "cell_type": "code",
46
+ "execution_count": 2,
47
+ "id": "fafef296",
48
  "metadata": {
49
  "execution": {
50
+ "iopub.execute_input": "2023-03-22T17:01:04.071923Z",
51
+ "iopub.status.busy": "2023-03-22T17:01:04.071227Z",
52
+ "iopub.status.idle": "2023-03-22T17:01:05.411226Z",
53
+ "shell.execute_reply": "2023-03-22T17:01:05.410575Z"
54
  },
55
  "lines_to_next_cell": 1
56
  },
57
  "outputs": [],
58
  "source": [
59
+ "from minichain import prompt, show, type_to_prompt, OpenAI\n",
60
  "from dataclasses import dataclass\n",
61
  "from typing import List\n",
62
  "from enum import Enum"
 
64
  },
65
  {
66
  "cell_type": "markdown",
67
+ "id": "defad07f",
68
  "metadata": {},
69
  "source": [
70
  "Data specification"
 
72
  },
73
  {
74
  "cell_type": "code",
75
+ "execution_count": 3,
76
+ "id": "b28d3bef",
77
  "metadata": {
78
  "execution": {
79
+ "iopub.execute_input": "2023-03-22T17:01:05.414380Z",
80
+ "iopub.status.busy": "2023-03-22T17:01:05.413863Z",
81
+ "iopub.status.idle": "2023-03-22T17:01:05.418873Z",
82
+ "shell.execute_reply": "2023-03-22T17:01:05.418413Z"
83
  }
84
  },
85
  "outputs": [],
 
88
  " POINTS = 1\n",
89
  " REBOUNDS = 2\n",
90
  " ASSISTS = 3\n",
91
+ "\n",
92
  "@dataclass\n",
93
  "class Stat:\n",
94
  " value: int\n",
95
  " stat: StatType\n",
96
+ "\n",
97
  "@dataclass\n",
98
  "class Player:\n",
99
  " player: str\n",
100
  " stats: List[Stat]"
101
  ]
102
  },
 
 
 
 
 
 
 
 
103
  {
104
  "cell_type": "code",
105
+ "execution_count": 4,
106
+ "id": "7e79dbb5",
107
  "metadata": {
108
  "execution": {
109
+ "iopub.execute_input": "2023-03-22T17:01:05.420896Z",
110
+ "iopub.status.busy": "2023-03-22T17:01:05.420709Z",
111
+ "iopub.status.idle": "2023-03-22T17:01:05.423985Z",
112
+ "shell.execute_reply": "2023-03-22T17:01:05.423565Z"
113
+ },
114
+ "lines_to_next_cell": 1
115
  },
116
  "outputs": [],
117
  "source": [
118
+ "@prompt(OpenAI(), template_file=\"stats.pmpt.tpl\", parser=\"json\")\n",
119
+ "def stats(model, passage):\n",
120
+ " out = model(dict(passage=passage, typ=type_to_prompt(Player)))\n",
121
+ " return [Player(**j) for j in out] "
122
  ]
123
  },
124
  {
125
+ "cell_type": "markdown",
126
+ "id": "ecc90cb1",
127
+ "metadata": {},
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
  "source": [
129
+ "$"
 
 
 
 
130
  ]
131
  },
132
  {
133
  "cell_type": "code",
134
  "execution_count": 5,
135
+ "id": "73cfa15f",
136
  "metadata": {
137
  "execution": {
138
+ "iopub.execute_input": "2023-03-22T17:01:05.426096Z",
139
+ "iopub.status.busy": "2023-03-22T17:01:05.425913Z",
140
+ "iopub.status.idle": "2023-03-22T17:01:05.738646Z",
141
+ "shell.execute_reply": "2023-03-22T17:01:05.737900Z"
142
+ },
143
+ "lines_to_next_cell": 2
144
  },
145
  "outputs": [
146
+ {
147
+ "name": "stdout",
148
+ "output_type": "stream",
149
+ "text": [
150
+ "Running on local URL: http://127.0.0.1:7861\n",
151
+ "\n",
152
+ "To create a public link, set `share=True` in `launch()`.\n"
153
+ ]
154
+ },
155
  {
156
  "data": {
157
  "text/html": [
158
+ "<div><iframe src=\"http://127.0.0.1:7861/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
  ],
160
  "text/plain": [
161
+ "<IPython.core.display.HTML object>"
162
  ]
163
  },
 
164
  "metadata": {},
165
+ "output_type": "display_data"
166
  }
167
  ],
168
+ "source": [
169
+ "article = open(\"sixers.txt\").read()\n",
170
+ "gradio = show(lambda passage: stats(passage),\n",
171
+ " examples=[article],\n",
172
+ " subprompts=[stats],\n",
173
+ " out_type=\"json\",\n",
174
+ " description=desc,\n",
175
+ " code=open(\"stats.py\", \"r\").read().split(\"$\")[1].strip().strip(\"#\").strip(),\n",
176
+ ")\n",
177
+ "if __name__ == \"__main__\":\n",
178
+ " gradio.launch()"
179
+ ]
180
+ },
181
+ {
182
+ "cell_type": "markdown",
183
+ "id": "c2c3c29a",
184
+ "metadata": {},
185
  "source": [
186
  "ExtractionPrompt().show({\"passage\": \"Harden had 10 rebounds.\"},\n",
187
  " '[{\"player\": \"Harden\", \"stats\": {\"value\": 10, \"stat\": 2}}]')"
 
189
  },
190
  {
191
  "cell_type": "markdown",
192
+ "id": "d6453878",
193
  "metadata": {},
194
  "source": [
195
+ "# View the run log."
196
  ]
197
  },
198
  {
199
+ "cell_type": "markdown",
200
+ "id": "4439426d",
201
+ "metadata": {},
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
202
  "source": [
203
  "minichain.show_log(\"bash.log\")"
204
  ]
stats.py CHANGED
@@ -9,7 +9,7 @@ Information extraction that is automatically generated from a typed specificatio
9
 
10
  # $
11
 
12
- import minichain
13
  from dataclasses import dataclass
14
  from typing import List
15
  from enum import Enum
@@ -34,31 +34,25 @@ class Player:
34
  # -
35
 
36
 
37
- # Code
38
-
39
- class ExtractionPrompt(minichain.TypedTemplatePrompt):
40
- template_file = "stats.pmpt.tpl"
41
- Out = Player
42
-
43
-
44
- with minichain.start_chain("stats") as backend:
45
- prompt = ExtractionPrompt(backend.OpenAI(max_tokens=512))
46
 
47
  # $
48
 
49
-
50
  article = open("sixers.txt").read()
51
- gradio = prompt.to_gradio(fields =["passage"],
52
- examples=[article],
53
- out_type="json",
54
- description=desc,
55
- code=open("stats.py", "r").read().split("$")[1].strip().strip("#").strip(),
56
- templates=[open("stats.pmpt.tpl")]
57
  )
58
  if __name__ == "__main__":
59
  gradio.launch()
60
 
61
-
62
  # ExtractionPrompt().show({"passage": "Harden had 10 rebounds."},
63
  # '[{"player": "Harden", "stats": {"value": 10, "stat": 2}}]')
64
 
 
9
 
10
  # $
11
 
12
+ from minichain import prompt, show, type_to_prompt, OpenAI
13
  from dataclasses import dataclass
14
  from typing import List
15
  from enum import Enum
 
34
  # -
35
 
36
 
37
+ @prompt(OpenAI(), template_file="stats.pmpt.tpl", parser="json")
38
+ def stats(model, passage):
39
+ out = model(dict(passage=passage, typ=type_to_prompt(Player)))
40
+ return [Player(**j) for j in out]
 
 
 
 
 
41
 
42
  # $
43
 
 
44
  article = open("sixers.txt").read()
45
+ gradio = show(lambda passage: stats(passage),
46
+ examples=[article],
47
+ subprompts=[stats],
48
+ out_type="json",
49
+ description=desc,
50
+ code=open("stats.py", "r").read().split("$")[1].strip().strip("#").strip(),
51
  )
52
  if __name__ == "__main__":
53
  gradio.launch()
54
 
55
+
56
  # ExtractionPrompt().show({"passage": "Harden had 10 rebounds."},
57
  # '[{"player": "Harden", "stats": {"value": 10, "stat": 2}}]')
58
 
temp ADDED
Binary file (20.5 kB). View file
 
temp.log CHANGED
Binary files a/temp.log and b/temp.log differ
 
test ADDED
Binary file (106 kB). View file
 
test.log ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {"action_status": "started", "timestamp": 1679500877.6194744, "task_uuid": "11976481-763e-4847-94c2-142c65608e13", "action_type": "test", "task_level": [1]}
2
+ {"action_status": "started", "timestamp": 1679500877.6206672, "task_uuid": "e158df54-9a51-4087-ad85-9af5a8b98a6c", "action_type": "<function math_prompt at 0x7f5ea80eb880>", "task_level": [1]}
3
+ {"prompt": "#### Question:\n\n* What is 37593 * 67?\n\n#### Code:\n\n```python\nprint(37593 * 67)\n```\n\n#### Question:\n\n* Janet's ducks lay 16 eggs per day. She eats three for breakfast every morning and bakes muffins for her friends every day with four. She sells the remainder at the farmers' market daily for $2 per fresh duck egg. How much in dollars does she make every day at the farmers' market?\n\n#### Code:\n\n```python\nprint((16-3-4)*2)\n```\n\n#### Question:\n\n* How many of the integers between 0 and 99 inclusive are divisible by 8?\n\n#### Code:\n\n```python\ncount = 0\nfor i in range(0, 99+1):\n if i % 8 == 0: count += 1\nprint(count)\n```\n\n#### Question:\n\n* A robe takes 2 bolts of blue fiber and half that much white fiber. How many bolts in total does it take?\n\n#### Code:\n\n```python\nprint(2 + 2/2)\n```\n\n#### Question:\n\n* What is the sum of the powers of 3 (3^i) that are smaller than 100?\n\n#### Code:", "action_status": "started", "timestamp": 1679500877.6207328, "task_uuid": "e158df54-9a51-4087-ad85-9af5a8b98a6c", "action_type": "Prompted", "task_level": [2, 1]}
4
+ {"action_status": "succeeded", "timestamp": 1679500877.6600158, "task_uuid": "e158df54-9a51-4087-ad85-9af5a8b98a6c", "action_type": "Prompted", "task_level": [2, 2]}
5
+ {"result": "```python\ntotal = 0\nfor i in range(1, 100):\n if 3**i < 100:\n total += 3**i\nprint(total)\n```", "action_status": "started", "timestamp": 1679500877.6601174, "task_uuid": "e158df54-9a51-4087-ad85-9af5a8b98a6c", "action_type": "Response", "task_level": [3, 1]}
6
+ {"action_status": "succeeded", "timestamp": 1679500877.6601753, "task_uuid": "e158df54-9a51-4087-ad85-9af5a8b98a6c", "action_type": "Response", "task_level": [3, 2]}
7
+ {"action_status": "succeeded", "timestamp": 1679500877.6602166, "task_uuid": "e158df54-9a51-4087-ad85-9af5a8b98a6c", "action_type": "<function math_prompt at 0x7f5ea80eb880>", "task_level": [4]}
8
+ {"action_status": "started", "timestamp": 1679500877.6603165, "task_uuid": "d417ec4b-3b25-4f33-a8b4-b3e5025652af", "action_type": "<function python at 0x7f5ea7231900>", "task_level": [1]}
9
+ {"prompt": "```python\ntotal = 0\nfor i in range(1, 100):\n if 3**i < 100:\n total += 3**i\nprint(total)\n```", "action_status": "started", "timestamp": 1679500877.6605005, "task_uuid": "d417ec4b-3b25-4f33-a8b4-b3e5025652af", "action_type": "Prompted", "task_level": [2, 1]}
10
+ {"action_status": "succeeded", "timestamp": 1679500877.660738, "task_uuid": "d417ec4b-3b25-4f33-a8b4-b3e5025652af", "action_type": "Prompted", "task_level": [2, 2]}
11
+ {"result": "120\n", "action_status": "started", "timestamp": 1679500877.6607795, "task_uuid": "d417ec4b-3b25-4f33-a8b4-b3e5025652af", "action_type": "Response", "task_level": [3, 1]}
12
+ {"action_status": "succeeded", "timestamp": 1679500877.6608076, "task_uuid": "d417ec4b-3b25-4f33-a8b4-b3e5025652af", "action_type": "Response", "task_level": [3, 2]}
13
+ {"action_status": "succeeded", "timestamp": 1679500877.6608305, "task_uuid": "d417ec4b-3b25-4f33-a8b4-b3e5025652af", "action_type": "<function python at 0x7f5ea7231900>", "task_level": [4]}
14
+ {"action_status": "succeeded", "timestamp": 1679500877.6608603, "task_uuid": "11976481-763e-4847-94c2-142c65608e13", "action_type": "test", "task_level": [2]}
test.pmpt.tpl ADDED
@@ -0,0 +1 @@
 
 
1
+ Hello there! {{x}}
test.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from minichain import prompt, Mock, show
2
+ import minichain
3
+
4
+ @prompt(Mock(["hello"]))
5
+ def prompt_function1(model, x):
6
+ return model(x)
7
+
8
+ @prompt(Mock(["b"]), template_file="test.pmpt.tpl")
9
+ def prompt_function2(model, x):
10
+ return model(dict(x=x))
11
+
12
+ def run(query):
13
+ x = prompt_function1(query)
14
+ return prompt_function2(prompt_function2(x))
15
+
16
+
17
+ demo = show(run,
18
+ examples=["a"],
19
+ subprompts=[prompt_function1, prompt_function2, prompt_function2])
20
+
21
+ if __name__ == "__main__":
22
+ demo.launch()
test.py~ ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+
2
+ import minichain
3
+ with minichain.start_chain("test") as backend:
4
+ p1 = minichain.Prompt(backend.Mock(["hello"]))
5
+ p2 = minichain.Prompt(backend.Mock(["goodbye"]))
6
+ prompt = p1.chain(p2)
7
+
8
+ minichain.show(prompt)
test2.ipynb ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "id": "b48c8513",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "from minichain import prompt, Mock, show\n",
11
+ "import minichain\n",
12
+ "\n",
13
+ "@prompt(Mock([\"hello\"]))\n",
14
+ "def prompt_function1(model, x):\n",
15
+ " return model(x)\n",
16
+ "\n",
17
+ "@prompt(Mock([\"b\"]), template_file=\"test.pmpt.tpl\")\n",
18
+ "def prompt_function2(model, x):\n",
19
+ " return model(dict(x=x))\n"
20
+ ]
21
+ },
22
+ {
23
+ "cell_type": "code",
24
+ "execution_count": 2,
25
+ "id": "f98856ac",
26
+ "metadata": {},
27
+ "outputs": [],
28
+ "source": [
29
+ "def run(query):\n",
30
+ " x = prompt_function1(query)\n",
31
+ " return prompt_function2(prompt_function2(x))\n",
32
+ "\n",
33
+ "\n",
34
+ "demo = show(run,\n",
35
+ " examples=[\"a\"],\n",
36
+ " subprompts=[prompt_function1, prompt_function2, prompt_function2])\n"
37
+ ]
38
+ },
39
+ {
40
+ "cell_type": "code",
41
+ "execution_count": 3,
42
+ "id": "b7522022",
43
+ "metadata": {},
44
+ "outputs": [
45
+ {
46
+ "name": "stdout",
47
+ "output_type": "stream",
48
+ "text": [
49
+ "Running on local URL: http://127.0.0.1:7861\n"
50
+ ]
51
+ },
52
+ {
53
+ "data": {
54
+ "text/html": [
55
+ "<div><iframe src=\"http://127.0.0.1:7861/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
56
+ ],
57
+ "text/plain": [
58
+ "<IPython.core.display.HTML object>"
59
+ ]
60
+ },
61
+ "metadata": {},
62
+ "output_type": "display_data"
63
+ }
64
+ ],
65
+ "source": [
66
+ "x = demo.launch(quiet=True)"
67
+ ]
68
+ }
69
+ ],
70
+ "metadata": {
71
+ "kernelspec": {
72
+ "display_name": "minichain",
73
+ "language": "python",
74
+ "name": "minichain"
75
+ },
76
+ "language_info": {
77
+ "codemirror_mode": {
78
+ "name": "ipython",
79
+ "version": 3
80
+ },
81
+ "file_extension": ".py",
82
+ "mimetype": "text/x-python",
83
+ "name": "python",
84
+ "nbconvert_exporter": "python",
85
+ "pygments_lexer": "ipython3",
86
+ "version": "3.10.6"
87
+ }
88
+ },
89
+ "nbformat": 4,
90
+ "nbformat_minor": 5
91
+ }