|
28 | 28 | "\n",
|
29 | 29 | "Answer: \u001b[33;1m\u001b[1;3mHello World\n",
|
30 | 30 | "\u001b[0m\n",
|
31 |
| - "\u001b[1m> Finished LLMBashChain chain.\u001b[0m\n" |
| 31 | + "\u001b[1m> Finished chain.\u001b[0m\n" |
32 | 32 | ]
|
33 | 33 | },
|
34 | 34 | {
|
|
55 | 55 | "bash_chain.run(text)"
|
56 | 56 | ]
|
57 | 57 | },
|
| 58 | + { |
| 59 | + "cell_type": "markdown", |
| 60 | + "metadata": {}, |
| 61 | + "source": [ |
| 62 | + "## Customize Prompt\n", |
| 63 | + "You can also customize the prompt that is used. Here is an example prompting to avoid using the 'echo' utility" |
| 64 | + ] |
| 65 | + }, |
58 | 66 | {
|
59 | 67 | "cell_type": "code",
|
60 |
| - "execution_count": null, |
| 68 | + "execution_count": 28, |
61 | 69 | "metadata": {},
|
62 | 70 | "outputs": [],
|
63 |
| - "source": [] |
| 71 | + "source": [ |
| 72 | + "from langchain.prompts.prompt import PromptTemplate\n", |
| 73 | + "\n", |
| 74 | + "_PROMPT_TEMPLATE = \"\"\"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:\n", |
| 75 | + "Question: \"copy the files in the directory named 'target' into a new directory at the same level as target called 'myNewDirectory'\"\n", |
| 76 | + "I need to take the following actions:\n", |
| 77 | + "- List all files in the directory\n", |
| 78 | + "- Create a new directory\n", |
| 79 | + "- Copy the files from the first directory into the second directory\n", |
| 80 | + "```bash\n", |
| 81 | + "ls\n", |
| 82 | + "mkdir myNewDirectory\n", |
| 83 | + "cp -r target/* myNewDirectory\n", |
| 84 | + "```\n", |
| 85 | + "\n", |
| 86 | + "Do not use 'echo' when writing the script.\n", |
| 87 | + "\n", |
| 88 | + "That is the format. Begin!\n", |
| 89 | + "Question: {question}\"\"\"\n", |
| 90 | + "\n", |
| 91 | + "PROMPT = PromptTemplate(input_variables=[\"question\"], template=_PROMPT_TEMPLATE)" |
| 92 | + ] |
| 93 | + }, |
| 94 | + { |
| 95 | + "cell_type": "code", |
| 96 | + "execution_count": 29, |
| 97 | + "metadata": {}, |
| 98 | + "outputs": [ |
| 99 | + { |
| 100 | + "name": "stdout", |
| 101 | + "output_type": "stream", |
| 102 | + "text": [ |
| 103 | + "\n", |
| 104 | + "\n", |
| 105 | + "\u001b[1m> Entering new LLMBashChain chain...\u001b[0m\n", |
| 106 | + "Please write a bash script that prints 'Hello World' to the console.\u001b[32;1m\u001b[1;3m\n", |
| 107 | + "\n", |
| 108 | + "```bash\n", |
| 109 | + "printf \"Hello World\\n\"\n", |
| 110 | + "```\u001b[0m['```bash', 'printf \"Hello World\\\\n\"', '```']\n", |
| 111 | + "\n", |
| 112 | + "Answer: \u001b[33;1m\u001b[1;3mHello World\n", |
| 113 | + "\u001b[0m\n", |
| 114 | + "\u001b[1m> Finished chain.\u001b[0m\n" |
| 115 | + ] |
| 116 | + }, |
| 117 | + { |
| 118 | + "data": { |
| 119 | + "text/plain": [ |
| 120 | + "'Hello World\\n'" |
| 121 | + ] |
| 122 | + }, |
| 123 | + "execution_count": 29, |
| 124 | + "metadata": {}, |
| 125 | + "output_type": "execute_result" |
| 126 | + } |
| 127 | + ], |
| 128 | + "source": [ |
| 129 | + "bash_chain = LLMBashChain(llm=llm, prompt=PROMPT, verbose=True)\n", |
| 130 | + "\n", |
| 131 | + "text = \"Please write a bash script that prints 'Hello World' to the console.\"\n", |
| 132 | + "\n", |
| 133 | + "bash_chain.run(text)" |
| 134 | + ] |
64 | 135 | }
|
65 | 136 | ],
|
66 | 137 | "metadata": {
|
|
79 | 150 | "name": "python",
|
80 | 151 | "nbconvert_exporter": "python",
|
81 | 152 | "pygments_lexer": "ipython3",
|
82 |
| - "version": "3.10.9" |
| 153 | + "version": "3.10.6" |
83 | 154 | }
|
84 | 155 | },
|
85 | 156 | "nbformat": 4,
|
|
0 commit comments