Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
Suppress Pydantic serialization warnings from litellm ModelResponse (#4557)
pedrohsdbb92447df35e7
diff --git a/skyvern/forge/sdk/api/llm/api_handler_factory.py b/skyvern/forge/sdk/api/llm/api_handler_factory.pyindex d8dc23eec..080d0fbae 100644--- a/skyvern/forge/sdk/api/llm/api_handler_factory.py+++ b/skyvern/forge/sdk/api/llm/api_handler_factory.py@@ -2,6 +2,7 @@ import copyimport dataclassesimport jsonimport time+import warningsfrom asyncio import CancelledErrorfrom typing import Any, AsyncIterator, Protocol, runtime_checkable@@ -54,6 +55,19 @@ CHECK_USER_GOAL_PROMPT_NAMES = {"check-user-goal", "check-user-goal-with-terminaEXTRACT_ACTION_DEFAULT_THINKING_BUDGET = 512+def _safe_model_dump_json(response: ModelResponse, indent: int = 2) -> str:+ """+ Call model_dump_json() while suppressing Pydantic serialization warnings.++ litellm's ModelResponse has Union types (Choices | StreamingChoices) that cause+ Pydantic to emit warnings during serialization. These are cosmetic and don't+ affect the serialized output.+ """+ with warnings.catch_warnings():+ warnings.filterwarnings("ignore", category=UserWarning, message=".*Pydantic.*Serializ.*")+ return response.model_dump_json(indent=indent)++@runtime_checkableclass RouterWithModelList(Protocol):model_list: list[dict[str, Any]]@@ -671,7 +685,7 @@ class LLMAPIHandlerFactory:)raise LLMProviderError(llm_key) from e- llm_response_json = response.model_dump_json(indent=2)+ llm_response_json = _safe_model_dump_json(response)if should_persist_llm_artifacts:artifacts.append(await app.ARTIFACT_MANAGER.prepare_llm_artifact(@@ -1063,7 +1077,7 @@ class LLMAPIHandlerFactory:)raise LLMProviderError(llm_key) from e- llm_response_json = response.model_dump_json(indent=2)+ llm_response_json = _safe_model_dump_json(response)if should_persist_llm_artifacts:artifacts.append(await app.ARTIFACT_MANAGER.prepare_llm_artifact(@@ -1442,7 +1456,7 @@ class LLMCaller:LOG.exception("LLM request failed unexpectedly", llm_key=self.llm_key)raise LLMProviderError(self.llm_key) from e- llm_response_json = response.model_dump_json(indent=2)+ llm_response_json = _safe_model_dump_json(response)if should_persist_llm_artifacts:artifacts.append(await app.ARTIFACT_MANAGER.prepare_llm_artifact(