File size: 36,457 Bytes
7b856a8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 |
{
"cells": [
{
"cell_type": "markdown",
"id": "95a637f8",
"metadata": {},
"source": [
"Adapted from Prompt-aided Language Models [PAL](https://arxiv.org/pdf/2211.10435.pdf)."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "3eefe2ae",
"metadata": {
"execution": {
"iopub.execute_input": "2023-02-27T14:15:43.541342Z",
"iopub.status.busy": "2023-02-27T14:15:43.541045Z",
"iopub.status.idle": "2023-02-27T14:15:43.740615Z",
"shell.execute_reply": "2023-02-27T14:15:43.739910Z"
},
"lines_to_next_cell": 1
},
"outputs": [],
"source": [
"import minichain"
]
},
{
"cell_type": "markdown",
"id": "1932de81",
"metadata": {},
"source": [
"PAL Prompt"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "8b0f3ba4",
"metadata": {
"execution": {
"iopub.execute_input": "2023-02-27T14:15:43.745885Z",
"iopub.status.busy": "2023-02-27T14:15:43.744171Z",
"iopub.status.idle": "2023-02-27T14:15:43.749926Z",
"shell.execute_reply": "2023-02-27T14:15:43.749298Z"
},
"lines_to_next_cell": 1
},
"outputs": [],
"source": [
"class PalPrompt(minichain.TemplatePrompt):\n",
" template_file = \"pal.pmpt.tpl\""
]
},
{
"cell_type": "markdown",
"id": "5e6b0f1e",
"metadata": {},
"source": [
"Prompt to run and print python code."
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "5f5fea2c",
"metadata": {
"execution": {
"iopub.execute_input": "2023-02-27T14:15:43.754328Z",
"iopub.status.busy": "2023-02-27T14:15:43.753171Z",
"iopub.status.idle": "2023-02-27T14:15:43.758857Z",
"shell.execute_reply": "2023-02-27T14:15:43.758175Z"
},
"lines_to_next_cell": 1
},
"outputs": [],
"source": [
"class PyPrompt(minichain.Prompt):\n",
" def prompt(self, inp):\n",
" return inp + \"\\nprint(solution())\"\n",
"\n",
" def parse(self, response, inp):\n",
" return int(response)"
]
},
{
"cell_type": "markdown",
"id": "b494356e",
"metadata": {},
"source": [
"Chain the prompts."
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "d6e170f7",
"metadata": {
"execution": {
"iopub.execute_input": "2023-02-27T14:15:43.763969Z",
"iopub.status.busy": "2023-02-27T14:15:43.762806Z",
"iopub.status.idle": "2023-02-27T14:15:54.833413Z",
"shell.execute_reply": "2023-02-27T14:15:54.832851Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"9\n"
]
}
],
"source": [
"with minichain.start_chain(\"pal\") as backend:\n",
" question = \"Melanie is a door-to-door saleswoman. She sold a third of her ' \\\n",
" 'vacuum cleaners at the green house, 2 more to the red house, and half of ' \\\n",
" 'what was left at the orange house. If Melanie has 5 vacuum cleaners left, ' \\\n",
" 'how many did she start with?'\"\n",
" prompt = PalPrompt(backend.OpenAI()).chain(PyPrompt(backend.Python()))\n",
" result = prompt({\"question\": question})\n",
" print(result)"
]
},
{
"cell_type": "markdown",
"id": "4a631744",
"metadata": {},
"source": [
"View prompt examples."
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "729a67c3",
"metadata": {
"execution": {
"iopub.execute_input": "2023-02-27T14:15:54.835748Z",
"iopub.status.busy": "2023-02-27T14:15:54.835484Z",
"iopub.status.idle": "2023-02-27T14:15:54.882169Z",
"shell.execute_reply": "2023-02-27T14:15:54.881546Z"
},
"tags": [
"hide_inp"
]
},
"outputs": [
{
"data": {
"text/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\">'question'</span><span class=\"p\">:</span> <span class=\"s1\">'Joe has 10 cars and Bobby has 12. How many do they have together?'</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"
],
"text/plain": [
"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\">'question'</span><span class=\"p\">:</span> <span class=\"s1\">'Joe has 10 cars and Bobby has 12. How many do they have together?'</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')"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"PalPrompt().show(\n",
" {\"question\": \"Joe has 10 cars and Bobby has 12. How many do they have together?\"},\n",
" \"def solution():\\n\\treturn 10 + 12\",\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "616a782d",
"metadata": {
"execution": {
"iopub.execute_input": "2023-02-27T14:15:54.884523Z",
"iopub.status.busy": "2023-02-27T14:15:54.884246Z",
"iopub.status.idle": "2023-02-27T14:15:54.889558Z",
"shell.execute_reply": "2023-02-27T14:15:54.889097Z"
},
"tags": [
"hide_inp"
]
},
"outputs": [
{
"data": {
"text/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"
],
"text/plain": [
"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')"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"PyPrompt().show(\"def solution():\\n\\treturn 10 + 12\", \"22\")"
]
},
{
"cell_type": "markdown",
"id": "5aad5ea7",
"metadata": {},
"source": [
"View the log."
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "a4fb48ac",
"metadata": {
"execution": {
"iopub.execute_input": "2023-02-27T14:15:54.892000Z",
"iopub.status.busy": "2023-02-27T14:15:54.891678Z",
"iopub.status.idle": "2023-02-27T14:15:54.914877Z",
"shell.execute_reply": "2023-02-27T14:15:54.914134Z"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[38;5;15m28b775fd-0862-4c8f-aada-b6158be3b664\u001b[1m\u001b[0m\n",
"└── \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",
" ├── \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",
" │ ├── \u001b[38;5;4minput\u001b[0m: \u001b[0m\n",
" │ │ └── \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",
" │ └── \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",
" ├── \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",
" │ ├── \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",
" │ │ ⏎\n",
" │ │ # solution in Python:⏎\n",
" │ │ ⏎\n",
" │ │ ⏎\n",
" │ │ def solution():⏎\n",
" │ │ \"\"\"Olivia has $23. She bought five bagels for $3 each. How much money does she have left?\"\"\"⏎\n",
" │ │ money_initial = 23⏎\n",
" │ │ bagels = 5⏎\n",
" │ │ bagel_cost = 3⏎\n",
" │ │ money_spent = bagels * bagel_cost⏎\n",
" │ │ money_left = money_initial - money_spent⏎\n",
" │ │ result = money_left⏎\n",
" │ │ return result⏎\n",
" │ │ ⏎\n",
" │ │ ⏎\n",
" │ │ ⏎\n",
" │ │ ⏎\n",
" │ │ ⏎\n",
" │ │ 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",
" │ │ ⏎\n",
" │ │ # solution in Python:⏎\n",
" │ │ ⏎\n",
" │ │ ⏎\n",
" │ │ def solution():⏎\n",
" │ │ \"\"\"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",
" │ │ golf_balls_initial = 58⏎\n",
" │ │ golf_balls_lost_tuesday = 23⏎\n",
" │ │ golf_balls_lost_wednesday = 2⏎\n",
" │ │ golf_balls_left = golf_balls_initial - golf_balls_lost_tuesday - golf_balls_lost_wednesday⏎\n",
" │ │ result = golf_balls_left⏎\n",
" │ │ return result⏎\n",
" │ │ ⏎\n",
" │ │ ⏎\n",
" │ │ ⏎\n",
" │ │ ⏎\n",
" │ │ ⏎\n",
" │ │ 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",
" │ │ ⏎\n",
" │ │ # solution in Python:⏎\n",
" │ │ ⏎\n",
" │ │ ⏎\n",
" │ │ def solution():⏎\n",
" │ │ \"\"\"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",
" │ │ computers_initial = 9⏎\n",
" │ │ computers_per_day = 5⏎\n",
" │ │ num_days = 4 # 4 days between monday and thursday⏎\n",
" │ │ computers_added = computers_per_day * num_days⏎\n",
" │ │ computers_total = computers_initial + computers_added⏎\n",
" │ │ result = computers_total⏎\n",
" │ │ return result⏎\n",
" │ │ ⏎\n",
" │ │ ⏎\n",
" │ │ ⏎\n",
" │ │ ⏎\n",
" │ │ ⏎\n",
" │ │ 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",
" │ │ ⏎\n",
" │ │ # solution in Python:⏎\n",
" │ │ ⏎\n",
" │ │ ⏎\n",
" │ │ def solution():⏎\n",
" │ │ \"\"\"Shawn has five toys. For Christmas, he got two toys each from his mom and dad. How many toys does he have now?\"\"\"⏎\n",
" │ │ toys_initial = 5⏎\n",
" │ │ mom_toys = 2⏎\n",
" │ │ dad_toys = 2⏎\n",
" │ │ total_received = mom_toys + dad_toys⏎\n",
" │ │ total_toys = toys_initial + total_received⏎\n",
" │ │ result = total_toys⏎\n",
" │ │ return result⏎\n",
" │ │ ⏎\n",
" │ │ ⏎\n",
" │ │ ⏎\n",
" │ │ ⏎\n",
" │ │ ⏎\n",
" │ │ Q: Jason had 20 lollipops. He gave Denny some lollipops. Now Jason has 12 lollipops. How many lollipops did Jason give to Denny?⏎\n",
" │ │ ⏎\n",
" │ │ # solution in Python:⏎\n",
" │ │ ⏎\n",
" │ │ ⏎\n",
" │ │ def solution():⏎\n",
" │ │ \"\"\"Jason had 20 lollipops. He gave Denny some lollipops. Now Jason has 12 lollipops. How many lollipops did Jason give to Denny?\"\"\"⏎\n",
" │ │ jason_lollipops_initial = 20⏎\n",
" │ │ jason_lollipops_after = 12⏎\n",
" │ │ denny_lollipops = jason_lollipops_initial - jason_lollipops_after⏎\n",
" │ │ result = denny_lollipops⏎\n",
" │ │ return result⏎\n",
" │ │ ⏎\n",
" │ │ ⏎\n",
" │ │ ⏎\n",
" │ │ ⏎\n",
" │ │ ⏎\n",
" │ │ Q: Leah had 32 chocolates and her sister had 42. If they ate 35, how many pieces do they have left in total?⏎\n",
" │ │ ⏎\n",
" │ │ # solution in Python:⏎\n",
" │ │ ⏎\n",
" │ │ ⏎\n",
" │ │ def solution():⏎\n",
" │ │ \"\"\"Leah had 32 chocolates and her sister had 42. If they ate 35, how many pieces do they have left in total?\"\"\"⏎\n",
" │ │ leah_chocolates = 32⏎\n",
" │ │ sister_chocolates = 42⏎\n",
" │ │ total_chocolates = leah_chocolates + sister_chocolates⏎\n",
" │ │ chocolates_eaten = 35⏎\n",
" │ │ chocolates_left = total_chocolates - chocolates_eaten⏎\n",
" │ │ result = chocolates_left⏎\n",
" │ │ return result⏎\n",
" │ │ ⏎\n",
" │ │ ⏎\n",
" │ │ ⏎\n",
" │ │ ⏎\n",
" │ │ ⏎\n",
" │ │ Q: If there are 3 cars in the parking lot and 2 more cars arrive, how many cars are in the parking lot?⏎\n",
" │ │ ⏎\n",
" │ │ # solution in Python:⏎\n",
" │ │ ⏎\n",
" │ │ ⏎\n",
" │ │ def solution():⏎\n",
" │ │ \"\"\"If there are 3 cars in the parking lot and 2 more cars arrive, how many cars are in the parking lot?\"\"\"⏎\n",
" │ │ cars_initial = 3⏎\n",
" │ │ cars_arrived = 2⏎\n",
" │ │ total_cars = cars_initial + cars_arrived⏎\n",
" │ │ result = total_cars⏎\n",
" │ │ return result⏎\n",
" │ │ ⏎\n",
" │ │ ⏎\n",
" │ │ ⏎\n",
" │ │ ⏎\n",
" │ │ ⏎\n",
" │ │ 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",
" │ │ ⏎\n",
" │ │ # solution in Python:⏎\n",
" │ │ ⏎\n",
" │ │ ⏎\n",
" │ │ def solution():⏎\n",
" │ │ \"\"\"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",
" │ │ trees_initial = 15⏎\n",
" │ │ trees_after = 21⏎\n",
" │ │ trees_added = trees_after - trees_initial⏎\n",
" │ │ result = trees_added⏎\n",
" │ │ return result⏎\n",
" │ │ ⏎\n",
" │ │ ⏎\n",
" │ │ ⏎\n",
" │ │ ⏎\n",
" │ │ ⏎\n",
" │ │ 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",
" │ │ ⏎\n",
" │ │ # solution in Python:\u001b[0m\n",
" │ └── \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",
" ├── \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",
" │ ├── \u001b[38;5;4mresult\u001b[0m: ⏎\n",
" │ │ ⏎\n",
" │ │ ⏎\n",
" │ │ def solution():⏎\n",
" │ │ \"\"\"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",
" │ │ vacuum_cleaners_left = 5⏎\n",
" │ │ vacuum_cleaners_sold_green = vacuum_cleaners_left // 3⏎\n",
" │ │ vacuum_cleaners_sold_red = 2⏎\n",
" │ │ vacuum_cleaners_sold_orange = (vacuum_cleaners_left - vacuum_cleaners_sold_green - vacuum_cleaners_sold_red) // 2⏎\n",
" │ │ vacuum_cleaners_initial = vacuum_cleaners_left + vacuum_cleaners_sold_green + vacuum_cleaners_sold_red + vacuum_cleaners_sold_orange⏎\n",
" │ │ result = vacuum_cleaners_initial⏎\n",
" │ │ return result\u001b[0m\n",
" │ └── \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",
" └── \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",
"\n",
"\u001b[38;5;15mf2a0c10a-9d37-45b0-af51-bc18b0da6877\u001b[1m\u001b[0m\n",
"└── \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",
" ├── \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",
" │ ├── \u001b[38;5;4minput\u001b[0m: ⏎\n",
" │ │ ⏎\n",
" │ │ ⏎\n",
" │ │ def solution():⏎\n",
" │ │ \"\"\"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",
" │ │ vacuum_cleaners_left = 5⏎\n",
" │ │ vacuum_cleaners_sold_green = vacuum_cleaners_left // 3⏎\n",
" │ │ vacuum_cleaners_sold_red = 2⏎\n",
" │ │ vacuum_cleaners_sold_orange = (vacuum_cleaners_left - vacuum_cleaners_sold_green - vacuum_cleaners_sold_red) // 2⏎\n",
" │ │ vacuum_cleaners_initial = vacuum_cleaners_left + vacuum_cleaners_sold_green + vacuum_cleaners_sold_red + vacuum_cleaners_sold_orange⏎\n",
" │ │ result = vacuum_cleaners_initial⏎\n",
" │ │ return result\u001b[0m\n",
" │ └── \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",
" ├── \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",
" │ ├── \u001b[38;5;4mprompt\u001b[0m: ⏎\n",
" │ │ ⏎\n",
" │ │ ⏎\n",
" │ │ def solution():⏎\n",
" │ │ \"\"\"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",
" │ │ vacuum_cleaners_left = 5⏎\n",
" │ │ vacuum_cleaners_sold_green = vacuum_cleaners_left // 3⏎\n",
" │ │ vacuum_cleaners_sold_red = 2⏎\n",
" │ │ vacuum_cleaners_sold_orange = (vacuum_cleaners_left - vacuum_cleaners_sold_green - vacuum_cleaners_sold_red) // 2⏎\n",
" │ │ vacuum_cleaners_initial = vacuum_cleaners_left + vacuum_cleaners_sold_green + vacuum_cleaners_sold_red + vacuum_cleaners_sold_orange⏎\n",
" │ │ result = vacuum_cleaners_initial⏎\n",
" │ │ return result⏎\n",
" │ │ print(solution())\u001b[0m\n",
" │ └── \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",
" ├── \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",
" │ ├── \u001b[38;5;4mresult\u001b[0m: 9⏎\n",
" │ │ \u001b[0m\n",
" │ └── \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",
" └── \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",
"\n",
"\u001b[38;5;15m18cad0c1-8de2-4459-af6c-fd8426cdacad\u001b[1m\u001b[0m\n",
"└── \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",
" └── \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",
"\n"
]
}
],
"source": [
"minichain.show_log(\"pal.log\")"
]
}
],
"metadata": {
"jupytext": {
"cell_metadata_filter": "tags,-all"
},
"kernelspec": {
"display_name": "minichain",
"language": "python",
"name": "minichain"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|