add SkyvernClient (#1943)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from ddtrace import tracer
|
||||
from ddtrace.filters import FilterRequestsOnUrl
|
||||
|
||||
from skyvern.agent import SkyvernAgent, SkyvernClient
|
||||
from skyvern.forge.sdk.forge_log import setup_logger
|
||||
|
||||
tracer.configure(
|
||||
@@ -11,3 +12,5 @@ tracer.configure(
|
||||
},
|
||||
)
|
||||
setup_logger()
|
||||
|
||||
__all__ = ["SkyvernAgent", "SkyvernClient"]
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from skyvern.agent.local import Agent
|
||||
from skyvern.agent.agent import SkyvernAgent
|
||||
from skyvern.agent.client import SkyvernClient
|
||||
|
||||
__all__ = ["Agent"]
|
||||
__all__ = ["SkyvernAgent", "SkyvernClient"]
|
||||
|
||||
@@ -15,7 +15,7 @@ from skyvern.forge.sdk.workflow.models.workflow import WorkflowRunStatus
|
||||
from skyvern.utils import migrate_db
|
||||
|
||||
|
||||
class Agent:
|
||||
class SkyvernAgent:
|
||||
def __init__(self) -> None:
|
||||
load_dotenv(".env")
|
||||
migrate_db()
|
||||
73
skyvern/agent/client.py
Normal file
73
skyvern/agent/client.py
Normal file
@@ -0,0 +1,73 @@
|
||||
from enum import StrEnum
|
||||
|
||||
import httpx
|
||||
|
||||
from skyvern.config import settings
|
||||
from skyvern.exceptions import SkyvernClientException
|
||||
from skyvern.forge.sdk.schemas.task_runs import TaskRunResponse
|
||||
from skyvern.forge.sdk.schemas.tasks import ProxyLocation
|
||||
from skyvern.forge.sdk.workflow.models.workflow import WorkflowRunStatusResponse
|
||||
|
||||
|
||||
class RunEngine(StrEnum):
|
||||
skyvern_v1 = "skyvern-1.0"
|
||||
skyvern_v2 = "skyvern-2.0"
|
||||
|
||||
|
||||
class SkyvernClient:
|
||||
def __init__(
|
||||
self,
|
||||
base_url: str = settings.SKYVERN_BASE_URL,
|
||||
api_key: str = settings.SKYVERN_API_KEY,
|
||||
) -> None:
|
||||
self.base_url = base_url
|
||||
self.api_key = api_key
|
||||
|
||||
async def run_task(
|
||||
self,
|
||||
goal: str,
|
||||
engine: RunEngine = RunEngine.skyvern_v1,
|
||||
url: str | None = None,
|
||||
webhook_url: str | None = None,
|
||||
totp_identifier: str | None = None,
|
||||
totp_url: str | None = None,
|
||||
title: str | None = None,
|
||||
error_code_mapping: dict[str, str] | None = None,
|
||||
proxy_location: ProxyLocation | None = None,
|
||||
max_steps: int | None = None,
|
||||
) -> TaskRunResponse:
|
||||
if engine == RunEngine.skyvern_v1:
|
||||
return TaskRunResponse()
|
||||
elif engine == RunEngine.skyvern_v2:
|
||||
return TaskRunResponse()
|
||||
raise ValueError(f"Invalid engine: {engine}")
|
||||
|
||||
async def run_workflow(
|
||||
self,
|
||||
workflow_id: str,
|
||||
webhook_url: str | None = None,
|
||||
proxy_location: ProxyLocation | None = None,
|
||||
) -> TaskRunResponse:
|
||||
return TaskRunResponse()
|
||||
|
||||
async def get_run(
|
||||
self,
|
||||
run_id: str,
|
||||
) -> TaskRunResponse:
|
||||
return TaskRunResponse()
|
||||
|
||||
async def get_workflow_run(
|
||||
self,
|
||||
workflow_run_id: str,
|
||||
) -> WorkflowRunStatusResponse:
|
||||
async with httpx.AsyncClient() as client:
|
||||
response = await client.get(
|
||||
f"{self.base_url}/api/v1/workflows/runs/{workflow_run_id}",
|
||||
headers={"x-api-key": self.api_key},
|
||||
)
|
||||
if response.status_code != 200:
|
||||
raise SkyvernClientException(
|
||||
f"Failed to get workflow run: {response.text}",
|
||||
status_code=response.status_code,
|
||||
)
|
||||
return WorkflowRunStatusResponse.model_validate(response.json())
|
||||
@@ -48,8 +48,6 @@ class Settings(BaseSettings):
|
||||
SIGNATURE_ALGORITHM: str = "HS256"
|
||||
ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 * 24 * 7 # one week
|
||||
|
||||
SKYVERN_API_KEY: str = "PLACEHOLDER"
|
||||
|
||||
# Artifact storage settings
|
||||
ARTIFACT_STORAGE_PATH: str = f"{SKYVERN_DIR}/artifacts"
|
||||
GENERATE_PRESIGNED_URLS: bool = False
|
||||
@@ -166,6 +164,10 @@ class Settings(BaseSettings):
|
||||
ENABLE_LOG_ARTIFACTS: bool = False
|
||||
ENABLE_CODE_BLOCK: bool = False
|
||||
|
||||
# SkyvernClient Settings
|
||||
SKYVERN_BASE_URL: str = "https://api.skyvern.com"
|
||||
SKYVERN_API_KEY: str = "PLACEHOLDER"
|
||||
|
||||
def is_cloud_environment(self) -> bool:
|
||||
"""
|
||||
:return: True if env is not local, else False
|
||||
|
||||
@@ -9,6 +9,12 @@ class SkyvernException(Exception):
|
||||
super().__init__(message)
|
||||
|
||||
|
||||
class SkyvernClientException(SkyvernException):
|
||||
def __init__(self, message: str | None = None, status_code: int | None = None):
|
||||
self.status_code = status_code
|
||||
super().__init__(message)
|
||||
|
||||
|
||||
class SkyvernHTTPException(SkyvernException):
|
||||
def __init__(self, message: str | None = None, status_code: int = status.HTTP_400_BAD_REQUEST):
|
||||
self.status_code = status_code
|
||||
|
||||
@@ -5,7 +5,6 @@ from skyvern.forge.sdk.api.llm.exceptions import (
|
||||
DuplicateLLMConfigError,
|
||||
InvalidLLMConfigError,
|
||||
MissingLLMProviderEnvVarsError,
|
||||
NoProviderEnabledError,
|
||||
)
|
||||
from skyvern.forge.sdk.api.llm.models import LiteLLMParams, LLMConfig, LLMRouterConfig
|
||||
|
||||
@@ -55,7 +54,10 @@ if not any(
|
||||
settings.ENABLE_NOVITA,
|
||||
]
|
||||
):
|
||||
raise NoProviderEnabledError()
|
||||
LOG.warning(
|
||||
"At least one LLM provider must be enabled. Run setup.sh and follow through the LLM provider setup, or "
|
||||
"update the .env file (check out .env.example to see the required environment variables)."
|
||||
)
|
||||
|
||||
|
||||
if settings.ENABLE_OPENAI:
|
||||
|
||||
@@ -674,7 +674,7 @@ async def get_workflow_runs_by_id(
|
||||
"/workflows/{workflow_id}/runs/{workflow_run_id}/",
|
||||
include_in_schema=False,
|
||||
)
|
||||
async def get_workflow_run(
|
||||
async def get_workflow_run_with_workflow_id(
|
||||
workflow_id: str,
|
||||
workflow_run_id: str,
|
||||
current_org: Organization = Depends(org_auth_service.get_current_org),
|
||||
@@ -721,7 +721,7 @@ async def get_workflow_run_timeline(
|
||||
response_model=WorkflowRunStatusResponse,
|
||||
include_in_schema=False,
|
||||
)
|
||||
async def get_workflow_run_by_run_id(
|
||||
async def get_workflow_run(
|
||||
workflow_run_id: str,
|
||||
current_org: Organization = Depends(org_auth_service.get_current_org),
|
||||
) -> WorkflowRunStatusResponse:
|
||||
|
||||
Reference in New Issue
Block a user