Skip to content

Commit

Permalink
liqun/fix logging issue (microsoft#139)
Browse files Browse the repository at this point in the history
fix annoying logs
  • Loading branch information
liqul authored Jan 18, 2024
1 parent 8de53e0 commit 9da1329
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
13 changes: 7 additions & 6 deletions project/plugins/vision_web_explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import json
import time
from io import BytesIO
from typing import Any, Dict, List, Tuple
from typing import Dict, List, Tuple

import requests

Expand All @@ -18,7 +18,6 @@
raise ImportError("Please install selenium first.")

from taskweaver.plugin import Plugin, register_plugin
from taskweaver.plugin.context import PluginContext


# Function to encode the image
Expand Down Expand Up @@ -598,21 +597,23 @@ def get_objective_done(

@register_plugin
class VisionWebBrowser(Plugin):
def __init__(self, name: str, ctx: PluginContext, config: Dict[str, Any]):
super().__init__(name, ctx, config)
vision_planner: VisionPlanner = None

def _init(self):
driver = None
try:
GPT4V_KEY = self.config.get("api_key")
GPT4V_ENDPOINT = self.config.get("endpoint")
driver = SeleniumDriver(chrome_driver_path=self.config.get("driver_path"), mobile_emulation=False)
self.vision_planner = VisionPlanner(api_key=GPT4V_KEY, endpoint=GPT4V_ENDPOINT, driver=driver)
except Exception as e:
print(e)
if driver is not None:
driver.quit()
raise Exception("Failed to initialize the plugin.")
raise Exception(f"Failed to initialize the plugin due to: {e}")

def __call__(self, request: str, additional_info: str = None):
if self.vision_planner is None:
self._init()
try:
done_message = self.vision_planner.get_objective_done(request, additional_info)
except Exception as e:
Expand Down
4 changes: 2 additions & 2 deletions taskweaver/memory/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from injector import Module, provider

from taskweaver.config.module_config import ModuleConfig
from taskweaver.misc.component_registry import ComponentRegistry
from taskweaver.misc.component_registry import ComponentDisabledException, ComponentRegistry
from taskweaver.utils import read_yaml, validate_yaml


Expand Down Expand Up @@ -272,7 +272,7 @@ def _load_component(self, path: str) -> Tuple[str, PluginEntry]:
if entry is None:
raise Exception(f"failed to loading plugin from {path}")
if not entry.enabled:
raise Exception(f"plugin {entry.name} is disabled")
raise ComponentDisabledException(f"plugin {entry.name} is disabled")
return entry.name, entry


Expand Down
6 changes: 6 additions & 0 deletions taskweaver/misc/component_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
component_type = TypeVar("component_type")


class ComponentDisabledException(Exception):
pass


class ComponentRegistry(ABC, Generic[component_type]):
def __init__(self, file_glob: str, ttl: Optional[timedelta] = None) -> None:
super().__init__()
Expand Down Expand Up @@ -42,6 +46,8 @@ def get_registry(
for path in glob.glob(self._file_glob):
try:
name, component = self._load_component(path)
except ComponentDisabledException:
continue
except Exception as e:
if show_error:
print(f"failed to loading component from {path}, skipping: {e}")
Expand Down

0 comments on commit 9da1329

Please sign in to comment.