Skip to main content

Filesystem Shell interface that an OpenAI Assitant can use as a tool.

Project description

ai_shell

OpenAI-centric shell for giving safe, chat-optimized, filesystem access to an Assistant as a "tool".

Even if you trust the bot to run bash directly on your machine or docker container, standard tools will run up your bill with excess tokens in the reply, or a command generates too few tokens and the bot doesn't know what is going on.

This is an alternative to code_interpreter, tools running code in docker container locally, or tools running arbitrary shell code locally.

Installation

pip install ai_shell

Usage

See these full examples. As long as the OPENAI_API_KEY environment variable is set, you can run these examples.

To execute demo bots, run these commands and follow initialization instructions if needed. They all expect to manipulate python code in an /src/ folder.

python -m ai_shell.demo_bots.docs_writer_bot
python -m ai_shell.demo_bots.pylint_bot
python -m ai_shell.demo_bots.test_writer_bot
python -m ai_shell.demo_bots.tool_tester_bot
python -m ai_shell.demo_bots.todo_bot

This is the python interface to the tools, how you're expected to wire up the tool to your bot.

import ai_shell

cat = ai_shell.CatTool(".")
print(cat.cat(["file.py"]))
print(cat.cat_markdown(["file.py"]))

ls = ai_shell.LsTool(".")
print(ls.ls("docs"))
print(ls.ls_markdown("docs"))

This is the smallest example to illustrate basic capabilities, also see here.

import asyncio
import ai_shell


async def main():
    def static_keep_going(toolkit: ai_shell.ToolKit):
        usage = toolkit.get_tool_usage_for("ls")
        if usage["count"] > 0:
            return (
                "Great job! You've used ls. Summarize in paragraph form and we're done."
            )
        return (
            "You haven't used the ls tool yet. Do you have access to the ls tool? If"
            " there is a problem report it to the report_text tool to end the session."
        )

    # Creates temporary bots
    bot = ai_shell.TaskBot(
        ai_shell.Config(),
        name="Folder inspection bot.",
        bot_instructions="Run the ls tool and tell me what you see.",
        model="gpt-3.5-turbo-1106",
        dialog_logger_md=ai_shell.DialogLoggerWithMarkdown("./tmp"),
    )
    await bot.initialize()
    the_ask = f"""You are in the './' folder. You do not need to guess the pwd, it is './'. 
    Run ls and tell me what you see in paragraph format."""
    await bot.basic_tool_loop(
        the_ask=the_ask,
        root_folder="./src",
        tool_names=[
            "ls",
            "report_text",
        ],
        keep_going_prompt=static_keep_going,
    )


if __name__ == "__main__":
    asyncio.run(main())

This is the cli interface, which is intended for testing, not for bot usage.

ais cat_markdown --file-paths pyproject.toml

Features in Brief

  • Many cli-like tools interfaces, such as ls, cat, grep, head, tail, and git.
  • OpenAI glue for all cli tools.
  • UX with a bot in mind.
  • Security with mischievous but not especially malicious bot in mind.
  • Bot (Assistant) boilerplate help
  • Support for bots doing one shot tool use and goal function driven tool use.
  • Bot have extensibility points.
  • TODO: plugin system for tools.

Analogues supported today

Directories: ls, find

Files: cat, grep, head, tail

Editing: sed, ed, edlin, patch, replace, insert, rewrite, write new

Data: cut

Other: pycat, token counter, git

Tasking: todo

n.b. Every file is read and written as utf-8 strings.

Prior Art

ai_shell draws inspiration from various command-line interface (CLI) tools and shell environments, integrating features from traditional shells with OpenAI's language models. It is designed to provide an easy and secure interface for AI-assisted file system interactions, keeping in mind both usability and safety.

Documentation

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ai_shell-1.0.3.tar.gz (97.7 kB view details)

Uploaded Source

Built Distribution

ai_shell-1.0.3-py3-none-any.whl (132.1 kB view details)

Uploaded Python 3

File details

Details for the file ai_shell-1.0.3.tar.gz.

File metadata

  • Download URL: ai_shell-1.0.3.tar.gz
  • Upload date:
  • Size: 97.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for ai_shell-1.0.3.tar.gz
Algorithm Hash digest
SHA256 0fd2dcb0fa3b7cd10053abd79f6d5d8c22a3d783c7046835926e245883fad502
MD5 7ad5ff178b9a94c3f0e565afa15f548f
BLAKE2b-256 6ac24fa851c0ccc8be8e61985f0e7a3a2ab76c132dbd76afb9ef9a7f4a762fb0

See more details on using hashes here.

File details

Details for the file ai_shell-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: ai_shell-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 132.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for ai_shell-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 21db92044a9cc7643fd40f49dfeea1a9a80f4c38b9da3965163498eece6f9066
MD5 d7e94b42237d0ea593331ccc54f00049
BLAKE2b-256 1dd3cdcd93b8096afca2c9955c4c6d24987435718806fb71827481b1f5f19a15

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page