Pal
In [1]:
Copied!
desc = """
### Prompt-aided Language Models
Chain for answering complex problems by code generation and execution. [[Code](https://github.com/srush/MiniChain/blob/main/examples/pal.py)]
(Adapted from Prompt-aided Language Models [PAL](https://arxiv.org/pdf/2211.10435.pdf)).
"""
desc = """
### Prompt-aided Language Models
Chain for answering complex problems by code generation and execution. [[Code](https://github.com/srush/MiniChain/blob/main/examples/pal.py)]
(Adapted from Prompt-aided Language Models [PAL](https://arxiv.org/pdf/2211.10435.pdf)).
"""
$
In [2]:
Copied!
from minichain import prompt, show, OpenAI, Python
from minichain import prompt, show, OpenAI, Python
In [3]:
Copied!
@prompt(OpenAI(), template_file="pal.pmpt.tpl")
def pal_prompt(model, question):
return model(dict(question=question))
@prompt(OpenAI(), template_file="pal.pmpt.tpl")
def pal_prompt(model, question):
return model(dict(question=question))
In [4]:
Copied!
@prompt(Python())
def python(model, inp):
return int(model(inp + "\nprint(solution())"))
@prompt(Python())
def python(model, inp):
return int(model(inp + "\nprint(solution())"))
In [5]:
Copied!
def pal(question):
return python(pal_prompt(question))
def pal(question):
return python(pal_prompt(question))
$
In [6]:
Copied!
question = "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?"
question = "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?"
In [7]:
Copied!
gradio = show(pal,
examples=[question],
subprompts=[pal_prompt, python],
description=desc,
code=open("pal.py", "r").read().split("$")[1].strip().strip("#").strip(),
)
gradio = show(pal,
examples=[question],
subprompts=[pal_prompt, python],
description=desc,
code=open("pal.py", "r").read().split("$")[1].strip().strip("#").strip(),
)
In [8]:
Copied!
if __name__ == "__main__":
gradio.launch()
if __name__ == "__main__":
gradio.launch()
Running on local URL: http://127.0.0.1:7861 To create a public link, set `share=True` in `launch()`.