replace 50+ occurrences of print() with logger (#3056)

Co-authored-by: James Collins <collijk@uw.edu>
Co-authored-by: Luke Kyohere <lkyohere@mfsafrica.com>
Co-authored-by: k-boikov <64261260+k-boikov@users.noreply.github.com>
Co-authored-by: Media <12145726+rihp@users.noreply.github.com>
Co-authored-by: Nicholas Tindle <nick@ntindle.com>
This commit is contained in:
Richard Beales
2023-04-30 05:40:57 +01:00
committed by GitHub
parent 6997bb0bdd
commit 06ae4684c8
20 changed files with 134 additions and 139 deletions

View File

@@ -15,6 +15,7 @@ from auto_gpt_plugin_template import AutoGPTPluginTemplate
from openapi_python_client.cli import Config as OpenAPIConfig
from autogpt.config import Config
from autogpt.logs import logger
from autogpt.models.base_open_ai_plugin import BaseOpenAIPlugin
@@ -33,11 +34,10 @@ def inspect_zip_for_modules(zip_path: str, debug: bool = False) -> list[str]:
with zipfile.ZipFile(zip_path, "r") as zfile:
for name in zfile.namelist():
if name.endswith("__init__.py"):
if debug:
print(f"Found module '{name}' in the zipfile at: {name}")
logger.debug(f"Found module '{name}' in the zipfile at: {name}")
result.append(name)
if debug and len(result) == 0:
print(f"Module '__init__.py' not found in the zipfile @ {zip_path}.")
if len(result) == 0:
logger.debug(f"Module '__init__.py' not found in the zipfile @ {zip_path}.")
return result
@@ -71,12 +71,12 @@ def fetch_openai_plugins_manifest_and_spec(cfg: Config) -> dict:
if response.status_code == 200:
manifest = response.json()
if manifest["schema_version"] != "v1":
print(
logger.warn(
f"Unsupported manifest version: {manifest['schem_version']} for {url}"
)
continue
if manifest["api"]["type"] != "openapi":
print(
logger.warn(
f"Unsupported API type: {manifest['api']['type']} for {url}"
)
continue
@@ -84,11 +84,13 @@ def fetch_openai_plugins_manifest_and_spec(cfg: Config) -> dict:
manifest, f"{openai_plugin_client_dir}/ai-plugin.json"
)
else:
print(f"Failed to fetch manifest for {url}: {response.status_code}")
logger.warn(
f"Failed to fetch manifest for {url}: {response.status_code}"
)
except requests.exceptions.RequestException as e:
print(f"Error while requesting manifest from {url}: {e}")
logger.warn(f"Error while requesting manifest from {url}: {e}")
else:
print(f"Manifest for {url} already exists")
logger.info(f"Manifest for {url} already exists")
manifest = json.load(open(f"{openai_plugin_client_dir}/ai-plugin.json"))
if not os.path.exists(f"{openai_plugin_client_dir}/openapi.json"):
openapi_spec = openapi_python_client._get_document(
@@ -98,7 +100,7 @@ def fetch_openai_plugins_manifest_and_spec(cfg: Config) -> dict:
openapi_spec, f"{openai_plugin_client_dir}/openapi.json"
)
else:
print(f"OpenAPI spec for {url} already exists")
logger.info(f"OpenAPI spec for {url} already exists")
openapi_spec = json.load(open(f"{openai_plugin_client_dir}/openapi.json"))
manifests[url] = {"manifest": manifest, "openapi_spec": openapi_spec}
return manifests
@@ -115,13 +117,13 @@ def create_directory_if_not_exists(directory_path: str) -> bool:
if not os.path.exists(directory_path):
try:
os.makedirs(directory_path)
print(f"Created directory: {directory_path}")
logger.debug(f"Created directory: {directory_path}")
return True
except OSError as e:
print(f"Error creating directory {directory_path}: {e}")
logger.warn(f"Error creating directory {directory_path}: {e}")
return False
else:
print(f"Directory {directory_path} already exists")
logger.info(f"Directory {directory_path} already exists")
return True
@@ -159,7 +161,7 @@ def initialize_openai_plugins(
config=_config,
)
if client_results:
print(
logger.warn(
f"Error creating OpenAPI client: {client_results[0].header} \n"
f" details: {client_results[0].detail}"
)
@@ -212,8 +214,7 @@ def scan_plugins(cfg: Config, debug: bool = False) -> List[AutoGPTPluginTemplate
for module in moduleList:
plugin = Path(plugin)
module = Path(module)
if debug:
print(f"Plugin: {plugin} Module: {module}")
logger.debug(f"Plugin: {plugin} Module: {module}")
zipped_package = zipimporter(str(plugin))
zipped_module = zipped_package.load_module(str(module.parent))
for key in dir(zipped_module):
@@ -240,9 +241,9 @@ def scan_plugins(cfg: Config, debug: bool = False) -> List[AutoGPTPluginTemplate
loaded_plugins.append(plugin)
if loaded_plugins:
print(f"\nPlugins found: {len(loaded_plugins)}\n" "--------------------")
logger.info(f"\nPlugins found: {len(loaded_plugins)}\n" "--------------------")
for plugin in loaded_plugins:
print(f"{plugin._name}: {plugin._version} - {plugin._description}")
logger.info(f"{plugin._name}: {plugin._version} - {plugin._description}")
return loaded_plugins