Bash
In [1]:
Copied!
desc = """
### Bash Command Suggestion
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)]
(Adapted from LangChain [BashChain](https://langchain.readthedocs.io/en/latest/modules/chains/examples/llm_bash.html))
"""
desc = """
### Bash Command Suggestion
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)]
(Adapted from LangChain [BashChain](https://langchain.readthedocs.io/en/latest/modules/chains/examples/llm_bash.html))
"""
$
In [2]:
Copied!
from minichain import show, prompt, OpenAI, Bash
from minichain import show, prompt, OpenAI, Bash
In [3]:
Copied!
@prompt(OpenAI(), template_file = "bash.pmpt.tpl")
def cli_prompt(model, query):
x = model(dict(question=query))
return "\n".join(x.strip().split("\n")[1:-1])
@prompt(OpenAI(), template_file = "bash.pmpt.tpl")
def cli_prompt(model, query):
x = model(dict(question=query))
return "\n".join(x.strip().split("\n")[1:-1])
In [4]:
Copied!
@prompt(Bash())
def bash_run(model, x):
return model(x)
@prompt(Bash())
def bash_run(model, x):
return model(x)
In [5]:
Copied!
def bash(query):
return bash_run(cli_prompt(query))
def bash(query):
return bash_run(cli_prompt(query))
$
In [6]:
Copied!
gradio = show(bash,
subprompts=[cli_prompt, bash_run],
examples=['Go up one directory, and then into the minichain directory,'
'and list the files in the directory',
"Please write a bash script that prints 'Hello World' to the console."],
out_type="markdown",
description=desc,
code=open("bash.py", "r").read().split("$")[1].strip().strip("#").strip(),
)
if __name__ == "__main__":
gradio.launch()
gradio = show(bash,
subprompts=[cli_prompt, bash_run],
examples=['Go up one directory, and then into the minichain directory,'
'and list the files in the directory',
"Please write a bash script that prints 'Hello World' to the console."],
out_type="markdown",
description=desc,
code=open("bash.py", "r").read().split("$")[1].strip().strip("#").strip(),
)
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()`.