support openrouter qwen model (#3630)
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import importlib
|
||||
import json
|
||||
import types
|
||||
from unittest.mock import AsyncMock
|
||||
from unittest.mock import AsyncMock, MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
from skyvern import config
|
||||
from skyvern.config import Settings
|
||||
from skyvern.forge import app
|
||||
from skyvern.forge.sdk.api.llm import api_handler_factory, config_registry
|
||||
@@ -19,6 +20,9 @@ class DummyResponse(dict):
|
||||
def model_dump_json(self, indent: int = 2):
|
||||
return json.dumps(self, indent=indent)
|
||||
|
||||
def model_dump(self):
|
||||
return self
|
||||
|
||||
|
||||
class DummyArtifactManager:
|
||||
async def create_llm_artifact(self, *args, **kwargs):
|
||||
@@ -49,27 +53,36 @@ async def test_openrouter_basic_completion(monkeypatch):
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_openrouter_dynamic_model(monkeypatch):
|
||||
settings = Settings(
|
||||
ENABLE_OPENROUTER=True,
|
||||
OPENROUTER_API_KEY="key",
|
||||
OPENROUTER_MODEL="base-model",
|
||||
LLM_KEY="OPENROUTER",
|
||||
)
|
||||
SettingsManager.set_settings(settings)
|
||||
# Update settings via monkeypatch to ensure config_registry sees them
|
||||
|
||||
monkeypatch.setattr(config.settings, "ENABLE_OPENROUTER", True)
|
||||
monkeypatch.setattr(config.settings, "OPENROUTER_API_KEY", "key")
|
||||
monkeypatch.setattr(config.settings, "OPENROUTER_MODEL", "base-model")
|
||||
monkeypatch.setattr(config.settings, "OPENROUTER_API_BASE", "https://openrouter.ai/api/v1")
|
||||
|
||||
# Clear existing configs before reload
|
||||
config_registry.LLMConfigRegistry._configs.clear()
|
||||
importlib.reload(config_registry)
|
||||
|
||||
monkeypatch.setattr(app, "ARTIFACT_MANAGER", DummyArtifactManager())
|
||||
|
||||
# Mock the AsyncOpenAI client
|
||||
async_mock = AsyncMock(return_value=DummyResponse('{"status": "ok"}'))
|
||||
monkeypatch.setattr(api_handler_factory.litellm, "acompletion", async_mock)
|
||||
mock_client = MagicMock()
|
||||
mock_client.chat.completions.create = async_mock
|
||||
|
||||
# Patch AsyncOpenAI to return our mock client
|
||||
monkeypatch.setattr(api_handler_factory, "AsyncOpenAI", lambda **kwargs: mock_client)
|
||||
|
||||
base_handler = api_handler_factory.LLMAPIHandlerFactory.get_llm_api_handler("OPENROUTER")
|
||||
override_handler = api_handler_factory.LLMAPIHandlerFactory.get_override_llm_api_handler(
|
||||
"openrouter/other-model", default=base_handler
|
||||
)
|
||||
|
||||
result = await override_handler("hi", "test")
|
||||
assert result == {"status": "ok"}
|
||||
called_model = async_mock.call_args.kwargs.get("model")
|
||||
assert called_model == "openrouter/other-model"
|
||||
assert called_model == "other-model"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
Reference in New Issue
Block a user