SDK: fix api-key in local mode (#4213)
This commit is contained in:
committed by
GitHub
parent
1f6309c405
commit
65e3388433
@@ -1,8 +1,11 @@
|
|||||||
|
import os
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
from httpx import ASGITransport
|
from httpx import ASGITransport
|
||||||
|
|
||||||
|
from skyvern.config import settings
|
||||||
|
from skyvern.forge.api_app import create_api_app
|
||||||
from skyvern.forge.sdk.api.llm.config_registry import LLMConfigRegistry
|
from skyvern.forge.sdk.api.llm.config_registry import LLMConfigRegistry
|
||||||
from skyvern.forge.sdk.api.llm.models import LLMConfig, LLMRouterConfig
|
from skyvern.forge.sdk.api.llm.models import LLMConfig, LLMRouterConfig
|
||||||
|
|
||||||
@@ -14,11 +17,10 @@ def create_embedded_server(
|
|||||||
class EmbeddedServerTransport(httpx.AsyncBaseTransport):
|
class EmbeddedServerTransport(httpx.AsyncBaseTransport):
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self._transport: ASGITransport | None = None
|
self._transport: ASGITransport | None = None
|
||||||
|
self._api_key: str | None = None
|
||||||
|
|
||||||
async def handle_async_request(self, request: httpx.Request) -> httpx.Response:
|
async def handle_async_request(self, request: httpx.Request) -> httpx.Response:
|
||||||
if self._transport is None:
|
if self._transport is None:
|
||||||
from skyvern.config import settings # noqa: PLC0415
|
|
||||||
|
|
||||||
settings.BROWSER_LOGS_ENABLED = False
|
settings.BROWSER_LOGS_ENABLED = False
|
||||||
|
|
||||||
if llm_config:
|
if llm_config:
|
||||||
@@ -36,9 +38,15 @@ def create_embedded_server(
|
|||||||
else:
|
else:
|
||||||
raise ValueError(f"Invalid setting: {key}")
|
raise ValueError(f"Invalid setting: {key}")
|
||||||
|
|
||||||
from skyvern.forge.api_app import create_api_app # noqa: PLC0415
|
self._api_key = os.getenv("SKYVERN_API_KEY")
|
||||||
|
if not self._api_key:
|
||||||
|
raise ValueError("SKYVERN_API_KEY is not set. Provide api_key or set SKYVERN_API_KEY in .env file.")
|
||||||
|
api_app = create_api_app()
|
||||||
|
|
||||||
self._transport = ASGITransport(app=create_api_app())
|
self._transport = ASGITransport(app=api_app)
|
||||||
|
|
||||||
|
if self._api_key and "x-api-key" not in request.headers:
|
||||||
|
request.headers["x-api-key"] = self._api_key
|
||||||
|
|
||||||
response = await self._transport.handle_async_request(request)
|
response = await self._transport.handle_async_request(request)
|
||||||
return response
|
return response
|
||||||
|
|||||||
Reference in New Issue
Block a user