Skip to content

Commit

Permalink
Customize codex and runner via settings; HTTP timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
rudyryk committed Aug 25, 2024
1 parent 926d83e commit ca762a2
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 23 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/publish-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name: Publish / PyPI

on:
push:
branches:
- 'main'
# branches:
# - 'main'
tags:
- 'v*'
paths-ignore:
Expand Down
17 changes: 10 additions & 7 deletions golemgpt/actions/http_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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(
Expand Down
7 changes: 2 additions & 5 deletions golemgpt/golems/general.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -24,8 +22,6 @@

class GeneralGolem:
cognitron_class = OpenAIToolsCognitron
codex_class = ReasonableCodex
runner_class = JustDoRunner

def __init__(
self,
Expand All @@ -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:
Expand Down
6 changes: 0 additions & 6 deletions golemgpt/runners/__init__.py
Original file line number Diff line number Diff line change
@@ -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)
9 changes: 7 additions & 2 deletions golemgpt/settings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from enum import IntEnum
from pathlib import Path
from pydantic import BaseSettings
from pydantic import BaseSettings, PyObject


class Verbosity(IntEnum):
Expand All @@ -13,14 +13,19 @@ class Verbosity(IntEnum):


class Settings(BaseSettings):
"""General Golem-GPT settings."""

GOLEM_DEBUG: bool = False
WORKDIR: Path = Path("workdir")
VERBOSITY_MAIN: Verbosity = Verbosity.NORMAL
VERBOSITY_CODEX: Verbosity = Verbosity.SILENT

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 = ""

Expand Down
6 changes: 6 additions & 0 deletions golemgpt/utils/http.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
]
Expand Down

0 comments on commit ca762a2

Please sign in to comment.