mirror of
https://github.com/langchain-ai/langchain.git
synced 2026-10-06 18:05:25 +03:00
4.2 KiB
4.2 KiB
In [1]:
from langchain.chains import LLMBashChain
from langchain.llms import OpenAI
llm = OpenAI(temperature=0)
text = "Please write a bash script that prints 'Hello World' to the console."
bash_chain = LLMBashChain(llm=llm, verbose=True)
bash_chain.run(text)Out [1]:
[1m> Entering new LLMBashChain chain...[0m Please write a bash script that prints 'Hello World' to the console.[32;1m[1;3m ```bash echo "Hello World" ```[0m['```bash', 'echo "Hello World"', '```'] Answer: [33;1m[1;3mHello World [0m [1m> Finished chain.[0m
'Hello World\n'
In [28]:
from langchain.prompts.prompt import PromptTemplate
_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:
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
```
Do not use 'echo' when writing the script.
That is the format. Begin!
Question: {question}"""
PROMPT = PromptTemplate(input_variables=["question"], template=_PROMPT_TEMPLATE)In [29]:
bash_chain = LLMBashChain(llm=llm, prompt=PROMPT, verbose=True)
text = "Please write a bash script that prints 'Hello World' to the console."
bash_chain.run(text)Out [29]:
[1m> Entering new LLMBashChain chain...[0m Please write a bash script that prints 'Hello World' to the console.[32;1m[1;3m ```bash printf "Hello World\n" ```[0m['```bash', 'printf "Hello World\\n"', '```'] Answer: [33;1m[1;3mHello World [0m [1m> Finished chain.[0m
'Hello World\n'