refactor(typing): validate RunwayML task JSON and let dotprompt loaders accept exported prompts
Some checks are pending
LiteLLM Rust / rust-lint (push) Waiting to run
LiteLLM Rust / rust-test (push) Waiting to run
LiteLLM Rust / rust-wheel (push) Waiting to run

This commit is contained in:
mateo-berri 2026-10-21 06:03:38 +00:00
parent 84063d7475
commit 36ce9b81e0
3 changed files with 11 additions and 8 deletions

View file

@ -355,7 +355,7 @@ class DotpromptManager(CustomPromptManagement):
metadata: Final = json_data.get("metadata", {})
self.prompt_manager.add_prompt(prompt_id, content, metadata)
def load_prompts_from_json(self, prompts_data: dict[str, dict[str, object]]) -> None:
def load_prompts_from_json(self, prompts_data: Mapping[str, Mapping[str, object]]) -> None:
"""Load multiple prompts from JSON data."""
self.prompt_manager.load_prompts_from_json_data(prompts_data)

View file

@ -377,6 +377,6 @@ class PromptManager:
for prompt_id, template in self.prompts.items()
}
def load_prompts_from_json_data(self, prompt_data: dict[str, dict[str, object]]) -> None:
def load_prompts_from_json_data(self, prompt_data: Mapping[str, Mapping[str, object]]) -> None:
"""Load additional prompts from JSON data (merges with existing prompts)."""
self._load_prompts_from_json(prompt_data)
self._load_prompts_from_json({prompt_id: dict(entry) for prompt_id, entry in prompt_data.items()})

View file

@ -4,6 +4,7 @@ from collections.abc import Mapping, Sequence
from typing import TYPE_CHECKING, Any, Final
import httpx
from pydantic import TypeAdapter
from typing_extensions import ReadOnly, TypedDict
from litellm._logging import verbose_logger
@ -35,14 +36,16 @@ class _RunwayMLTask(TypedDict, total=False):
id: ReadOnly[str]
status: ReadOnly[str]
output: ReadOnly[Sequence[str | Mapping[str, str]]]
failure: ReadOnly[str]
failureCode: ReadOnly[str]
output: ReadOnly[Sequence[str | Mapping[str, str | None]] | None]
failure: ReadOnly[str | None]
failureCode: ReadOnly[str | None]
_RUNWAY_TASK_ADAPTER: Final = TypeAdapter(_RunwayMLTask)
def _parse_runway_task(response: httpx.Response) -> _RunwayMLTask:
task: Final[_RunwayMLTask] = response.json()
return task
return _RUNWAY_TASK_ADAPTER.validate_json(response.content)
class RunwayMLImageGenerationConfig(BaseImageGenerationConfig):