Skip to content

Commit

Permalink
isort implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
waynehamadi committed Apr 17, 2023
1 parent 9577468 commit cf9a94a
Show file tree
Hide file tree
Showing 45 changed files with 232 additions and 183 deletions.
3 changes: 3 additions & 0 deletions autogpt/__main__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
"""Main script for the autogpt package."""
import logging

from colorama import Fore

from autogpt.agent.agent import Agent
from autogpt.args import parse_arguments
from autogpt.config import Config, check_openai_api_key
from autogpt.logs import logger
from autogpt.memory import get_memory
from autogpt.prompt import construct_prompt

# Load environment variables from .env file


Expand Down
4 changes: 2 additions & 2 deletions autogpt/agent/agent.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from colorama import Fore, Style
from autogpt.app import execute_command, get_command

from autogpt.app import execute_command, get_command
from autogpt.chat import chat_with_ai, create_chat_message
from autogpt.config import Config
from autogpt.json_fixes.master_json_fix_method import fix_json_using_multiple_techniques
Expand Down Expand Up @@ -84,7 +84,7 @@ def start_interaction_loop(self):

# Print Assistant thoughts
if assistant_reply_json != {}:
validate_json(assistant_reply_json, 'llm_response_format_1')
validate_json(assistant_reply_json, "llm_response_format_1")
# Get command name and arguments
try:
print_assistant_thoughts(self.ai_name, assistant_reply_json)
Expand Down
4 changes: 3 additions & 1 deletion autogpt/agent/agent_manager.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"""Agent manager for managing GPT agents"""
from __future__ import annotations

from typing import Union
from autogpt.llm_utils import create_chat_completion

from autogpt.config.config import Singleton
from autogpt.llm_utils import create_chat_completion


class AgentManager(metaclass=Singleton):
Expand Down
35 changes: 19 additions & 16 deletions autogpt/app.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
""" Command and Control """
import json
from typing import List, NoReturn, Union, Dict
from typing import Dict, List, NoReturn, Union

from autogpt.agent.agent_manager import AgentManager
from autogpt.commands.evaluate_code import evaluate_code
from autogpt.commands.google_search import google_official_search, google_search
from autogpt.commands.improve_code import improve_code
from autogpt.commands.write_tests import write_tests
from autogpt.config import Config
from autogpt.commands.image_gen import generate_image
from autogpt.commands.audio_text import read_audio_from_file
from autogpt.commands.web_requests import scrape_links, scrape_text
from autogpt.commands.evaluate_code import evaluate_code
from autogpt.commands.execute_code import (
execute_python_file,
execute_shell,
Expand All @@ -18,19 +13,24 @@
from autogpt.commands.file_operations import (
append_to_file,
delete_file,
download_file,
read_file,
search_files,
write_to_file,
download_file
)
from autogpt.commands.git_operations import clone_repository
from autogpt.commands.google_search import google_official_search, google_search
from autogpt.commands.image_gen import generate_image
from autogpt.commands.improve_code import improve_code
from autogpt.commands.twitter import send_tweet
from autogpt.commands.web_requests import scrape_links, scrape_text
from autogpt.commands.web_selenium import browse_website
from autogpt.commands.write_tests import write_tests
from autogpt.config import Config
from autogpt.json_fixes.parsing import fix_and_parse_json
from autogpt.memory import get_memory
from autogpt.processing.text import summarize_text
from autogpt.speech import say_text
from autogpt.commands.web_selenium import browse_website
from autogpt.commands.git_operations import clone_repository
from autogpt.commands.twitter import send_tweet


CFG = Config()
AGENT_MANAGER = AgentManager()
Expand Down Expand Up @@ -133,11 +133,14 @@ def execute_command(command_name: str, arguments):

# google_result can be a list or a string depending on the search results
if isinstance(google_result, list):
safe_message = [google_result_single.encode('utf-8', 'ignore') for google_result_single in google_result]
safe_message = [
google_result_single.encode("utf-8", "ignore")
for google_result_single in google_result
]
else:
safe_message = google_result.encode('utf-8', 'ignore')
safe_message = google_result.encode("utf-8", "ignore")

return safe_message.decode('utf-8')
return safe_message.decode("utf-8")
elif command_name == "memory_add":
memory = get_memory(CFG)
return memory.add(arguments["string"])
Expand Down
26 changes: 17 additions & 9 deletions autogpt/args.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""This module contains the argument parsing logic for the script."""
import argparse

from colorama import Fore, Back, Style
from colorama import Back, Fore, Style

from autogpt import utils
from autogpt.config import Config
from autogpt.logs import logger
Expand Down Expand Up @@ -64,10 +65,10 @@ def parse_arguments() -> None:
" skip the re-prompt.",
)
parser.add_argument(
'--allow-downloads',
action='store_true',
dest='allow_downloads',
help='Dangerous: Allows Auto-GPT to download files natively.'
"--allow-downloads",
action="store_true",
dest="allow_downloads",
help="Dangerous: Allows Auto-GPT to download files natively.",
)
args = parser.parse_args()

Expand Down Expand Up @@ -141,10 +142,17 @@ def parse_arguments() -> None:

if args.allow_downloads:
logger.typewriter_log("Native Downloading:", Fore.GREEN, "ENABLED")
logger.typewriter_log("WARNING: ", Fore.YELLOW,
f"{Back.LIGHTYELLOW_EX}Auto-GPT will now be able to download and save files to your machine.{Back.RESET} " +
"It is recommended that you monitor any files it downloads carefully.")
logger.typewriter_log("WARNING: ", Fore.YELLOW, f"{Back.RED + Style.BRIGHT}ALWAYS REMEMBER TO NEVER OPEN FILES YOU AREN'T SURE OF!{Style.RESET_ALL}")
logger.typewriter_log(
"WARNING: ",
Fore.YELLOW,
f"{Back.LIGHTYELLOW_EX}Auto-GPT will now be able to download and save files to your machine.{Back.RESET} "
+ "It is recommended that you monitor any files it downloads carefully.",
)
logger.typewriter_log(
"WARNING: ",
Fore.YELLOW,
f"{Back.RED + Style.BRIGHT}ALWAYS REMEMBER TO NEVER OPEN FILES YOU AREN'T SURE OF!{Style.RESET_ALL}",
)
CFG.allow_downloads = True

if args.browser_name:
Expand Down
3 changes: 2 additions & 1 deletion autogpt/commands/audio_text.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import requests
import json

import requests

from autogpt.config import Config
from autogpt.workspace import path_in_workspace

Expand Down
2 changes: 1 addition & 1 deletion autogpt/commands/execute_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import docker
from docker.errors import ImageNotFound

from autogpt.workspace import path_in_workspace, WORKSPACE_PATH
from autogpt.workspace import WORKSPACE_PATH, path_in_workspace


def execute_python_file(file: str) -> str:
Expand Down
22 changes: 11 additions & 11 deletions autogpt/commands/file_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import os.path
from pathlib import Path
from typing import Generator, List

import requests
from requests.adapters import HTTPAdapter
from requests.adapters import Retry
from colorama import Fore, Back
from colorama import Back, Fore
from requests.adapters import HTTPAdapter, Retry

from autogpt.spinner import Spinner
from autogpt.utils import readable_file_size
from autogpt.workspace import path_in_workspace, WORKSPACE_PATH

from autogpt.workspace import WORKSPACE_PATH, path_in_workspace

LOG_FILE = "file_logger.txt"
LOG_FILE_PATH = WORKSPACE_PATH / LOG_FILE
Expand Down Expand Up @@ -47,7 +47,7 @@ def log_operation(operation: str, filename: str) -> None:
with open(LOG_FILE_PATH, "w", encoding="utf-8") as f:
f.write("File Operation Logger ")

append_to_file(LOG_FILE, log_entry, shouldLog = False)
append_to_file(LOG_FILE, log_entry, shouldLog=False)


def split_file(
Expand Down Expand Up @@ -241,23 +241,23 @@ def download_file(url, filename):
session = requests.Session()
retry = Retry(total=3, backoff_factor=1, status_forcelist=[502, 503, 504])
adapter = HTTPAdapter(max_retries=retry)
session.mount('http://', adapter)
session.mount('https://', adapter)
session.mount("http://", adapter)
session.mount("https://", adapter)

total_size = 0
downloaded_size = 0

with session.get(url, allow_redirects=True, stream=True) as r:
r.raise_for_status()
total_size = int(r.headers.get('Content-Length', 0))
total_size = int(r.headers.get("Content-Length", 0))
downloaded_size = 0

with open(safe_filename, 'wb') as f:
with open(safe_filename, "wb") as f:
for chunk in r.iter_content(chunk_size=8192):
f.write(chunk)
downloaded_size += len(chunk)

# Update the progress message
# Update the progress message
progress = f"{readable_file_size(downloaded_size)} / {readable_file_size(total_size)}"
spinner.update_message(f"{message} {progress}")

Expand Down
1 change: 1 addition & 0 deletions autogpt/commands/git_operations.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Git operations for autogpt"""
import git

from autogpt.config import Config
from autogpt.workspace import path_in_workspace

Expand Down
1 change: 1 addition & 0 deletions autogpt/commands/image_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import openai
import requests
from PIL import Image

from autogpt.config import Config
from autogpt.workspace import path_in_workspace

Expand Down
3 changes: 2 additions & 1 deletion autogpt/commands/twitter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import tweepy
import os

import tweepy
from dotenv import load_dotenv

load_dotenv()
Expand Down
1 change: 1 addition & 0 deletions autogpt/commands/web_playwright.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"Playwright not installed. Please install it with 'pip install playwright' to use."
)
from bs4 import BeautifulSoup

from autogpt.processing.html import extract_hyperlinks, format_hyperlinks


Expand Down
6 changes: 3 additions & 3 deletions autogpt/commands/web_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from urllib.parse import urljoin, urlparse

import requests
from requests.compat import urljoin
from requests import Response
from bs4 import BeautifulSoup
from requests import Response
from requests.compat import urljoin

from autogpt.config import Config
from autogpt.memory import get_memory
Expand Down Expand Up @@ -79,7 +79,7 @@ def check_local_file_access(url: str) -> bool:
"http://0000",
"http://0000/",
"https://0000",
"https://0000/"
"https://0000/",
]
return any(url.startswith(prefix) for prefix in local_prefixes)

Expand Down
24 changes: 13 additions & 11 deletions autogpt/commands/web_selenium.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
"""Selenium web scraping module."""
from __future__ import annotations

from selenium import webdriver
from autogpt.processing.html import extract_hyperlinks, format_hyperlinks
import autogpt.processing.text as summary
import logging
from pathlib import Path
from sys import platform

from bs4 import BeautifulSoup
from selenium.webdriver.remote.webdriver import WebDriver
from selenium import webdriver
from selenium.webdriver.chrome.options import Options as ChromeOptions
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.firefox.options import Options as FirefoxOptions
from selenium.webdriver.remote.webdriver import WebDriver
from selenium.webdriver.safari.options import Options as SafariOptions
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.firefox import GeckoDriverManager
from selenium.webdriver.chrome.options import Options as ChromeOptions
from selenium.webdriver.firefox.options import Options as FirefoxOptions
from selenium.webdriver.safari.options import Options as SafariOptions
import logging
from pathlib import Path

import autogpt.processing.text as summary
from autogpt.config import Config
from sys import platform
from autogpt.processing.html import extract_hyperlinks, format_hyperlinks

FILE_DIR = Path(__file__).parent.parent
CFG = Config()
Expand Down
1 change: 1 addition & 0 deletions autogpt/commands/write_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import annotations

import json

from autogpt.llm_utils import call_ai_function


Expand Down
2 changes: 1 addition & 1 deletion autogpt/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
This module contains the configuration classes for AutoGPT.
"""
from autogpt.config.ai_config import AIConfig
from autogpt.config.config import check_openai_api_key, Config
from autogpt.config.config import Config, check_openai_api_key
from autogpt.config.singleton import AbstractSingleton, Singleton

__all__ = [
Expand Down
1 change: 1 addition & 0 deletions autogpt/config/ai_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import os
from typing import Type

import yaml


Expand Down
11 changes: 6 additions & 5 deletions autogpt/config/config.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
"""Configuration class to store the state of bools for different scripts access."""
import os
from colorama import Fore

from autogpt.config.singleton import Singleton

import openai
import yaml

from colorama import Fore
from dotenv import load_dotenv

from autogpt.config.singleton import Singleton

load_dotenv(verbose=True)


Expand Down Expand Up @@ -74,7 +73,9 @@ def __init__(self) -> None:
self.weaviate_scopes = os.getenv("WEAVIATE_SCOPES", None)
self.weaviate_embedded_path = os.getenv("WEAVIATE_EMBEDDED_PATH")
self.weaviate_api_key = os.getenv("WEAVIATE_API_KEY", None)
self.use_weaviate_embedded = os.getenv("USE_WEAVIATE_EMBEDDED", "False") == "True"
self.use_weaviate_embedded = (
os.getenv("USE_WEAVIATE_EMBEDDED", "False") == "True"
)

# milvus configuration, e.g., localhost:19530.
self.milvus_addr = os.getenv("MILVUS_ADDR", "localhost:19530")
Expand Down
2 changes: 1 addition & 1 deletion autogpt/json_fixes/auto_fix.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""This module contains the function to fix JSON strings using GPT-3."""
import json

from autogpt.config import Config
from autogpt.llm_utils import call_ai_function
from autogpt.logs import logger
from autogpt.config import Config

CFG = Config()

Expand Down
1 change: 1 addition & 0 deletions autogpt/json_fixes/bracket_termination.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import contextlib
import json
from typing import Optional

from autogpt.config import Config

CFG = Config()
Expand Down
Loading

0 comments on commit cf9a94a

Please sign in to comment.