Spaces:
Runtime error
Runtime error
Upload with huggingface_hub
Browse files- app.py +56 -0
- bash.pmpt.tpl +17 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Notebook to generate and run a bash command.
|
2 |
+
# Adapted from LangChain
|
3 |
+
# [BashChain](https://langchain.readthedocs.io/en/latest/modules/chains/examples/llm_bash.html)
|
4 |
+
|
5 |
+
import minichain
|
6 |
+
|
7 |
+
# Prompt that asks LLM to produce a bash command.
|
8 |
+
|
9 |
+
|
10 |
+
class CLIPrompt(minichain.TemplatePrompt):
|
11 |
+
template_file = "bash.pmpt.tpl"
|
12 |
+
|
13 |
+
def parse(self, out: str, inp):
|
14 |
+
out = out.strip()
|
15 |
+
assert out.startswith("```bash")
|
16 |
+
return out.split("\n")[1:-1]
|
17 |
+
|
18 |
+
|
19 |
+
# Prompt that runs the bash command.
|
20 |
+
|
21 |
+
|
22 |
+
class BashPrompt(minichain.Prompt):
|
23 |
+
def prompt(self, inp) -> str:
|
24 |
+
return ";".join(inp).replace("\n", "")
|
25 |
+
|
26 |
+
def parse(self, out: str, inp) -> str:
|
27 |
+
return out
|
28 |
+
|
29 |
+
|
30 |
+
# Generate and run bash command.
|
31 |
+
|
32 |
+
with minichain.start_chain("bash") as backend:
|
33 |
+
question = (
|
34 |
+
'"go up one directory, and then into the minichain directory,'
|
35 |
+
'and list the files in the directory"'
|
36 |
+
)
|
37 |
+
prompt = CLIPrompt(backend.OpenAI()).chain(BashPrompt(backend.BashProcess()))
|
38 |
+
result = prompt({"question": question})
|
39 |
+
print(result)
|
40 |
+
|
41 |
+
# View the prompts.
|
42 |
+
|
43 |
+
# + tags=["hide_inp"]
|
44 |
+
CLIPrompt().show(
|
45 |
+
{"question": "list the files in the directory"}, """```bash\nls\n```"""
|
46 |
+
)
|
47 |
+
# -
|
48 |
+
|
49 |
+
|
50 |
+
# + tags=["hide_inp"]
|
51 |
+
BashPrompt().show(["ls", "cat file.txt"], "hello")
|
52 |
+
# -
|
53 |
+
|
54 |
+
# View the run log.
|
55 |
+
|
56 |
+
minichain.show_log("bash.log")
|
bash.pmpt.tpl
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
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:
|
2 |
+
|
3 |
+
Question: "copy the files in the directory named 'target' into a new directory at the same level as target called 'myNewDirectory'"
|
4 |
+
|
5 |
+
I need to take the following actions:
|
6 |
+
- List all files in the directory
|
7 |
+
- Create a new directory
|
8 |
+
- Copy the files from the first directory into the second directory
|
9 |
+
```bash
|
10 |
+
ls
|
11 |
+
mkdir myNewDirectory
|
12 |
+
cp -r target/* myNewDirectory
|
13 |
+
```
|
14 |
+
|
15 |
+
That is the format. Begin!
|
16 |
+
|
17 |
+
Question: {{question}}
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
git+https://github.com/srush/minichain
|
3 |
+
manifest-ml
|