Files
langchain/docs/modules/agents/tools/examples/bash.ipynb
T
Zander ChaseandFergusFettes ee670c448e Persistent Bash Shell (#3580)
Clean up linting and make more idiomatic by using an output parser

---------

Co-authored-by: FergusFettes <fergusfettes@gmail.com>
2023-04-26 15:20:28 -07:00

4.7 KiB

Bash

It can often be useful to have an LLM generate bash commands, and then run them. A common use case for this is letting the LLM interact with your local file system. We provide an easy util to execute bash commands.

In [1]:
from langchain.utilities import BashProcess
In [2]:
bash = BashProcess()
In [3]:
print(bash.run("ls"))
apify.ipynb
arxiv.ipynb
bash.ipynb
bing_search.ipynb
chatgpt_plugins.ipynb
ddg.ipynb
google_places.ipynb
google_search.ipynb
google_serper.ipynb
gradio_tools.ipynb
human_tools.ipynb
ifttt.ipynb
openweathermap.ipynb
python.ipynb
requests.ipynb
search_tools.ipynb
searx_search.ipynb
serpapi.ipynb
wikipedia.ipynb
wolfram_alpha.ipynb
zapier.ipynb

In [4]:
bash.run("cd ..")
# The commands are executed in a new subprocess each time, meaning that
# this call will return the same results as the last.
print(bash.run("ls"))
apify.ipynb
arxiv.ipynb
bash.ipynb
bing_search.ipynb
chatgpt_plugins.ipynb
ddg.ipynb
google_places.ipynb
google_search.ipynb
google_serper.ipynb
gradio_tools.ipynb
human_tools.ipynb
ifttt.ipynb
openweathermap.ipynb
python.ipynb
requests.ipynb
search_tools.ipynb
searx_search.ipynb
serpapi.ipynb
wikipedia.ipynb
wolfram_alpha.ipynb
zapier.ipynb

Terminal Persistance

By default, the bash command will be executed in a new subprocess each time. To retain a persistent bash session, we can use the persistent=True arg.

In [5]:
bash = BashProcess(persistent=True)
In [6]:
bash.run("cd ..")
# Note the list of files is different
print(bash.run("ls"))
custom_tools.ipynb		multi_input_tool.ipynb
examples			tool_input_validation.ipynb
getting_started.md
In [ ]: