Skip to content

Commit

Permalink
Merge branch 'master' into zamilmajdy/open-1911-clashing-node-on-dyna…
Browse files Browse the repository at this point in the history
…mic-input-pin
  • Loading branch information
majdyz authored Oct 9, 2024
2 parents ee1c048 + c582b55 commit 4ee4486
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 13 deletions.
7 changes: 4 additions & 3 deletions autogpt_platform/backend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ REDIS_PORT=6379
REDIS_PASSWORD=password

ENABLE_CREDIT=false
APP_ENV="local"
# What environment things should be logged under: local dev or prod
APP_ENV=local
# What environment to behave as: "local" or "cloud"
BEHAVE_AS=local
PYRO_HOST=localhost
SENTRY_DSN=

Expand Down Expand Up @@ -98,5 +101,3 @@ ENABLE_CLOUD_LOGGING=false
ENABLE_FILE_LOGGING=false
# Use to manually set the log directory
# LOG_DIR=./logs

APP_ENV=local
42 changes: 39 additions & 3 deletions autogpt_platform/backend/backend/blocks/llm.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import ast
import logging
from enum import Enum
from enum import Enum, EnumMeta
from json import JSONDecodeError
from typing import Any, List, NamedTuple
from types import MappingProxyType
from typing import TYPE_CHECKING, Any, List, NamedTuple

if TYPE_CHECKING:
from enum import _EnumMemberT

import anthropic
import ollama
Expand All @@ -12,6 +16,7 @@
from backend.data.block import Block, BlockCategory, BlockOutput, BlockSchema
from backend.data.model import BlockSecret, SchemaField, SecretField
from backend.util import json
from backend.util.settings import BehaveAs, Settings

logger = logging.getLogger(__name__)

Expand All @@ -29,7 +34,26 @@ class ModelMetadata(NamedTuple):
cost_factor: int


class LlmModel(str, Enum):
class LlmModelMeta(EnumMeta):
@property
def __members__(
self: type["_EnumMemberT"],
) -> MappingProxyType[str, "_EnumMemberT"]:
if Settings().config.behave_as == BehaveAs.LOCAL:
members = super().__members__
return members
else:
removed_providers = ["ollama"]
existing_members = super().__members__
members = {
name: member
for name, member in existing_members.items()
if LlmModel[name].provider not in removed_providers
}
return MappingProxyType(members)


class LlmModel(str, Enum, metaclass=LlmModelMeta):
# OpenAI models
O1_PREVIEW = "o1-preview"
O1_MINI = "o1-mini"
Expand Down Expand Up @@ -58,6 +82,18 @@ class LlmModel(str, Enum):
def metadata(self) -> ModelMetadata:
return MODEL_METADATA[self]

@property
def provider(self) -> str:
return self.metadata.provider

@property
def context_window(self) -> int:
return self.metadata.context_window

@property
def cost_factor(self) -> int:
return self.metadata.cost_factor


MODEL_METADATA = {
LlmModel.O1_PREVIEW: ModelMetadata("openai", 32000, cost_factor=60),
Expand Down
4 changes: 2 additions & 2 deletions autogpt_platform/backend/backend/server/rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from backend.executor import ExecutionManager, ExecutionScheduler
from backend.server.model import CreateGraph, SetGraphActiveVersion
from backend.util.service import AppService, expose, get_service_client
from backend.util.settings import Config, Settings
from backend.util.settings import AppEnvironment, Config, Settings

from .utils import get_user_id

Expand Down Expand Up @@ -52,7 +52,7 @@ async def lifespan(self, _: FastAPI):
await db.disconnect()

def run_service(self):
docs_url = "/docs" if settings.config.app_env == "local" else None
docs_url = "/docs" if settings.config.app_env == AppEnvironment.LOCAL else None
app = FastAPI(
title="AutoGPT Agent Server",
description=(
Expand Down
4 changes: 2 additions & 2 deletions autogpt_platform/backend/backend/server/ws_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from backend.server.conn_manager import ConnectionManager
from backend.server.model import ExecutionSubscription, Methods, WsMessage
from backend.util.service import AppProcess
from backend.util.settings import Config, Settings
from backend.util.settings import AppEnvironment, Config, Settings

logger = logging.getLogger(__name__)
settings = Settings()
Expand All @@ -28,7 +28,7 @@ async def lifespan(app: FastAPI):
event_queue.close()


docs_url = "/docs" if settings.config.app_env == "local" else None
docs_url = "/docs" if settings.config.app_env == AppEnvironment.LOCAL else None
app = FastAPI(lifespan=lifespan)
event_queue = RedisEventQueue()
_connection_manager = None
Expand Down
9 changes: 7 additions & 2 deletions autogpt_platform/backend/backend/util/logging.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import os
from backend.util.settings import AppEnvironment, BehaveAs, Settings

settings = Settings()


def configure_logging():
import logging

import autogpt_libs.logging.config

if os.getenv("APP_ENV") != "cloud":
if (
settings.config.behave_as == BehaveAs.LOCAL
or settings.config.app_env == AppEnvironment.LOCAL
):
autogpt_libs.logging.config.configure_logging(force_cloud_logging=False)
else:
autogpt_libs.logging.config.configure_logging(force_cloud_logging=True)
Expand Down
12 changes: 11 additions & 1 deletion autogpt_platform/backend/backend/util/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ class AppEnvironment(str, Enum):
PRODUCTION = "prod"


class BehaveAs(str, Enum):
LOCAL = "local"
CLOUD = "cloud"


class UpdateTrackingModel(BaseModel, Generic[T]):
_updated_fields: Set[str] = PrivateAttr(default_factory=set)

Expand Down Expand Up @@ -130,7 +135,12 @@ class Config(UpdateTrackingModel["Config"], BaseSettings):

app_env: AppEnvironment = Field(
default=AppEnvironment.LOCAL,
description="The name of the app environment.",
description="The name of the app environment: local or dev or prod",
)

behave_as: BehaveAs = Field(
default=BehaveAs.LOCAL,
description="What environment to behave as: local or cloud",
)

backend_cors_allow_origins: List[str] = Field(default_factory=list)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ env:
ENABLE_AUTH: "true"
REDIS_HOST: "redis-prod-master.redis-prod.svc.cluster.local"
REDIS_PORT: "6379"
ANTHROPIC_API_KEY: ""
OPENAI_API_KEY: ""
REDIS_PASSWORD: ""
NUM_GRAPH_WORKERS: 10
Expand Down

0 comments on commit 4ee4486

Please sign in to comment.