In [1]:
from typing import List
from minichain import Backend, JinjaPrompt, Prompt, start_chain
In [ ]:
 

Prompt that asks LLM to produce a bash command.

In [2]:
class CLIPrompt(JinjaPrompt[List[str]]):
    template_file = "bash.pmpt.tpl"
    def parse(self, result: str) -> List[str]:
        assert result.startswith("```bash")
        return result.split("\n")[1:-1]
In [3]:
CLIPrompt().show(
    {"question": "list the files in the directory"},
    """```bash\nls\n```""")
Out[3]:

CLIPrompt

Input:
{'question': 'list the files in the directory'}
Full Prompt:

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:

Question: "copy the files in the directory named 'target' into a new directory at the same level as target called 'myNewDirectory'"

I need to take the following actions:
- List all files in the directory
- Create a new directory
- Copy the files from the first directory into the second directory
```bash
ls
mkdir myNewDirectory
cp -r target/* myNewDirectory
```

That is the format. Begin!

Question:

list the files in the directory

Response:
```bash
ls
```
Value:
['ls']

Prompt that runs the bash command.

In [4]:
class BashPrompt(Prompt[List[str], str]):
    def prompt(self, inp: List[str]) -> str:
        return ";".join(inp).replace("\n", "")

    def parse(self, out: str) -> str:
        return out
In [5]:
BashPrompt().show(["ls", "cat file.txt"], "hello")
Out[5]:

BashPrompt

Input:
['ls', 'cat file.txt']
Full Prompt:

ls;cat file.txt

Response:
hello
Value:
hello
In [6]:
with start_chain("bash") as backend:
    mock = backend.Mock(
        [
                """```bash
ls
ls
ls
```"""
        ]
    )
    # openai = backend.OpenAI()
    question = '"go up one directory and list the files in the directory"'
    prompt = CLIPrompt(mock).chain(BashPrompt(backend.BashProcess()))
    result = prompt({"question": question})
    print(result.val)
base.py
bash.html
bash.ipynb
bash.log
bash.pmpt.tpl
bash.pmpt.tpl~
bash.py
bash.py~
#parallel.py#
parallel.py
parallel.py~
selfask
selfask.html
selfask.ipynb
selfask.log
selfask.pmpt.tpl
selfask.py
story.py
story.py~
base.py
bash.html
bash.ipynb
bash.log
bash.pmpt.tpl
bash.pmpt.tpl~
bash.py
bash.py~
#parallel.py#
parallel.py
parallel.py~
selfask
selfask.html
selfask.ipynb
selfask.log
selfask.pmpt.tpl
selfask.py
story.py
story.py~
base.py
bash.html
bash.ipynb
bash.log
bash.pmpt.tpl
bash.pmpt.tpl~
bash.py
bash.py~
#parallel.py#
parallel.py
parallel.py~
selfask
selfask.html
selfask.ipynb
selfask.log
selfask.pmpt.tpl
selfask.py
story.py
story.py~

In [ ]:
    
In [7]:
!eliot-tree -l 0 bash.log | grep -v "succeeded" | grep -v "started"
f1d34948-3c10-43b1-993c-d3c55d3255b5

b4113480-2253-4c08-be66-b4d54acd0911
    │   ├── input: 
    │   │   └── question: "go up one directory and list the files in the directory"
    │   ├── prompt: 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:⏎
    │   │   ⏎
    │   │   Question: "copy the files in the directory named 'target' into a new directory at the same level as target called 'myNewDirectory'"⏎
    │   │   ⏎
    │   │   I need to take the following actions:⏎
    │   │   - List all files in the directory⏎
    │   │   - Create a new directory⏎
    │   │   - Copy the files from the first directory into the second directory⏎
    │   │   ```bash⏎
    │   │   ls⏎
    │   │   mkdir myNewDirectory⏎
    │   │   cp -r target/* myNewDirectory⏎
    │   │   ```⏎
    │   │   ⏎
    │   │   That is the format. Begin!⏎
    │   │   ⏎
    │   │   Question: "go up one directory and list the files in the directory"
    │   ├── result: ```bash⏎
    │   │   ls⏎
    │   │   ls⏎
    │   │   ls⏎
    │   │   ```
    │   │   └── returned: 
    │   │       ├── 0: ls
    │   │       ├── 1: ls
    │   │       └── 2: ls

bbfa93a2-07f9-4c2f-880e-8b4ea8cd5d66
    │   ├── input: 
    │   │   ├── 0: ls
    │   │   ├── 1: ls
    │   │   └── 2: ls
    │   ├── prompt: ls;ls;ls
    │   ├── result: base.py⏎
    │   │   bash.html⏎
    │   │   bash.ipynb⏎
    │   │   bash.log⏎
    │   │   bash.pmpt.tpl⏎
    │   │   bash.pmpt.tpl~⏎
    │   │   bash.py⏎
    │   │   bash.py~⏎
    │   │   #parallel.py#⏎
    │   │   parallel.py⏎
    │   │   parallel.py~⏎
    │   │   selfask⏎
    │   │   selfask.html⏎
    │   │   selfask.ipynb⏎
    │   │   selfask.log⏎
    │   │   selfask.pmpt.tpl⏎
    │   │   selfask.py⏎
    │   │   story.py⏎
    │   │   story.py~⏎
    │   │   base.py⏎
    │   │   bash.html⏎
    │   │   bash.ipynb⏎
    │   │   bash.log⏎
    │   │   bash.pmpt.tpl⏎
    │   │   bash.pmpt.tpl~⏎
    │   │   bash.py⏎
    │   │   bash.py~⏎
    │   │   #parallel.py#⏎
    │   │   parallel.py⏎
    │   │   parallel.py~⏎
    │   │   selfask⏎
    │   │   selfask.html⏎
    │   │   selfask.ipynb⏎
    │   │   selfask.log⏎
    │   │   selfask.pmpt.tpl⏎
    │   │   selfask.py⏎
    │   │   story.py⏎
    │   │   story.py~⏎
    │   │   base.py⏎
    │   │   bash.html⏎
    │   │   bash.ipynb⏎
    │   │   bash.log⏎
    │   │   bash.pmpt.tpl⏎
    │   │   bash.pmpt.tpl~⏎
    │   │   bash.py⏎
    │   │   bash.py~⏎
    │   │   #parallel.py#⏎
    │   │   parallel.py⏎
    │   │   parallel.py~⏎
    │   │   selfask⏎
    │   │   selfask.html⏎
    │   │   selfask.ipynb⏎
    │   │   selfask.log⏎
    │   │   selfask.pmpt.tpl⏎
    │   │   selfask.py⏎
    │   │   story.py⏎
    │   │   story.py~⏎
    │   │   
    │   │   └── returned: base.py⏎
    │   │       bash.html⏎
    │   │       bash.ipynb⏎
    │   │       bash.log⏎
    │   │       bash.pmpt.tpl⏎
    │   │       bash.pmpt.tpl~⏎
    │   │       bash.py⏎
    │   │       bash.py~⏎
    │   │       #parallel.py#⏎
    │   │       parallel.py⏎
    │   │       parallel.py~⏎
    │   │       selfask⏎
    │   │       selfask.html⏎
    │   │       selfask.ipynb⏎
    │   │       selfask.log⏎
    │   │       selfask.pmpt.tpl⏎
    │   │       selfask.py⏎
    │   │       story.py⏎
    │   │       story.py~⏎
    │   │       base.py⏎
    │   │       bash.html⏎
    │   │       bash.ipynb⏎
    │   │       bash.log⏎
    │   │       bash.pmpt.tpl⏎
    │   │       bash.pmpt.tpl~⏎
    │   │       bash.py⏎
    │   │       bash.py~⏎
    │   │       #parallel.py#⏎
    │   │       parallel.py⏎
    │   │       parallel.py~⏎
    │   │       selfask⏎
    │   │       selfask.html⏎
    │   │       selfask.ipynb⏎
    │   │       selfask.log⏎
    │   │       selfask.pmpt.tpl⏎
    │   │       selfask.py⏎
    │   │       story.py⏎
    │   │       story.py~⏎
    │   │       base.py⏎
    │   │       bash.html⏎
    │   │       bash.ipynb⏎
    │   │       bash.log⏎
    │   │       bash.pmpt.tpl⏎
    │   │       bash.pmpt.tpl~⏎
    │   │       bash.py⏎
    │   │       bash.py~⏎
    │   │       #parallel.py#⏎
    │   │       parallel.py⏎
    │   │       parallel.py~⏎
    │   │       selfask⏎
    │   │       selfask.html⏎
    │   │       selfask.ipynb⏎
    │   │       selfask.log⏎
    │   │       selfask.pmpt.tpl⏎
    │   │       selfask.py⏎
    │   │       story.py⏎
    │   │       story.py~⏎
    │   │