diff --git a/.github/workflows/publish-pypi.yml b/.github/workflows/publish-pypi.yml index 3ead5c6..cf9ec31 100644 --- a/.github/workflows/publish-pypi.yml +++ b/.github/workflows/publish-pypi.yml @@ -2,8 +2,8 @@ name: Publish / PyPI on: push: - branches: - - 'main' + # branches: + # - 'main' tags: - 'v*' paths-ignore: diff --git a/golemgpt/actions/http_download.py b/golemgpt/actions/http_download.py index 2350bd2..8f4251b 100644 --- a/golemgpt/actions/http_download.py +++ b/golemgpt/actions/http_download.py @@ -2,7 +2,7 @@ from time import time from typing import Optional, Union from golemgpt.utils.misc import workpath -from golemgpt.utils.http import http_download +from golemgpt.utils.http import http_download, RequestError HTTP_REQUEST_PROMPT = """ Response saved to {out_filename} ({file_size} bytes). @@ -25,14 +25,17 @@ def http_download_action( except ValueError: return f"File {out_filename} is outside of working dir." - response = http_download( - method=method, url=url, path=path, headers=headers, - json=body if isinstance(body, (dict, list)) else None, - body=body if isinstance(body, str) else None, - ) + try: + response = http_download( + method=method, url=url, path=path, headers=headers, + json=body if isinstance(body, (dict, list)) else None, + body=body if isinstance(body, str) else None, + ) + except RequestError as error: + return f"HTTP request failed: {error}" if response.status in (401, 403): - return "HTTP request failed: maybe ask user for credentials?" + return "HTTP request unauthorized: let's ask user for credentials?" file_size = path.stat().st_size return HTTP_REQUEST_PROMPT.format( diff --git a/golemgpt/golems/general.py b/golemgpt/golems/general.py index 161a92b..5d8cd1a 100644 --- a/golemgpt/golems/general.py +++ b/golemgpt/golems/general.py @@ -1,7 +1,5 @@ from golemgpt.actions import ALL_KNOWN_ACTIONS from golemgpt.codex import BaseCodex -from golemgpt.codex import ReasonableCodex -from golemgpt.runners import JustDoRunner from golemgpt.settings import Settings from golemgpt.memory import BaseMemory from golemgpt.utils import console, genkey @@ -24,8 +22,6 @@ class GeneralGolem: cognitron_class = OpenAIToolsCognitron - codex_class = ReasonableCodex - runner_class = JustDoRunner def __init__( self, @@ -42,7 +38,8 @@ def __init__( self.goals = goals self.memory = memory self.settings = settings - self.runner = self.runner_class(settings) + self.codex_class = settings.CODEX_CLASS + self.runner = settings.RUNNER_CLASS(settings) self.core = self.cognitron() def __str__(self) -> str: diff --git a/golemgpt/runners/__init__.py b/golemgpt/runners/__init__.py index c78a3b5..6d3e9ef 100644 --- a/golemgpt/runners/__init__.py +++ b/golemgpt/runners/__init__.py @@ -1,11 +1,5 @@ -from typing import Callable -from golemgpt.settings import Settings from .justdo import JustDoRunner __all__ = [ 'JustDoRunner', ] - - -def default_runner(settings: Settings) -> Callable: - return JustDoRunner(settings) diff --git a/golemgpt/settings.py b/golemgpt/settings.py index 965fe2a..b323514 100644 --- a/golemgpt/settings.py +++ b/golemgpt/settings.py @@ -1,6 +1,6 @@ from enum import IntEnum from pathlib import Path -from pydantic import BaseSettings +from pydantic import BaseSettings, PyObject class Verbosity(IntEnum): @@ -13,6 +13,8 @@ class Verbosity(IntEnum): class Settings(BaseSettings): + """General Golem-GPT settings.""" + GOLEM_DEBUG: bool = False WORKDIR: Path = Path("workdir") VERBOSITY_MAIN: Verbosity = Verbosity.NORMAL @@ -20,7 +22,10 @@ class Settings(BaseSettings): OPENAI_API_KEY: str = "" OPENAI_ORG_ID: str = "" - OPENAI_MODEL: str = "gpt-4-turbo" + OPENAI_MODEL: str = "gpt-4o-mini" + + CODEX_CLASS: PyObject = "golemgpt.codex.ReasonableCodex" + RUNNER_CLASS: PyObject = "golemgpt.runners.JustDoRunner" BING_SEARCH_API_KEY: str = "" diff --git a/golemgpt/utils/http.py b/golemgpt/utils/http.py index d8c7fa2..752298d 100644 --- a/golemgpt/utils/http.py +++ b/golemgpt/utils/http.py @@ -1,9 +1,14 @@ from typing import Any, Dict, Optional, Union from json import dumps as json_dumps, loads as json_loads import urllib3 +import urllib3.exceptions http = urllib3.PoolManager() +RequestError = urllib3.exceptions.RequestError + +DEFAULT_TIMEOUT = 30.0 + def _do_request( method: str, url: str, headers: Optional[Dict[str, str]] = None, @@ -24,6 +29,7 @@ def http_request_streamed( json: Optional[Any] = None, **kwargs: Any ) -> urllib3.HTTPResponse: """Send an HTTP request without preloading, i.e. streamed.""" + kwargs.setdefault("timeout", DEFAULT_TIMEOUT) return _do_request( method=method, url=url, headers=headers, json=json, preload_content=False, **kwargs diff --git a/pyproject.toml b/pyproject.toml index b76566e..9df3714 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "golem-gpt" -version = "0.2.1" +version = "0.2.2-dev1" authors = [ { name="Alexey Kinev", email="rudy@05bit.com" }, ]