Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shu/removeSettingsManager.get_settings #1305

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions skyvern/analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import typer
from posthog import Posthog

from skyvern.forge.sdk.settings_manager import SettingsManager
from skyvern.config import settings

posthog = Posthog(
"phc_bVT2ugnZhMHRWqMvSRHPdeTjaPxQqT3QSsI3r5FlQR5",
Expand All @@ -31,7 +31,7 @@ def analytics_metadata() -> Dict[str, Any]:
"machine": platform.machine(),
"platform": platform.platform(),
"python_version": platform.python_version(),
"environment": SettingsManager.get_settings().ENV,
"environment": settings.ENV,
}


Expand All @@ -40,10 +40,10 @@ def capture(
data: dict[str, Any] | None = None,
) -> None:
# If telemetry is disabled, don't send any data
if not SettingsManager.get_settings().SKYVERN_TELEMETRY:
if not settings.SKYVERN_TELEMETRY:
return

distinct_id = SettingsManager.get_settings().ANALYTICS_ID
distinct_id = settings.ANALYTICS_ID

payload: dict[str, Any] = data or {}
try:
Expand Down
4 changes: 4 additions & 0 deletions skyvern/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class Settings(BaseSettings):
ENABLE_AZURE: bool = False
ENABLE_AZURE_GPT4O_MINI: bool = False
ENABLE_BEDROCK: bool = False
ENABLE_GEMINI: bool = False
# OPENAI
OPENAI_API_KEY: str | None = None
# ANTHROPIC
Expand All @@ -119,6 +120,9 @@ class Settings(BaseSettings):
AZURE_GPT4O_MINI_API_BASE: str | None = None
AZURE_GPT4O_MINI_API_VERSION: str | None = None

# GEMINI
GEMINI_API_KEY: str | None = None

# TOTP Settings
TOTP_LIFESPAN_MINUTES: int = 10
VERIFICATION_CODE_INITIAL_WAIT_TIME_SECS: int = 40
Expand Down
6 changes: 3 additions & 3 deletions skyvern/forge/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
from dotenv import load_dotenv

from skyvern import analytics
from skyvern.forge.sdk.settings_manager import SettingsManager
from skyvern.config import settings

LOG = structlog.stdlib.get_logger()


if __name__ == "__main__":
analytics.capture("skyvern-oss-run-server")
port = SettingsManager.get_settings().PORT
port = settings.PORT
LOG.info("Agent server starting.", host="0.0.0.0", port=port)
load_dotenv()

reload = SettingsManager.get_settings().ENV == "local"
reload = settings.ENV == "local"
uvicorn.run(
"skyvern.forge.api_app:app",
host="0.0.0.0",
Expand Down
50 changes: 24 additions & 26 deletions skyvern/forge/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from playwright.async_api import Page

from skyvern import analytics
from skyvern.config import settings
from skyvern.constants import (
GET_DOWNLOADED_FILES_TIMEOUT,
SAVE_DOWNLOADED_FILES_TIMEOUT,
Expand Down Expand Up @@ -51,7 +52,6 @@
from skyvern.forge.sdk.db.enums import TaskType
from skyvern.forge.sdk.models import Organization, Step, StepStatus
from skyvern.forge.sdk.schemas.tasks import Task, TaskRequest, TaskStatus
from skyvern.forge.sdk.settings_manager import SettingsManager
from skyvern.forge.sdk.workflow.context_manager import WorkflowRunContext
from skyvern.forge.sdk.workflow.models.block import ActionBlock, BaseTaskBlock, ValidationBlock
from skyvern.forge.sdk.workflow.models.workflow import Workflow, WorkflowRun, WorkflowRunStatus
Expand Down Expand Up @@ -84,25 +84,25 @@ def __init__(self, action: Action) -> None:

class ForgeAgent:
def __init__(self) -> None:
if SettingsManager.get_settings().ADDITIONAL_MODULES:
for module in SettingsManager.get_settings().ADDITIONAL_MODULES:
if settings.ADDITIONAL_MODULES:
for module in settings.ADDITIONAL_MODULES:
LOG.info("Loading additional module", module=module)
__import__(module)
LOG.info(
"Additional modules loaded",
modules=SettingsManager.get_settings().ADDITIONAL_MODULES,
modules=settings.ADDITIONAL_MODULES,
)
LOG.info(
"Initializing ForgeAgent",
env=SettingsManager.get_settings().ENV,
execute_all_steps=SettingsManager.get_settings().EXECUTE_ALL_STEPS,
browser_type=SettingsManager.get_settings().BROWSER_TYPE,
max_scraping_retries=SettingsManager.get_settings().MAX_SCRAPING_RETRIES,
video_path=SettingsManager.get_settings().VIDEO_PATH,
browser_action_timeout_ms=SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS,
max_steps_per_run=SettingsManager.get_settings().MAX_STEPS_PER_RUN,
long_running_task_warning_ratio=SettingsManager.get_settings().LONG_RUNNING_TASK_WARNING_RATIO,
debug_mode=SettingsManager.get_settings().DEBUG_MODE,
env=settings.ENV,
execute_all_steps=settings.EXECUTE_ALL_STEPS,
browser_type=settings.BROWSER_TYPE,
max_scraping_retries=settings.MAX_SCRAPING_RETRIES,
video_path=settings.VIDEO_PATH,
browser_action_timeout_ms=settings.BROWSER_ACTION_TIMEOUT_MS,
max_steps_per_run=settings.MAX_STEPS_PER_RUN,
long_running_task_warning_ratio=settings.LONG_RUNNING_TASK_WARNING_RATIO,
debug_mode=settings.DEBUG_MODE,
)
self.async_operation_pool = AsyncOperationPool()

Expand Down Expand Up @@ -290,7 +290,7 @@ async def execute_step(
override_max_steps_per_run
or task.max_steps_per_run
or organization.max_steps_per_run
or SettingsManager.get_settings().MAX_STEPS_PER_RUN
or settings.MAX_STEPS_PER_RUN
)
if max_steps_per_run and task.max_steps_per_run != max_steps_per_run:
await app.DATABASE.update_task(
Expand Down Expand Up @@ -423,7 +423,7 @@ async def execute_step(
close_browser_on_completion=close_browser_on_completion,
task_block=task_block,
)
elif SettingsManager.get_settings().execute_all_steps() and next_step:
elif settings.execute_all_steps() and next_step:
return await self.execute_step(
organization,
task,
Expand All @@ -437,8 +437,8 @@ async def execute_step(
"Step executed but continuous execution is disabled.",
task_id=task.task_id,
step_id=step.step_id,
is_cloud_env=SettingsManager.get_settings().is_cloud_environment(),
execute_all_steps=SettingsManager.get_settings().execute_all_steps(),
is_cloud_env=settings.is_cloud_environment(),
execute_all_steps=settings.execute_all_steps(),
next_step_id=next_step.step_id if next_step else None,
)

Expand Down Expand Up @@ -1342,7 +1342,7 @@ async def _get_action_results(self, task: Task) -> str:
# Get action results from the last app.SETTINGS.PROMPT_ACTION_HISTORY_WINDOW steps
steps = await app.DATABASE.get_task_steps(task_id=task.task_id, organization_id=task.organization_id)
# the last step is always the newly created one and it should be excluded from the history window
window_steps = steps[-1 - SettingsManager.get_settings().PROMPT_ACTION_HISTORY_WINDOW : -1]
window_steps = steps[-1 - settings.PROMPT_ACTION_HISTORY_WINDOW : -1]
actions_and_results: list[tuple[Action, list[ActionResult]]] = []
for window_step in window_steps:
if window_step.output and window_step.output.actions_and_results:
Expand Down Expand Up @@ -1576,7 +1576,7 @@ async def execute_task_webhook(
task_id=task.task_id,
organization_id=task.organization_id,
artifact_types=[ArtifactType.SCREENSHOT_ACTION],
n=SettingsManager.get_settings().TASK_RESPONSE_ACTION_SCREENSHOT_COUNT,
n=settings.TASK_RESPONSE_ACTION_SCREENSHOT_COUNT,
)
if latest_action_screenshot_artifacts:
latest_action_screenshot_urls = await app.ARTIFACT_MANAGER.get_share_links(
Expand Down Expand Up @@ -1790,7 +1790,7 @@ async def handle_failed_step(self, organization: Organization, task: Task, step:
organization.max_retries_per_step
# we need to check by None because 0 is a valid value for max_retries_per_step
if organization.max_retries_per_step is not None
else SettingsManager.get_settings().MAX_RETRIES_PER_STEP
else settings.MAX_RETRIES_PER_STEP
)
if step.retry_index >= max_retries_per_step:
LOG.warning(
Expand All @@ -1799,7 +1799,7 @@ async def handle_failed_step(self, organization: Organization, task: Task, step:
step_id=step.step_id,
step_order=step.order,
step_retry=step.retry_index,
max_retries=SettingsManager.get_settings().MAX_RETRIES_PER_STEP,
max_retries=settings.MAX_RETRIES_PER_STEP,
)
await self.update_task(
task,
Expand Down Expand Up @@ -1923,7 +1923,7 @@ async def handle_completed_step(
override_max_steps_per_run
or task.max_steps_per_run
or organization.max_steps_per_run
or SettingsManager.get_settings().MAX_STEPS_PER_RUN
or settings.MAX_STEPS_PER_RUN
)

# HACK: action block only have one step to execute without complete action, so we consider the task is completed as long as the step is completed
Expand Down Expand Up @@ -1985,14 +1985,12 @@ async def handle_completed_step(
organization_id=task.organization_id,
)

if step.order == int(
max_steps_per_run * SettingsManager.get_settings().LONG_RUNNING_TASK_WARNING_RATIO - 1
):
if step.order == int(max_steps_per_run * settings.LONG_RUNNING_TASK_WARNING_RATIO - 1):
LOG.info(
"Long running task warning",
order=step.order,
max_steps=max_steps_per_run,
warning_ratio=SettingsManager.get_settings().LONG_RUNNING_TASK_WARNING_RATIO,
warning_ratio=settings.LONG_RUNNING_TASK_WARNING_RATIO,
)
return None, None, next_step

Expand Down
10 changes: 5 additions & 5 deletions skyvern/forge/api_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
from starlette_context.middleware import RawContextMiddleware
from starlette_context.plugins.base import Plugin

from skyvern.config import settings
from skyvern.exceptions import SkyvernHTTPException
from skyvern.forge import app as forge_app
from skyvern.forge.sdk.core import skyvern_context
from skyvern.forge.sdk.core.skyvern_context import SkyvernContext
from skyvern.forge.sdk.db.exceptions import NotFoundError
from skyvern.forge.sdk.routes.agent_protocol import base_router
from skyvern.forge.sdk.routes.streaming import websocket_router
from skyvern.forge.sdk.settings_manager import SettingsManager

LOG = structlog.get_logger()

Expand All @@ -40,7 +40,7 @@ def get_agent_app() -> FastAPI:
# Add CORS middleware
app.add_middleware(
CORSMiddleware,
allow_origins=SettingsManager.get_settings().ALLOWED_ORIGINS,
allow_origins=settings.ALLOWED_ORIGINS,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
Expand Down Expand Up @@ -90,13 +90,13 @@ async def request_middleware(request: Request, call_next: Callable[[Request], Aw
finally:
skyvern_context.reset()

if SettingsManager.get_settings().ADDITIONAL_MODULES:
for module in SettingsManager.get_settings().ADDITIONAL_MODULES:
if settings.ADDITIONAL_MODULES:
for module in settings.ADDITIONAL_MODULES:
LOG.info("Loading additional module to set up api app", module=module)
__import__(module)
LOG.info(
"Additional modules loaded to set up api app",
modules=SettingsManager.get_settings().ADDITIONAL_MODULES,
modules=settings.ADDITIONAL_MODULES,
)

if forge_app.setup_api_app:
Expand Down
12 changes: 6 additions & 6 deletions skyvern/forge/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from fastapi import FastAPI

from skyvern.config import settings
from skyvern.forge.agent import ForgeAgent
from skyvern.forge.agent_functions import AgentFunction
from skyvern.forge.sdk.api.llm.api_handler_factory import LLMAPIHandlerFactory
Expand All @@ -12,25 +13,24 @@
from skyvern.forge.sdk.db.client import AgentDB
from skyvern.forge.sdk.experimentation.providers import BaseExperimentationProvider, NoOpExperimentationProvider
from skyvern.forge.sdk.models import Organization
from skyvern.forge.sdk.settings_manager import SettingsManager
from skyvern.forge.sdk.workflow.context_manager import WorkflowContextManager
from skyvern.forge.sdk.workflow.service import WorkflowService
from skyvern.webeye.browser_manager import BrowserManager
from skyvern.webeye.scraper.scraper import ScrapeExcludeFunc

SETTINGS_MANAGER = SettingsManager.get_settings()
SETTINGS_MANAGER = settings
DATABASE = AgentDB(
SettingsManager.get_settings().DATABASE_STRING,
debug_enabled=SettingsManager.get_settings().DEBUG_MODE,
settings.DATABASE_STRING,
debug_enabled=settings.DEBUG_MODE,
)
if SettingsManager.get_settings().SKYVERN_STORAGE_TYPE == "s3":
if settings.SKYVERN_STORAGE_TYPE == "s3":
StorageFactory.set_storage(S3Storage())
STORAGE = StorageFactory.get_storage()
CACHE = CacheFactory.get_cache()
ARTIFACT_MANAGER = ArtifactManager()
BROWSER_MANAGER = BrowserManager()
EXPERIMENTATION_PROVIDER: BaseExperimentationProvider = NoOpExperimentationProvider()
LLM_API_HANDLER = LLMAPIHandlerFactory.get_llm_api_handler(SettingsManager.get_settings().LLM_KEY)
LLM_API_HANDLER = LLMAPIHandlerFactory.get_llm_api_handler(settings.LLM_KEY)
SECONDARY_LLM_API_HANDLER = LLMAPIHandlerFactory.get_llm_api_handler(
SETTINGS_MANAGER.SECONDARY_LLM_KEY if SETTINGS_MANAGER.SECONDARY_LLM_KEY else SETTINGS_MANAGER.LLM_KEY
)
Expand Down
6 changes: 3 additions & 3 deletions skyvern/forge/sdk/api/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import structlog
from aiobotocore.client import AioBaseClient

from skyvern.forge.sdk.settings_manager import SettingsManager
from skyvern.config import settings

LOG = structlog.get_logger()

Expand All @@ -22,7 +22,7 @@ async def wrapper(*args: list[Any], **kwargs: dict[str, Any]) -> Any:
self = args[0]
assert isinstance(self, AsyncAWSClient)
session = aioboto3.Session()
async with session.client(client_type, region_name=SettingsManager.get_settings().AWS_REGION) as client:
async with session.client(client_type, region_name=settings.AWS_REGION) as client:
return await f(*args, client=client, **kwargs)

return wrapper
Expand Down Expand Up @@ -95,7 +95,7 @@ async def create_presigned_urls(self, uris: list[str], client: AioBaseClient = N
url = await client.generate_presigned_url(
"get_object",
Params={"Bucket": parsed_uri.bucket, "Key": parsed_uri.key},
ExpiresIn=SettingsManager.get_settings().PRESIGNED_URL_EXPIRATION,
ExpiresIn=settings.PRESIGNED_URL_EXPIRATION,
)
presigned_urls.append(url)

Expand Down
8 changes: 4 additions & 4 deletions skyvern/forge/sdk/api/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
import structlog
from multidict import CIMultiDictProxy

from skyvern.config import settings
from skyvern.constants import REPO_ROOT_DIR
from skyvern.exceptions import DownloadFileMaxSizeExceeded
from skyvern.forge.sdk.api.aws import AsyncAWSClient
from skyvern.forge.sdk.settings_manager import SettingsManager

LOG = structlog.get_logger()

Expand Down Expand Up @@ -169,7 +169,7 @@ def create_folder_if_not_exist(dir: str) -> None:


def get_skyvern_temp_dir() -> str:
temp_dir = SettingsManager.get_settings().TEMP_PATH
temp_dir = settings.TEMP_PATH
create_folder_if_not_exist(temp_dir)
return temp_dir

Expand All @@ -178,13 +178,13 @@ def make_temp_directory(
suffix: str | None = None,
prefix: str | None = None,
) -> str:
temp_dir = SettingsManager.get_settings().TEMP_PATH
temp_dir = settings.TEMP_PATH
create_folder_if_not_exist(temp_dir)
return tempfile.mkdtemp(suffix=suffix, prefix=prefix, dir=temp_dir)


def create_named_temporary_file(delete: bool = True) -> tempfile._TemporaryFileWrapper:
temp_dir = SettingsManager.get_settings().TEMP_PATH
temp_dir = settings.TEMP_PATH
create_folder_if_not_exist(temp_dir)
return tempfile.NamedTemporaryFile(dir=temp_dir, delete=delete)

Expand Down
Loading
Loading