Tools

Adapted from Auto-GPT (https://github.com/Significant-Gravitas/Auto-GPT)

class loopgpt.tools.browser.Browser(browser_type='chrome')

This opens a browser. It opens the url and finds the answer for the query. Provide an empty query if you want to summarize the page.

Parameters:
  • url (str) – URL to open.

  • query (str) – Query to search for.

Returns:

Relevant summary and a list of links extracted from the URL.

Return type:

Dict

Adapted from Auto-GPT (https://github.com/Significant-Gravitas/Auto-GPT)

class loopgpt.tools.simple_browser.SimpleBrowser

Alternative browser implementation that uses requests library instead of the default Google Chrome implementation.

Usage:

` import loopgpt agent = loopgpt.Agent(...) agent.tools["browser"] = SimpleBrowser() `

class loopgpt.tools.filesystem.AppendToFile(*args, **kwargs)

Appends content to the end of a file. Creates the file if it does not exist.

Parameters:
  • file (str) – Path of the file to append to.

  • content (str) – Content to be appended to the file.

Returns:

True if the file was successfully appended to. Else False.

Return type:

bool

class loopgpt.tools.filesystem.CheckIfFileExists(*args, **kwargs)

Checks if a file exists.

Parameters:

file (str) – Path to the file to check.

Returns:

True if the file exists. Else False.

Return type:

bool

class loopgpt.tools.filesystem.DeleteFile(*args, **kwargs)

Deletes a file.

Parameters:

file (str) – Path to the file to be deleted.

Returns:

True if the file was successfully deleted. Else False.

Return type:

bool

class loopgpt.tools.filesystem.GetCWD(*args, **kwargs)

Get the current working directory.

Returns:

Path to the current working directory.

Return type:

str

class loopgpt.tools.filesystem.ListFiles(*args, **kwargs)

List files and directories in a given path. Directories end with a trailing slash.

Parameters:
  • path (str) – Path to the directory to list files and directories in.

  • recursive (bool) – If true, list files and directories recursively. Else, list only the files and directories in the given path.

  • show_hidden (bool) – If true, show hidden files and directories. Defaults to False.

  • exclude_dirs (bool) – If true, exclude directories from the result. Defaults to False.

Returns:

List of files and directories.

Return type:

List[str]

class loopgpt.tools.filesystem.MakeDirectory(*args, **kwargs)

Create a new directory at the given path.

Parameters:

path (str) – Path of the directory to be made.

Returns:

True if the directory was created, False otherwise.

Return type:

bool

class loopgpt.tools.filesystem.ReadFromFile(*args, **kwargs)

Reads the contents of a file.

Parameters:

file (str) – Path to the file to read.

Returns:

Contents of the file.

Return type:

str

class loopgpt.tools.filesystem.WriteToFile(*args, **kwargs)

Write content to a file. This will overwrite the file if it already exists.

Parameters:
  • file (str) – Path of the file to write to.

  • content (str) – Content to be written to the file.

Returns:

True if the file was successfully written to. Else False.

Return type:

bool

class loopgpt.tools.shell.Shell(*args, **kwargs)

Execute terminal commands.

Parameters:

command (str) – The command to execute.

Returns:

A dict containing the STDOUT and STDERR of the command.

Return type:

Dict[str, str]

class loopgpt.tools.code.ExecutePythonFile(*args, **kwargs)

Execute a Python file and return the output.

Parameters:

file (str) – Path to the Python file.

Returns:

Value of stdout if the execution was successful. Else error message.

Return type:

str

class loopgpt.tools.code.ImproveCode(*args, **kwargs)

Improve a piece of code given a list of suggestions.

Parameters:
  • code (str) – The code to improve.

  • suggestions (List[str]) – List of suggestions

Returns:

Improved code.

Return type:

str

class loopgpt.tools.code.ReviewCode(*args, **kwargs)

Review a piece of code and return a list of suggestions to improve it.

Parameters:

code (str) – Code to evaluate.

Returns:

List of suggestions to improve the code.

Return type:

List[str]

class loopgpt.tools.code.WriteTests(*args, **kwargs)

Write tests for a piece of code.

Parameters:

code (str) – Code to write tests for.

Returns:

Tests.

Return type:

str

loopgpt.tools.code.ai_function(func, desc, args, model: BaseModel)

Credits: Auto-GPT (https://github.com/Significant-Gravitas/Auto-GPT) Also see: https://github.com/Torantulino/AI-Functions

class loopgpt.tools.math.EvaluateMath(*args, **kwargs)

Evaluate simple math expressions.

Parameters:

expression (str) – The expression to evaluate.

Returns:

The result of the expression.

Return type:

str

class loopgpt.tools.memory_manager.AddToMemory(*args, **kwargs)

Add text to memory for later use.

Parameters:

text (str) – Text to be added to memory.

Returns:

True if the text was successfully added to memory. Else False.

Return type:

bool

class loopgpt.tools.user_manager.AskUser(*args, **kwargs)

Ask the user a question.

Parameters:

message (str) – The question for the user.

Returns:

The response from the user.

Return type:

str