File size: 1,325 Bytes
cd607b2
 
 
eac37df
cd607b2
f5ec828
eac37df
 
cd607b2
 
7b856a8
69deff6
 
4e3dc76
7b856a8
 
4e3dc76
 
8200c4e
7b856a8
4e3dc76
 
8200c4e
4e3dc76
7b856a8
4e3dc76
 
7b856a8
 
69deff6
cd607b2
4e3dc76
 
 
 
 
 
 
 
 
7b856a8
5b30d27
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
# + tags=["hide_inp"]

desc = """
### Bash Command Suggestion

Chain that ask for a command-line question and then runs the bash command. [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/srush/MiniChain/blob/master/examples/bash.ipynb)

(Adapted from LangChain [BashChain](https://langchain.readthedocs.io/en/latest/modules/chains/examples/llm_bash.html))
"""
# -

# $

from minichain import show, prompt, OpenAI, Bash


@prompt(OpenAI(), template_file = "bash.pmpt.tpl")
def cli_prompt(model, query):
    return model(dict(question=query))

@prompt(Bash())
def bash_run(model, x):
    x = "\n".join(x.strip().split("\n")[1:-1])
    return model(x)

def bash(query):
    return bash_run(cli_prompt(query))


# $

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.queue().launch()