mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-10 03:28:53 +00:00
chore(lint): remove litellm/types from the ruff lint exclusion
ruff.toml has excluded litellm/types/* since 2024, so no lint rule ever ran on the types tree. Remove the exclusion, apply ruff --fix and ruff format across litellm/types, and hand-fix what autofix cannot reach so the pyupgrade budgets stay at zero: implicit type aliases converted to PEP 604 unions, RootModel[Union[...]] bases, duplicate imports, and a stray print. Load-bearing import X as X re-exports deleted by preview-mode F401 are restored, and the six star-imported hub modules keep their re-export surface via per-file F401 ignores. Star-import consumers that silently relied on typing names leaking from those hubs are modernized to builtin generics and PEP 604 unions. Runtime annotation introspection that only recognized typing.Union is taught types.UnionType (guardrail UI field schemas, volcengine response fill), with regression tests for both. Strict budget limits for the rules the types tree now trips are raised to exact measured totals, so any net-new violation still fails the gate
This commit is contained in:
parent
4fcaf7d736
commit
4e32a8bf6a
184 changed files with 4707 additions and 4972 deletions
|
|
@ -8,8 +8,8 @@ from ..types.llms.openai import *
|
|||
|
||||
def get_optional_params_add_message(
|
||||
role: str | None,
|
||||
content: str | List[MessageContentTextObject | MessageContentImageFileObject | MessageContentImageURLObject] | None,
|
||||
attachments: List[Attachment] | None,
|
||||
content: str | list[MessageContentTextObject | MessageContentImageFileObject | MessageContentImageURLObject] | None,
|
||||
attachments: list[Attachment] | None,
|
||||
metadata: dict | None,
|
||||
custom_llm_provider: str,
|
||||
**kwargs,
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ async def acreate_fine_tuning_job(
|
|||
hyperparameters: dict | None = {},
|
||||
suffix: str | None = None,
|
||||
validation_file: str | None = None,
|
||||
integrations: List[str] | None = None,
|
||||
integrations: list[str] | None = None,
|
||||
seed: int | None = None,
|
||||
custom_llm_provider: Literal["openai", "azure", "vertex_ai"] = "openai",
|
||||
extra_headers: dict[str, str] | None = None,
|
||||
|
|
@ -157,7 +157,7 @@ def create_fine_tuning_job(
|
|||
hyperparameters: dict | None = {},
|
||||
suffix: str | None = None,
|
||||
validation_file: str | None = None,
|
||||
integrations: List[str] | None = None,
|
||||
integrations: list[str] | None = None,
|
||||
seed: int | None = None,
|
||||
custom_llm_provider: Literal["openai", "azure", "vertex_ai"] = "openai",
|
||||
extra_headers: dict[str, str] | None = None,
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ class AmazonCohereChatConfig:
|
|||
Reference - https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-cohere-command-r-plus.html
|
||||
"""
|
||||
|
||||
documents: List[Document] | None = None
|
||||
documents: list[Document] | None = None
|
||||
search_queries_only: bool | None = None
|
||||
preamble: str | None = None
|
||||
max_tokens: int | None = None
|
||||
|
|
@ -69,12 +69,12 @@ class AmazonCohereChatConfig:
|
|||
presence_penalty: float | None = None
|
||||
seed: int | None = None
|
||||
return_prompt: bool | None = None
|
||||
stop_sequences: List[str] | None = None
|
||||
stop_sequences: list[str] | None = None
|
||||
raw_prompting: bool | None = None
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
documents: List[Document] | None = None,
|
||||
documents: list[Document] | None = None,
|
||||
search_queries_only: bool | None = None,
|
||||
preamble: str | None = None,
|
||||
max_tokens: int | None = None,
|
||||
|
|
@ -112,7 +112,7 @@ class AmazonCohereChatConfig:
|
|||
and v is not None
|
||||
}
|
||||
|
||||
def get_supported_openai_params(self) -> List[str]:
|
||||
def get_supported_openai_params(self) -> list[str]:
|
||||
return [
|
||||
"max_tokens",
|
||||
"max_completion_tokens",
|
||||
|
|
@ -325,7 +325,7 @@ class AWSEventStreamDecoder:
|
|||
|
||||
self.model = model
|
||||
self.parser = EventStreamJSONParser()
|
||||
self.content_blocks: List[ContentBlockDeltaEvent] = []
|
||||
self.content_blocks: list[ContentBlockDeltaEvent] = []
|
||||
self.tool_calls_index: int | None = None
|
||||
self.response_id: str | None = None
|
||||
self.json_mode = json_mode
|
||||
|
|
@ -362,13 +362,13 @@ class AWSEventStreamDecoder:
|
|||
|
||||
def translate_thinking_blocks(
|
||||
self, thinking_block: BedrockConverseReasoningContentBlockDelta
|
||||
) -> List[Union[ChatCompletionThinkingBlock, ChatCompletionRedactedThinkingBlock]] | None:
|
||||
) -> list[ChatCompletionThinkingBlock | ChatCompletionRedactedThinkingBlock] | None:
|
||||
"""
|
||||
Translate the thinking blocks to a string
|
||||
"""
|
||||
|
||||
thinking_blocks_list: Final[List[Union[ChatCompletionThinkingBlock, ChatCompletionRedactedThinkingBlock]]] = []
|
||||
_thinking_block: Union[ChatCompletionThinkingBlock, ChatCompletionRedactedThinkingBlock] | None = None
|
||||
thinking_blocks_list: Final[list[ChatCompletionThinkingBlock | ChatCompletionRedactedThinkingBlock]] = []
|
||||
_thinking_block: ChatCompletionThinkingBlock | ChatCompletionRedactedThinkingBlock | None = None
|
||||
|
||||
if "text" in thinking_block:
|
||||
_thinking_block = ChatCompletionThinkingBlock(type="thinking")
|
||||
|
|
@ -402,12 +402,12 @@ class AWSEventStreamDecoder:
|
|||
) -> tuple[
|
||||
ChatCompletionToolCallChunk | None,
|
||||
dict,
|
||||
List[Union[ChatCompletionThinkingBlock, ChatCompletionRedactedThinkingBlock]] | None,
|
||||
list[ChatCompletionThinkingBlock | ChatCompletionRedactedThinkingBlock] | None,
|
||||
]:
|
||||
"""Handle 'start' event in converse chunk parsing."""
|
||||
tool_use: ChatCompletionToolCallChunk | None = None
|
||||
provider_specific_fields: dict = {}
|
||||
thinking_blocks: List[Union[ChatCompletionThinkingBlock, ChatCompletionRedactedThinkingBlock]] | None = None
|
||||
thinking_blocks: list[ChatCompletionThinkingBlock | ChatCompletionRedactedThinkingBlock] | None = None
|
||||
|
||||
self.content_blocks = [] # reset
|
||||
if start_obj is not None:
|
||||
|
|
@ -450,14 +450,14 @@ class AWSEventStreamDecoder:
|
|||
ChatCompletionToolCallChunk | None,
|
||||
dict,
|
||||
str | None,
|
||||
List[Union[ChatCompletionThinkingBlock, ChatCompletionRedactedThinkingBlock]] | None,
|
||||
list[ChatCompletionThinkingBlock | ChatCompletionRedactedThinkingBlock] | None,
|
||||
]:
|
||||
"""Handle 'delta' event in converse chunk parsing."""
|
||||
text = ""
|
||||
tool_use: ChatCompletionToolCallChunk | None = None
|
||||
provider_specific_fields: dict = {}
|
||||
reasoning_content: str | None = None
|
||||
thinking_blocks: List[Union[ChatCompletionThinkingBlock, ChatCompletionRedactedThinkingBlock]] | None = None
|
||||
thinking_blocks: list[ChatCompletionThinkingBlock | ChatCompletionRedactedThinkingBlock] | None = None
|
||||
|
||||
self.content_blocks.append(delta_obj)
|
||||
if "text" in delta_obj:
|
||||
|
|
@ -535,7 +535,7 @@ class AWSEventStreamDecoder:
|
|||
usage: Usage | None = None
|
||||
provider_specific_fields: dict = {}
|
||||
reasoning_content: str | None = None
|
||||
thinking_blocks: List[Union[ChatCompletionThinkingBlock, ChatCompletionRedactedThinkingBlock]] | None = None
|
||||
thinking_blocks: list[ChatCompletionThinkingBlock | ChatCompletionRedactedThinkingBlock] | None = None
|
||||
|
||||
content_block_index: Final = int(chunk_data.get("contentBlockIndex", 0))
|
||||
if "start" in chunk_data:
|
||||
|
|
@ -590,7 +590,7 @@ class AWSEventStreamDecoder:
|
|||
except Exception as e:
|
||||
raise Exception(f"Received streaming error - {e}")
|
||||
|
||||
def _chunk_parser(self, chunk_data: dict) -> Union[GChunk, ModelResponseStream, dict]:
|
||||
def _chunk_parser(self, chunk_data: dict) -> GChunk | ModelResponseStream | dict:
|
||||
text = ""
|
||||
is_finished = False
|
||||
finish_reason = ""
|
||||
|
|
@ -645,7 +645,7 @@ class AWSEventStreamDecoder:
|
|||
tool_use=None,
|
||||
)
|
||||
|
||||
def iter_bytes(self, iterator: Iterator[bytes]) -> Iterator[Union[GChunk, ModelResponseStream, dict]]:
|
||||
def iter_bytes(self, iterator: Iterator[bytes]) -> Iterator[GChunk | ModelResponseStream | dict]:
|
||||
"""Given an iterator that yields lines, iterate over it & yield every event encountered"""
|
||||
from botocore.eventstream import EventStreamBuffer
|
||||
|
||||
|
|
@ -659,9 +659,7 @@ class AWSEventStreamDecoder:
|
|||
_data = json.loads(message)
|
||||
yield self._chunk_parser(chunk_data=_data)
|
||||
|
||||
async def aiter_bytes(
|
||||
self, iterator: AsyncIterator[bytes]
|
||||
) -> AsyncIterator[Union[GChunk, ModelResponseStream, dict]]:
|
||||
async def aiter_bytes(self, iterator: AsyncIterator[bytes]) -> AsyncIterator[GChunk | ModelResponseStream | dict]:
|
||||
"""Given an async iterator that yields lines, iterate over it & yield every event encountered"""
|
||||
from botocore.eventstream import EventStreamBuffer
|
||||
|
||||
|
|
@ -741,7 +739,7 @@ class AmazonDeepSeekR1StreamDecoder(AWSEventStreamDecoder):
|
|||
sync_stream=sync_stream,
|
||||
)
|
||||
|
||||
def _chunk_parser(self, chunk_data: dict) -> Union[GChunk, ModelResponseStream, dict]:
|
||||
def _chunk_parser(self, chunk_data: dict) -> GChunk | ModelResponseStream | dict:
|
||||
return self.deepseek_model_response_iterator.chunk_parser(chunk=chunk_data)
|
||||
|
||||
|
||||
|
|
@ -756,7 +754,7 @@ class MockResponseIterator: # for returning ai21 streaming responses
|
|||
return self
|
||||
|
||||
def _handle_json_mode_chunk(
|
||||
self, text: str, tool_calls: List[ChatCompletionToolCallChunk] | None
|
||||
self, text: str, tool_calls: list[ChatCompletionToolCallChunk] | None
|
||||
) -> tuple[str, ChatCompletionToolCallChunk | None]:
|
||||
"""
|
||||
If JSON mode is enabled, convert the tool call to a message.
|
||||
|
|
@ -789,7 +787,7 @@ class MockResponseIterator: # for returning ai21 streaming responses
|
|||
text = chunk_data.choices[0].message.content or "" # type: ignore
|
||||
tool_use = None
|
||||
_model_response_tool_call: Final = cast(
|
||||
List[ChatCompletionMessageToolCall] | None,
|
||||
list[ChatCompletionMessageToolCall] | None,
|
||||
cast(Choices, chunk_data.choices[0]).message.tool_calls,
|
||||
)
|
||||
if self.json_mode is True:
|
||||
|
|
|
|||
|
|
@ -345,7 +345,7 @@ class OpenAIChatCompletion(BaseLLM, BaseOpenAILLM):
|
|||
client: OpenAI | AsyncOpenAI | None = None,
|
||||
shared_session: Optional["ClientSession"] = None,
|
||||
) -> OpenAI | AsyncOpenAI | None:
|
||||
client_initialization_params: Final[Dict] = locals()
|
||||
client_initialization_params: Final[dict] = locals()
|
||||
if client is None:
|
||||
if not isinstance(max_retries, int):
|
||||
raise OpenAIError(
|
||||
|
|
@ -402,7 +402,7 @@ class OpenAIChatCompletion(BaseLLM, BaseOpenAILLM):
|
|||
data: dict,
|
||||
timeout: float | httpx.Timeout,
|
||||
logging_obj: LiteLLMLoggingObj,
|
||||
) -> Tuple[dict, BaseModel]:
|
||||
) -> tuple[dict, BaseModel]:
|
||||
"""
|
||||
Helper to:
|
||||
- call chat.completions.create.with_raw_response when litellm.return_response_headers is True
|
||||
|
|
@ -439,7 +439,7 @@ class OpenAIChatCompletion(BaseLLM, BaseOpenAILLM):
|
|||
data: dict,
|
||||
timeout: float | httpx.Timeout,
|
||||
logging_obj: LiteLLMLoggingObj,
|
||||
) -> Tuple[dict, BaseModel]:
|
||||
) -> tuple[dict, BaseModel]:
|
||||
"""
|
||||
Helper to:
|
||||
- call chat.completions.create.with_raw_response when litellm.return_response_headers is True
|
||||
|
|
@ -474,11 +474,11 @@ class OpenAIChatCompletion(BaseLLM, BaseOpenAILLM):
|
|||
self,
|
||||
response: Any,
|
||||
model: str,
|
||||
messages: list[Dict],
|
||||
optional_params: Dict,
|
||||
messages: list[dict],
|
||||
optional_params: dict,
|
||||
logging_obj: LiteLLMLoggingObj,
|
||||
stream: bool,
|
||||
litellm_params: Dict,
|
||||
litellm_params: dict,
|
||||
) -> Any | None:
|
||||
"""
|
||||
Call agentic completion hooks for all custom loggers (OpenAI Chat Completions API).
|
||||
|
|
@ -1288,7 +1288,7 @@ class OpenAIChatCompletion(BaseLLM, BaseOpenAILLM):
|
|||
)
|
||||
|
||||
## embedding CALL
|
||||
headers: Dict | None = None
|
||||
headers: dict | None = None
|
||||
headers, sync_embedding_response = self.make_sync_openai_embedding_request(
|
||||
openai_client=openai_client,
|
||||
data=data,
|
||||
|
|
@ -2852,7 +2852,7 @@ class OpenAIAssistantsAPI(BaseLLM):
|
|||
assistant_id: str,
|
||||
additional_instructions: str | None,
|
||||
instructions: str | None,
|
||||
metadata: Dict | None,
|
||||
metadata: dict | None,
|
||||
model: str | None,
|
||||
stream: bool | None,
|
||||
tools: Iterable[AssistantToolParam] | None,
|
||||
|
|
@ -2891,12 +2891,12 @@ class OpenAIAssistantsAPI(BaseLLM):
|
|||
assistant_id: str,
|
||||
additional_instructions: str | None,
|
||||
instructions: str | None,
|
||||
metadata: Dict | None,
|
||||
metadata: dict | None,
|
||||
model: str | None,
|
||||
tools: Iterable[AssistantToolParam] | None,
|
||||
event_handler: AssistantEventHandler | None,
|
||||
) -> AsyncAssistantStreamManager[AsyncAssistantEventHandler]:
|
||||
data: Final[Dict[str, Any]] = {
|
||||
data: Final[dict[str, Any]] = {
|
||||
"thread_id": thread_id,
|
||||
"assistant_id": assistant_id,
|
||||
"additional_instructions": additional_instructions,
|
||||
|
|
@ -2916,12 +2916,12 @@ class OpenAIAssistantsAPI(BaseLLM):
|
|||
assistant_id: str,
|
||||
additional_instructions: str | None,
|
||||
instructions: str | None,
|
||||
metadata: Dict | None,
|
||||
metadata: dict | None,
|
||||
model: str | None,
|
||||
tools: Iterable[AssistantToolParam] | None,
|
||||
event_handler: AssistantEventHandler | None,
|
||||
) -> AssistantStreamManager[AssistantEventHandler]:
|
||||
data: Final[Dict[str, Any]] = {
|
||||
data: Final[dict[str, Any]] = {
|
||||
"thread_id": thread_id,
|
||||
"assistant_id": assistant_id,
|
||||
"additional_instructions": additional_instructions,
|
||||
|
|
@ -2943,7 +2943,7 @@ class OpenAIAssistantsAPI(BaseLLM):
|
|||
assistant_id: str,
|
||||
additional_instructions: str | None,
|
||||
instructions: str | None,
|
||||
metadata: Dict | None,
|
||||
metadata: dict | None,
|
||||
model: str | None,
|
||||
stream: bool | None,
|
||||
tools: Iterable[AssistantToolParam] | None,
|
||||
|
|
@ -2965,7 +2965,7 @@ class OpenAIAssistantsAPI(BaseLLM):
|
|||
assistant_id: str,
|
||||
additional_instructions: str | None,
|
||||
instructions: str | None,
|
||||
metadata: Dict | None,
|
||||
metadata: dict | None,
|
||||
model: str | None,
|
||||
stream: bool | None,
|
||||
tools: Iterable[AssistantToolParam] | None,
|
||||
|
|
@ -2988,7 +2988,7 @@ class OpenAIAssistantsAPI(BaseLLM):
|
|||
assistant_id: str,
|
||||
additional_instructions: str | None,
|
||||
instructions: str | None,
|
||||
metadata: Dict | None,
|
||||
metadata: dict | None,
|
||||
model: str | None,
|
||||
stream: bool | None,
|
||||
tools: Iterable[AssistantToolParam] | None,
|
||||
|
|
|
|||
|
|
@ -165,10 +165,10 @@ class OpenAIResponsesAPIConfig(BaseResponsesAPIConfig):
|
|||
self,
|
||||
model: str, # allows overrides to selectively run this
|
||||
input: str | ResponseInputParam,
|
||||
tools: List[ALL_RESPONSES_API_TOOL_PARAMS] | None = None,
|
||||
) -> Tuple[
|
||||
tools: list[ALL_RESPONSES_API_TOOL_PARAMS] | None = None,
|
||||
) -> tuple[
|
||||
str | ResponseInputParam,
|
||||
List[ALL_RESPONSES_API_TOOL_PARAMS] | None,
|
||||
list[ALL_RESPONSES_API_TOOL_PARAMS] | None,
|
||||
]:
|
||||
"""Sibling of `remove_cache_control_flag_from_messages_and_tools` on
|
||||
the chat path. Strips Anthropic-only `cache_control` markers from
|
||||
|
|
@ -447,7 +447,7 @@ class OpenAIResponsesAPIConfig(BaseResponsesAPIConfig):
|
|||
api_base: str,
|
||||
litellm_params: GenericLiteLLMParams,
|
||||
headers: dict,
|
||||
) -> Tuple[str, dict]:
|
||||
) -> tuple[str, dict]:
|
||||
"""
|
||||
Transform the delete response API request into a URL and data
|
||||
|
||||
|
|
@ -482,7 +482,7 @@ class OpenAIResponsesAPIConfig(BaseResponsesAPIConfig):
|
|||
api_base: str,
|
||||
litellm_params: GenericLiteLLMParams,
|
||||
headers: dict,
|
||||
) -> Tuple[str, dict]:
|
||||
) -> tuple[str, dict]:
|
||||
"""
|
||||
Transform the get response API request into a URL and data
|
||||
|
||||
|
|
@ -525,10 +525,10 @@ class OpenAIResponsesAPIConfig(BaseResponsesAPIConfig):
|
|||
headers: dict,
|
||||
after: str | None = None,
|
||||
before: str | None = None,
|
||||
include: List[str] | None = None,
|
||||
include: list[str] | None = None,
|
||||
limit: int = 20,
|
||||
order: Literal["asc", "desc"] = "desc",
|
||||
) -> Tuple[str, dict]:
|
||||
) -> tuple[str, dict]:
|
||||
encoded_response_id: Final = encode_url_path_segment(response_id, field_name="response_id")
|
||||
url: Final = f"{api_base}/{encoded_response_id}/input_items"
|
||||
params: Final[dict[str, Any]] = {}
|
||||
|
|
@ -563,7 +563,7 @@ class OpenAIResponsesAPIConfig(BaseResponsesAPIConfig):
|
|||
api_base: str,
|
||||
litellm_params: GenericLiteLLMParams,
|
||||
headers: dict,
|
||||
) -> Tuple[str, dict]:
|
||||
) -> tuple[str, dict]:
|
||||
"""
|
||||
Transform the cancel response API request into a URL and data
|
||||
|
||||
|
|
@ -607,7 +607,7 @@ class OpenAIResponsesAPIConfig(BaseResponsesAPIConfig):
|
|||
api_base: str,
|
||||
litellm_params: GenericLiteLLMParams,
|
||||
headers: dict,
|
||||
) -> Tuple[str, dict]:
|
||||
) -> tuple[str, dict]:
|
||||
"""
|
||||
Transform the compact response API request into a URL and data
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
from collections.abc import Callable, Mapping, Sequence
|
||||
from types import UnionType
|
||||
from typing import TYPE_CHECKING, Any, Final, Literal, Protocol, Union, get_args, get_origin
|
||||
|
||||
import httpx
|
||||
|
|
@ -475,14 +476,12 @@ class VolcEngineResponsesAPIConfig(OpenAIResponsesAPIConfig):
|
|||
return 0
|
||||
if annotation is list or origin is list:
|
||||
return []
|
||||
if origin is Union:
|
||||
if origin is Union or origin is UnionType:
|
||||
# Prefer empty list when any option is a list
|
||||
if any((arg is list or VolcEngineResponsesAPIConfig._annotation_origin(arg) is list) for arg in args):
|
||||
return []
|
||||
if type(None) in args:
|
||||
return None
|
||||
if origin is Union and type(None) in args:
|
||||
return None
|
||||
|
||||
# Fallback to None when no safer guess exists
|
||||
return None
|
||||
|
|
@ -514,7 +513,9 @@ class VolcEngineResponsesAPIConfig(OpenAIResponsesAPIConfig):
|
|||
Choose the best-matching Pydantic model class for a nested dict.
|
||||
"""
|
||||
origin: Final = VolcEngineResponsesAPIConfig._annotation_origin(annotation)
|
||||
union_args: Final = VolcEngineResponsesAPIConfig._annotation_args(annotation) if origin is Union else ()
|
||||
union_args: Final = (
|
||||
VolcEngineResponsesAPIConfig._annotation_args(annotation) if origin is Union or origin is UnionType else ()
|
||||
)
|
||||
candidates = tuple(candidate for candidate in (annotation, *union_args) if hasattr(candidate, "model_fields"))
|
||||
|
||||
if not candidates:
|
||||
|
|
|
|||
|
|
@ -8,7 +8,8 @@ import json
|
|||
import os
|
||||
from collections.abc import Mapping, Sequence
|
||||
from datetime import datetime, timezone
|
||||
from typing import TYPE_CHECKING, Any, Final, Literal, TypeVar, Union, cast
|
||||
from types import UnionType
|
||||
from typing import TYPE_CHECKING, Any, Final, Literal, TypeVar, Union, cast, get_args, get_origin
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Request
|
||||
|
|
@ -1556,13 +1557,9 @@ def _get_field_type_from_annotation(field_annotation: Any) -> str:
|
|||
Convert a Python type annotation to a UI-friendly type string
|
||||
"""
|
||||
# Handle Union types (like Optional[T])
|
||||
if (
|
||||
hasattr(field_annotation, "__origin__")
|
||||
and field_annotation.__origin__ is Union
|
||||
and hasattr(field_annotation, "__args__")
|
||||
):
|
||||
if get_origin(field_annotation) is Union or get_origin(field_annotation) is UnionType:
|
||||
# For Optional[T], get the non-None type
|
||||
args: Final = field_annotation.__args__
|
||||
args: Final = get_args(field_annotation)
|
||||
non_none_args: Final = [arg for arg in args if arg is not type(None)]
|
||||
if non_none_args:
|
||||
field_annotation = non_none_args[0]
|
||||
|
|
@ -1689,13 +1686,9 @@ def _should_skip_optional_params(field_name: str, field_annotation: Any) -> bool
|
|||
|
||||
def _unwrap_optional_type(field_annotation: Any) -> Any:
|
||||
"""Unwrap Optional types to get the actual type."""
|
||||
if (
|
||||
hasattr(field_annotation, "__origin__")
|
||||
and field_annotation.__origin__ is Union
|
||||
and hasattr(field_annotation, "__args__")
|
||||
):
|
||||
if get_origin(field_annotation) is Union or get_origin(field_annotation) is UnionType:
|
||||
# For Optional[BaseModel], get the non-None type
|
||||
args: Final = field_annotation.__args__
|
||||
args: Final = get_args(field_annotation)
|
||||
non_none_args: Final = [arg for arg in args if arg is not type(None)]
|
||||
if non_none_args:
|
||||
return non_none_args[0]
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ from litellm.types.guardrails import *
|
|||
sys.path.insert(0, os.path.abspath("../..")) # Adds the parent directory to the system path
|
||||
|
||||
|
||||
def can_modify_guardrails(team_obj: Optional[LiteLLM_TeamTable]) -> bool:
|
||||
def can_modify_guardrails(team_obj: LiteLLM_TeamTable | None) -> bool:
|
||||
if team_obj is None:
|
||||
return True
|
||||
|
||||
|
|
|
|||
|
|
@ -1,39 +1,38 @@
|
|||
from datetime import datetime
|
||||
from typing import List, Optional
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class AccessGroupCreateRequest(BaseModel):
|
||||
access_group_name: str
|
||||
description: Optional[str] = None
|
||||
access_model_names: Optional[List[str]] = None
|
||||
access_mcp_server_ids: Optional[List[str]] = None
|
||||
access_agent_ids: Optional[List[str]] = None
|
||||
assigned_team_ids: Optional[List[str]] = None
|
||||
assigned_key_ids: Optional[List[str]] = None
|
||||
description: str | None = None
|
||||
access_model_names: list[str] | None = None
|
||||
access_mcp_server_ids: list[str] | None = None
|
||||
access_agent_ids: list[str] | None = None
|
||||
assigned_team_ids: list[str] | None = None
|
||||
assigned_key_ids: list[str] | None = None
|
||||
|
||||
|
||||
class AccessGroupUpdateRequest(BaseModel):
|
||||
access_group_name: Optional[str] = None
|
||||
description: Optional[str] = None
|
||||
access_model_names: Optional[List[str]] = None
|
||||
access_mcp_server_ids: Optional[List[str]] = None
|
||||
access_agent_ids: Optional[List[str]] = None
|
||||
assigned_team_ids: Optional[List[str]] = None
|
||||
assigned_key_ids: Optional[List[str]] = None
|
||||
access_group_name: str | None = None
|
||||
description: str | None = None
|
||||
access_model_names: list[str] | None = None
|
||||
access_mcp_server_ids: list[str] | None = None
|
||||
access_agent_ids: list[str] | None = None
|
||||
assigned_team_ids: list[str] | None = None
|
||||
assigned_key_ids: list[str] | None = None
|
||||
|
||||
|
||||
class AccessGroupResponse(BaseModel):
|
||||
access_group_id: str
|
||||
access_group_name: str
|
||||
description: Optional[str] = None
|
||||
access_model_names: List[str]
|
||||
access_mcp_server_ids: List[str]
|
||||
access_agent_ids: List[str]
|
||||
assigned_team_ids: List[str]
|
||||
assigned_key_ids: List[str]
|
||||
description: str | None = None
|
||||
access_model_names: list[str]
|
||||
access_mcp_server_ids: list[str]
|
||||
access_agent_ids: list[str]
|
||||
assigned_team_ids: list[str]
|
||||
assigned_key_ids: list[str]
|
||||
created_at: datetime
|
||||
created_by: Optional[str] = None
|
||||
created_by: str | None = None
|
||||
updated_at: datetime
|
||||
updated_by: Optional[str] = None
|
||||
updated_by: str | None = None
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
from typing import List
|
||||
|
||||
from typing_extensions import Dict, Required, TypedDict, override
|
||||
from typing_extensions import TypedDict
|
||||
|
||||
from litellm.integrations.custom_logger import CustomLogger
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
from datetime import datetime
|
||||
from typing import Any, Dict, Final, List, Literal, Optional, TYPE_CHECKING, Union
|
||||
from typing import TYPE_CHECKING, Any, Final, Literal
|
||||
|
||||
from pydantic import BaseModel, PrivateAttr
|
||||
from typing_extensions import Required, TypedDict
|
||||
|
|
@ -23,26 +23,26 @@ class AgentExtension(TypedDict, total=False):
|
|||
"""A declaration of a protocol extension supported by an Agent."""
|
||||
|
||||
uri: str # required
|
||||
description: Optional[str]
|
||||
required: Optional[bool]
|
||||
params: Optional[Dict[str, Any]]
|
||||
description: str | None
|
||||
required: bool | None
|
||||
params: dict[str, Any] | None
|
||||
|
||||
|
||||
# AgentCapabilities
|
||||
class AgentCapabilities(TypedDict, total=False):
|
||||
"""Defines optional capabilities supported by an agent."""
|
||||
|
||||
streaming: Optional[bool]
|
||||
pushNotifications: Optional[bool]
|
||||
stateTransitionHistory: Optional[bool]
|
||||
extensions: Optional[List[AgentExtension]]
|
||||
streaming: bool | None
|
||||
pushNotifications: bool | None
|
||||
stateTransitionHistory: bool | None
|
||||
extensions: list[AgentExtension] | None
|
||||
|
||||
|
||||
# SecurityScheme types
|
||||
class SecuritySchemeBase(TypedDict, total=False):
|
||||
"""Base properties shared by all security scheme objects."""
|
||||
|
||||
description: Optional[str]
|
||||
description: str | None
|
||||
|
||||
|
||||
class APIKeySecurityScheme(SecuritySchemeBase, total=False):
|
||||
|
|
@ -58,7 +58,7 @@ class HTTPAuthSecurityScheme(SecuritySchemeBase, total=False):
|
|||
|
||||
type: Required[Literal["http"]]
|
||||
scheme: Required[str]
|
||||
bearerFormat: Optional[str]
|
||||
bearerFormat: str | None
|
||||
|
||||
|
||||
class MutualTLSSecurityScheme(SecuritySchemeBase, total=False):
|
||||
|
|
@ -70,10 +70,10 @@ class MutualTLSSecurityScheme(SecuritySchemeBase, total=False):
|
|||
class OAuthFlows(TypedDict, total=False):
|
||||
"""Defines the configuration for the supported OAuth 2.0 flows."""
|
||||
|
||||
authorizationCode: Optional[Dict[str, Any]]
|
||||
clientCredentials: Optional[Dict[str, Any]]
|
||||
implicit: Optional[Dict[str, Any]]
|
||||
password: Optional[Dict[str, Any]]
|
||||
authorizationCode: dict[str, Any] | None
|
||||
clientCredentials: dict[str, Any] | None
|
||||
implicit: dict[str, Any] | None
|
||||
password: dict[str, Any] | None
|
||||
|
||||
|
||||
class OAuth2SecurityScheme(SecuritySchemeBase, total=False):
|
||||
|
|
@ -81,7 +81,7 @@ class OAuth2SecurityScheme(SecuritySchemeBase, total=False):
|
|||
|
||||
type: Required[Literal["oauth2"]]
|
||||
flows: Required[OAuthFlows]
|
||||
oauth2MetadataUrl: Optional[str]
|
||||
oauth2MetadataUrl: str | None
|
||||
|
||||
|
||||
class OpenIdConnectSecurityScheme(SecuritySchemeBase, total=False):
|
||||
|
|
@ -92,13 +92,13 @@ class OpenIdConnectSecurityScheme(SecuritySchemeBase, total=False):
|
|||
|
||||
|
||||
# Union of all security schemes
|
||||
SecurityScheme = Union[
|
||||
APIKeySecurityScheme,
|
||||
HTTPAuthSecurityScheme,
|
||||
OAuth2SecurityScheme,
|
||||
OpenIdConnectSecurityScheme,
|
||||
MutualTLSSecurityScheme,
|
||||
]
|
||||
SecurityScheme = (
|
||||
APIKeySecurityScheme
|
||||
| HTTPAuthSecurityScheme
|
||||
| OAuth2SecurityScheme
|
||||
| OpenIdConnectSecurityScheme
|
||||
| MutualTLSSecurityScheme
|
||||
)
|
||||
|
||||
|
||||
# AgentSkill
|
||||
|
|
@ -108,11 +108,11 @@ class AgentSkill(TypedDict, total=False):
|
|||
id: str # required
|
||||
name: str # required
|
||||
description: str # required
|
||||
tags: List[str] # required
|
||||
examples: Optional[List[str]]
|
||||
inputModes: Optional[List[str]]
|
||||
outputModes: Optional[List[str]]
|
||||
security: Optional[List[Dict[str, List[str]]]]
|
||||
tags: list[str] # required
|
||||
examples: list[str] | None
|
||||
inputModes: list[str] | None
|
||||
outputModes: list[str] | None
|
||||
security: list[dict[str, list[str]]] | None
|
||||
|
||||
|
||||
# AgentInterface
|
||||
|
|
@ -129,7 +129,7 @@ class AgentCardSignature(TypedDict, total=False):
|
|||
|
||||
protected: str # required
|
||||
signature: str # required
|
||||
header: Optional[Dict[str, Any]]
|
||||
header: dict[str, Any] | None
|
||||
|
||||
|
||||
# AgentCard
|
||||
|
|
@ -147,20 +147,20 @@ class AgentCard(TypedDict, total=False):
|
|||
url: str
|
||||
version: str
|
||||
capabilities: AgentCapabilities
|
||||
defaultInputModes: List[str]
|
||||
defaultOutputModes: List[str]
|
||||
skills: List[AgentSkill]
|
||||
defaultInputModes: list[str]
|
||||
defaultOutputModes: list[str]
|
||||
skills: list[AgentSkill]
|
||||
|
||||
# Optional fields
|
||||
preferredTransport: Optional[str]
|
||||
additionalInterfaces: Optional[List[AgentInterface]]
|
||||
iconUrl: Optional[str]
|
||||
provider: Optional[AgentProvider]
|
||||
documentationUrl: Optional[str]
|
||||
securitySchemes: Optional[Dict[str, SecurityScheme]]
|
||||
security: Optional[List[Dict[str, List[str]]]]
|
||||
supportsAuthenticatedExtendedCard: Optional[bool]
|
||||
signatures: Optional[List[AgentCardSignature]]
|
||||
preferredTransport: str | None
|
||||
additionalInterfaces: list[AgentInterface] | None
|
||||
iconUrl: str | None
|
||||
provider: AgentProvider | None
|
||||
documentationUrl: str | None
|
||||
securitySchemes: dict[str, SecurityScheme] | None
|
||||
security: list[dict[str, list[str]]] | None
|
||||
supportsAuthenticatedExtendedCard: bool | None
|
||||
signatures: list[AgentCardSignature] | None
|
||||
|
||||
|
||||
class AugmentedAgentCard(AgentCard):
|
||||
|
|
@ -169,37 +169,37 @@ class AugmentedAgentCard(AgentCard):
|
|||
|
||||
# Object permission shape for agent MCP tool access (mirrors LiteLLM_ObjectPermissionBase)
|
||||
class AgentObjectPermission(TypedDict, total=False):
|
||||
mcp_servers: Optional[List[str]]
|
||||
mcp_access_groups: Optional[List[str]]
|
||||
mcp_tool_permissions: Optional[Dict[str, List[str]]]
|
||||
models: Optional[List[str]]
|
||||
agents: Optional[List[str]]
|
||||
mcp_servers: list[str] | None
|
||||
mcp_access_groups: list[str] | None
|
||||
mcp_tool_permissions: dict[str, list[str]] | None
|
||||
models: list[str] | None
|
||||
agents: list[str] | None
|
||||
|
||||
|
||||
class AgentConfig(TypedDict, total=False):
|
||||
agent_name: Required[str]
|
||||
agent_card_params: Required[AgentCard]
|
||||
litellm_params: Dict[str, Any] # allow for any future litellm params
|
||||
litellm_params: dict[str, Any] # allow for any future litellm params
|
||||
object_permission: AgentObjectPermission
|
||||
tpm_limit: Optional[int]
|
||||
rpm_limit: Optional[int]
|
||||
session_tpm_limit: Optional[int]
|
||||
session_rpm_limit: Optional[int]
|
||||
static_headers: Optional[Dict[str, str]]
|
||||
extra_headers: Optional[List[str]]
|
||||
tpm_limit: int | None
|
||||
rpm_limit: int | None
|
||||
session_tpm_limit: int | None
|
||||
session_rpm_limit: int | None
|
||||
static_headers: dict[str, str] | None
|
||||
extra_headers: list[str] | None
|
||||
|
||||
|
||||
class PatchAgentRequest(TypedDict, total=False):
|
||||
agent_name: str
|
||||
agent_card_params: AgentCard
|
||||
litellm_params: Dict[str, Any]
|
||||
litellm_params: dict[str, Any]
|
||||
object_permission: AgentObjectPermission
|
||||
tpm_limit: Optional[int]
|
||||
rpm_limit: Optional[int]
|
||||
session_tpm_limit: Optional[int]
|
||||
session_rpm_limit: Optional[int]
|
||||
static_headers: Optional[Dict[str, str]]
|
||||
extra_headers: Optional[List[str]]
|
||||
tpm_limit: int | None
|
||||
rpm_limit: int | None
|
||||
session_tpm_limit: int | None
|
||||
session_rpm_limit: int | None
|
||||
static_headers: dict[str, str] | None
|
||||
extra_headers: list[str] | None
|
||||
|
||||
|
||||
# Request/Response models for CRUD endpoints
|
||||
|
|
@ -207,32 +207,32 @@ class PatchAgentRequest(TypedDict, total=False):
|
|||
|
||||
class AgentKeySummary(BaseModel):
|
||||
token: str
|
||||
key_alias: Optional[str] = None
|
||||
key_name: Optional[str] = None
|
||||
key_alias: str | None = None
|
||||
key_name: str | None = None
|
||||
|
||||
|
||||
class AgentResponse(BaseModel):
|
||||
agent_id: str
|
||||
agent_name: str
|
||||
litellm_params: Optional[Dict[str, Any]] = None
|
||||
agent_card_params: Dict[str, Any]
|
||||
object_permission: Optional[Dict[str, Any]] = None
|
||||
spend: Optional[float] = None
|
||||
tpm_limit: Optional[int] = None
|
||||
rpm_limit: Optional[int] = None
|
||||
session_tpm_limit: Optional[int] = None
|
||||
session_rpm_limit: Optional[int] = None
|
||||
static_headers: Optional[Dict[str, str]] = None
|
||||
extra_headers: Optional[List[str]] = None
|
||||
keys: Optional[List[AgentKeySummary]] = None
|
||||
created_at: Optional[datetime] = None
|
||||
updated_at: Optional[datetime] = None
|
||||
created_by: Optional[str] = None
|
||||
updated_by: Optional[str] = None
|
||||
litellm_params: dict[str, Any] | None = None
|
||||
agent_card_params: dict[str, Any]
|
||||
object_permission: dict[str, Any] | None = None
|
||||
spend: float | None = None
|
||||
tpm_limit: int | None = None
|
||||
rpm_limit: int | None = None
|
||||
session_tpm_limit: int | None = None
|
||||
session_rpm_limit: int | None = None
|
||||
static_headers: dict[str, str] | None = None
|
||||
extra_headers: list[str] | None = None
|
||||
keys: list[AgentKeySummary] | None = None
|
||||
created_at: datetime | None = None
|
||||
updated_at: datetime | None = None
|
||||
created_by: str | None = None
|
||||
updated_by: str | None = None
|
||||
|
||||
|
||||
class ListAgentsResponse(BaseModel):
|
||||
agents: List[AgentResponse]
|
||||
agents: list[AgentResponse]
|
||||
|
||||
|
||||
class AgentCreateResponse(LiteLLMPydanticObjectBase):
|
||||
|
|
@ -246,8 +246,8 @@ class AgentCreateResponse(LiteLLMPydanticObjectBase):
|
|||
are preserved via extra="allow".
|
||||
"""
|
||||
|
||||
id: Optional[str] = None
|
||||
name: Optional[str] = None
|
||||
id: str | None = None
|
||||
name: str | None = None
|
||||
model_config = {"extra": "allow"}
|
||||
|
||||
_hidden_params: dict = PrivateAttr(default_factory=dict)
|
||||
|
|
@ -274,8 +274,8 @@ class AgentListResponse(LiteLLMPydanticObjectBase):
|
|||
a plain dict so no fields are silently dropped.
|
||||
"""
|
||||
|
||||
agents: List[Dict[str, Any]] = []
|
||||
next_page_token: Optional[str] = None
|
||||
agents: list[dict[str, Any]] = []
|
||||
next_page_token: str | None = None
|
||||
model_config = {"extra": "allow"}
|
||||
|
||||
_hidden_params: dict = PrivateAttr(default_factory=dict)
|
||||
|
|
@ -288,8 +288,8 @@ class AgentVersionsResponse(LiteLLMPydanticObjectBase):
|
|||
field of the form ``agents/{agent_id}/versions/{uuid}``.
|
||||
"""
|
||||
|
||||
agent_versions: List[Dict[str, Any]] = []
|
||||
next_page_token: Optional[str] = None
|
||||
agent_versions: list[dict[str, Any]] = []
|
||||
next_page_token: str | None = None
|
||||
model_config = {"extra": "allow"}
|
||||
|
||||
_hidden_params: dict = PrivateAttr(default_factory=dict)
|
||||
|
|
@ -297,18 +297,18 @@ class AgentVersionsResponse(LiteLLMPydanticObjectBase):
|
|||
|
||||
class AgentMakePublicResponse(BaseModel):
|
||||
message: str
|
||||
public_agent_groups: List[str]
|
||||
public_agent_groups: list[str]
|
||||
updated_by: str
|
||||
|
||||
|
||||
class MakeAgentsPublicRequest(BaseModel):
|
||||
agent_ids: List[str]
|
||||
agent_ids: list[str]
|
||||
|
||||
|
||||
def _normalize_a2a_jsonrpc_response(
|
||||
response_dict: Dict[str, Any],
|
||||
request_id: Optional[Any] = None,
|
||||
) -> Dict[str, Any]:
|
||||
response_dict: dict[str, Any],
|
||||
request_id: Any | None = None,
|
||||
) -> dict[str, Any]:
|
||||
"""
|
||||
Ensure JSON-RPC responses include ``id`` when the caller supplied one.
|
||||
|
||||
|
|
@ -333,11 +333,11 @@ class LiteLLMSendMessageResponse(LiteLLMPydanticObjectBase):
|
|||
# A2A response fields
|
||||
id: str
|
||||
jsonrpc: str = "2.0"
|
||||
result: Optional[Dict[str, Any]] = None
|
||||
error: Optional[Dict[str, Any]] = None
|
||||
result: dict[str, Any] | None = None
|
||||
error: dict[str, Any] | None = None
|
||||
|
||||
# LiteLLM usage tracking
|
||||
usage: Optional[Dict[str, Any]] = None
|
||||
usage: dict[str, Any] | None = None
|
||||
|
||||
model_config = {"extra": "allow"}
|
||||
|
||||
|
|
@ -348,7 +348,7 @@ class LiteLLMSendMessageResponse(LiteLLMPydanticObjectBase):
|
|||
def from_a2a_response(
|
||||
cls,
|
||||
response: "SendMessageResponse",
|
||||
request_id: Optional[Any] = None,
|
||||
request_id: Any | None = None,
|
||||
) -> "LiteLLMSendMessageResponse":
|
||||
"""
|
||||
Create a LiteLLMSendMessageResponse from an a2a SDK SendMessageResponse.
|
||||
|
|
@ -367,8 +367,8 @@ class LiteLLMSendMessageResponse(LiteLLMPydanticObjectBase):
|
|||
@classmethod
|
||||
def from_dict(
|
||||
cls,
|
||||
response_dict: Dict[str, Any],
|
||||
request_id: Optional[Any] = None,
|
||||
response_dict: dict[str, Any],
|
||||
request_id: Any | None = None,
|
||||
) -> "LiteLLMSendMessageResponse":
|
||||
"""
|
||||
Create a LiteLLMSendMessageResponse from a dict.
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
from enum import Enum
|
||||
from typing import Any, Dict, Final, List, Literal, Optional, Union
|
||||
from typing import Any, Final, Literal, Optional, Union
|
||||
|
||||
from pydantic import BaseModel
|
||||
from typing_extensions import TypedDict
|
||||
|
|
@ -40,7 +40,7 @@ class RedisPipelineIncrementOperation(TypedDict):
|
|||
|
||||
key: str
|
||||
increment_value: float
|
||||
ttl: Optional[int]
|
||||
ttl: int | None
|
||||
|
||||
|
||||
class RedisPipelineSetOperation(TypedDict):
|
||||
|
|
@ -50,7 +50,7 @@ class RedisPipelineSetOperation(TypedDict):
|
|||
|
||||
key: str
|
||||
value: Any
|
||||
ttl: Optional[int]
|
||||
ttl: int | None
|
||||
|
||||
|
||||
class RedisPipelineRpushOperation(TypedDict):
|
||||
|
|
@ -59,7 +59,7 @@ class RedisPipelineRpushOperation(TypedDict):
|
|||
"""
|
||||
|
||||
key: str
|
||||
values: List[Any]
|
||||
values: list[Any]
|
||||
|
||||
|
||||
class RedisPipelineLpopOperation(TypedDict):
|
||||
|
|
@ -68,23 +68,23 @@ class RedisPipelineLpopOperation(TypedDict):
|
|||
"""
|
||||
|
||||
key: str
|
||||
count: Optional[int]
|
||||
count: int | None
|
||||
|
||||
|
||||
DynamicCacheControl = TypedDict(
|
||||
"DynamicCacheControl",
|
||||
{
|
||||
# Will cache the response for the user-defined amount of time (in seconds).
|
||||
"ttl": Optional[int],
|
||||
"ttl": int | None,
|
||||
# Namespace to use for caching
|
||||
"namespace": Optional[str],
|
||||
"namespace": str | None,
|
||||
# Max Age to use for caching
|
||||
"s-maxage": Optional[int],
|
||||
"s-max-age": Optional[int],
|
||||
"s-maxage": int | None,
|
||||
"s-max-age": int | None,
|
||||
# Will not return a cached response, but instead call the actual endpoint.
|
||||
"no-cache": Optional[bool],
|
||||
"no-cache": bool | None,
|
||||
# Will not store the response in the cache.
|
||||
"no-store": Optional[bool],
|
||||
"no-store": bool | None,
|
||||
},
|
||||
)
|
||||
|
||||
|
|
@ -92,12 +92,12 @@ DynamicCacheControl = TypedDict(
|
|||
class CachePingResponse(BaseModel):
|
||||
status: str
|
||||
cache_type: str
|
||||
ping_response: Optional[bool] = None
|
||||
set_cache_response: Optional[str] = None
|
||||
litellm_cache_params: Optional[str] = None
|
||||
ping_response: bool | None = None
|
||||
set_cache_response: str | None = None
|
||||
litellm_cache_params: str | None = None
|
||||
|
||||
# intentionally a dict, since we run masker.mask_dict() on HealthCheckCacheParams
|
||||
health_check_cache_params: Optional[dict] = None
|
||||
health_check_cache_params: dict | None = None
|
||||
|
||||
|
||||
class HealthCheckCacheParams(BaseModel):
|
||||
|
|
@ -105,19 +105,19 @@ class HealthCheckCacheParams(BaseModel):
|
|||
Cache Params returned on /cache/ping call
|
||||
"""
|
||||
|
||||
host: Optional[str] = None
|
||||
port: Optional[Union[str, int]] = None
|
||||
redis_kwargs: Optional[Dict[str, Any]] = None
|
||||
namespace: Optional[str] = None
|
||||
redis_version: Optional[Union[str, int, float]] = None
|
||||
host: str | None = None
|
||||
port: str | int | None = None
|
||||
redis_kwargs: dict[str, Any] | None = None
|
||||
namespace: str | None = None
|
||||
redis_version: str | int | float | None = None
|
||||
|
||||
|
||||
class CachedEmbedding(TypedDict):
|
||||
"""Type definition for cached embedding objects"""
|
||||
|
||||
embedding: Optional[List[float]]
|
||||
index: Optional[int]
|
||||
object: Optional[str]
|
||||
model: Optional[str]
|
||||
prompt_tokens: Optional[int]
|
||||
prompt_tokens_details: Optional[dict]
|
||||
embedding: list[float] | None
|
||||
index: int | None
|
||||
object: str | None
|
||||
model: str | None
|
||||
prompt_tokens: int | None
|
||||
prompt_tokens_details: dict | None
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable, Coroutine, Iterable
|
||||
from dataclasses import dataclass
|
||||
from typing import Any, Callable, Coroutine, Final, Iterable, List, Optional, TYPE_CHECKING, Union
|
||||
from typing import TYPE_CHECKING, Any, Literal, Union
|
||||
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
from typing_extensions import Literal, Required, TypedDict
|
||||
from typing_extensions import Required, TypedDict
|
||||
|
||||
if TYPE_CHECKING:
|
||||
import httpx
|
||||
|
|
@ -57,11 +58,11 @@ class ChatCompletionContentPartImageParam(TypedDict, total=False):
|
|||
"""The type of the content part."""
|
||||
|
||||
|
||||
ChatCompletionContentPartParam = Union[ChatCompletionContentPartTextParam, ChatCompletionContentPartImageParam]
|
||||
ChatCompletionContentPartParam = ChatCompletionContentPartTextParam | ChatCompletionContentPartImageParam
|
||||
|
||||
|
||||
class ChatCompletionUserMessageParam(TypedDict, total=False):
|
||||
content: Required[Union[str, Iterable[ChatCompletionContentPartParam]]]
|
||||
content: Required[str | Iterable[ChatCompletionContentPartParam]]
|
||||
"""The contents of the user message."""
|
||||
|
||||
role: Required[Literal["user"]]
|
||||
|
|
@ -102,7 +103,7 @@ class Function(TypedDict, total=False):
|
|||
|
||||
|
||||
class ChatCompletionToolMessageParam(TypedDict, total=False):
|
||||
content: Required[Union[str, Iterable[ChatCompletionContentPartParam]]]
|
||||
content: Required[str | Iterable[ChatCompletionContentPartParam]]
|
||||
"""The contents of the tool message."""
|
||||
|
||||
role: Required[Literal["tool"]]
|
||||
|
|
@ -113,7 +114,7 @@ class ChatCompletionToolMessageParam(TypedDict, total=False):
|
|||
|
||||
|
||||
class ChatCompletionFunctionMessageParam(TypedDict, total=False):
|
||||
content: Required[Union[str, Iterable[ChatCompletionContentPartParam]]]
|
||||
content: Required[str | Iterable[ChatCompletionContentPartParam]]
|
||||
"""The contents of the function message."""
|
||||
|
||||
name: Required[str]
|
||||
|
|
@ -138,7 +139,7 @@ class ChatCompletionAssistantMessageParam(TypedDict, total=False):
|
|||
role: Required[Literal["assistant"]]
|
||||
"""The role of the messages author, in this case `assistant`."""
|
||||
|
||||
content: Optional[str]
|
||||
content: str | None
|
||||
"""The contents of the assistant message.
|
||||
|
||||
Required unless `tool_calls` or `function_call` is specified.
|
||||
|
|
@ -162,42 +163,42 @@ class ChatCompletionAssistantMessageParam(TypedDict, total=False):
|
|||
"""The tool calls generated by the model, such as function calls."""
|
||||
|
||||
|
||||
ChatCompletionMessageParam = Union[
|
||||
ChatCompletionSystemMessageParam,
|
||||
ChatCompletionUserMessageParam,
|
||||
ChatCompletionAssistantMessageParam,
|
||||
ChatCompletionFunctionMessageParam,
|
||||
ChatCompletionToolMessageParam,
|
||||
]
|
||||
ChatCompletionMessageParam = (
|
||||
ChatCompletionSystemMessageParam
|
||||
| ChatCompletionUserMessageParam
|
||||
| ChatCompletionAssistantMessageParam
|
||||
| ChatCompletionFunctionMessageParam
|
||||
| ChatCompletionToolMessageParam
|
||||
)
|
||||
|
||||
|
||||
class CompletionRequest(BaseModel):
|
||||
model: str
|
||||
messages: List[ChatCompletionMessageParam] = []
|
||||
timeout: Optional[Union[float, int]] = None
|
||||
temperature: Optional[float] = None
|
||||
top_p: Optional[float] = None
|
||||
n: Optional[int] = None
|
||||
stream: Optional[bool] = None
|
||||
stop: Optional[dict] = None
|
||||
max_tokens: Optional[int] = None
|
||||
presence_penalty: Optional[float] = None
|
||||
frequency_penalty: Optional[float] = None
|
||||
logit_bias: Optional[dict] = None
|
||||
user: Optional[str] = None
|
||||
response_format: Optional[dict] = None
|
||||
seed: Optional[int] = None
|
||||
tools: Optional[List[str]] = None
|
||||
tool_choice: Optional[str] = None
|
||||
logprobs: Optional[bool] = None
|
||||
top_logprobs: Optional[int] = None
|
||||
deployment_id: Optional[str] = None
|
||||
functions: Optional[List[str]] = None
|
||||
function_call: Optional[str] = None
|
||||
base_url: Optional[str] = None
|
||||
api_version: Optional[str] = None
|
||||
api_key: Optional[str] = None
|
||||
model_list: Optional[List[str]] = None
|
||||
messages: list[ChatCompletionMessageParam] = []
|
||||
timeout: float | int | None = None
|
||||
temperature: float | None = None
|
||||
top_p: float | None = None
|
||||
n: int | None = None
|
||||
stream: bool | None = None
|
||||
stop: dict | None = None
|
||||
max_tokens: int | None = None
|
||||
presence_penalty: float | None = None
|
||||
frequency_penalty: float | None = None
|
||||
logit_bias: dict | None = None
|
||||
user: str | None = None
|
||||
response_format: dict | None = None
|
||||
seed: int | None = None
|
||||
tools: list[str] | None = None
|
||||
tool_choice: str | None = None
|
||||
logprobs: bool | None = None
|
||||
top_logprobs: int | None = None
|
||||
deployment_id: str | None = None
|
||||
functions: list[str] | None = None
|
||||
function_call: str | None = None
|
||||
base_url: str | None = None
|
||||
api_version: str | None = None
|
||||
api_key: str | None = None
|
||||
model_list: list[str] | None = None
|
||||
|
||||
model_config = ConfigDict(protected_namespaces=(), extra="allow")
|
||||
|
||||
|
|
@ -206,34 +207,34 @@ class CompletionRequest(BaseModel):
|
|||
class _CompletionDispatchContext:
|
||||
_azure_detection_model: str
|
||||
acompletion: bool
|
||||
api_base: Optional[str]
|
||||
api_key: Optional[str]
|
||||
api_version: Optional[str]
|
||||
api_base: str | None
|
||||
api_key: str | None
|
||||
api_version: str | None
|
||||
client: Any
|
||||
custom_llm_provider: str
|
||||
custom_prompt_dict: dict
|
||||
extra_headers: Optional[dict]
|
||||
extra_headers: dict | None
|
||||
headers: dict
|
||||
hf_model_name: Optional[str]
|
||||
hf_model_name: str | None
|
||||
kwargs: dict
|
||||
litellm_params: dict
|
||||
logger_fn: Optional[Callable]
|
||||
logger_fn: Callable | None
|
||||
logging: LiteLLMLoggingObj
|
||||
max_retries: Optional[int]
|
||||
max_tokens: Optional[int]
|
||||
max_retries: int | None
|
||||
max_tokens: int | None
|
||||
messages: list
|
||||
metadata: Optional[dict]
|
||||
metadata: dict | None
|
||||
model: str
|
||||
model_response: ModelResponse
|
||||
optional_params: dict
|
||||
organization: Optional[str]
|
||||
provider_config: Optional[BaseConfig]
|
||||
shared_session: Optional[ClientSession]
|
||||
stream: Optional[bool]
|
||||
temperature: Optional[float]
|
||||
organization: str | None
|
||||
provider_config: BaseConfig | None
|
||||
shared_session: ClientSession | None
|
||||
stream: bool | None
|
||||
temperature: float | None
|
||||
text_completion: bool
|
||||
timeout: Optional[Union[float, str, httpx.Timeout]]
|
||||
top_p: Optional[float]
|
||||
timeout: float | str | httpx.Timeout | None
|
||||
top_p: float | None
|
||||
|
||||
|
||||
_CompletionDispatchResult = Union[
|
||||
|
|
|
|||
|
|
@ -5,18 +5,18 @@ Type definitions for litellm.compress().
|
|||
import sys
|
||||
|
||||
if sys.version_info >= (3, 11):
|
||||
from typing import Dict, List, NotRequired, TypedDict
|
||||
from typing import NotRequired, TypedDict
|
||||
else:
|
||||
from typing import Dict, List, TypedDict
|
||||
from typing import TypedDict
|
||||
|
||||
from typing_extensions import NotRequired
|
||||
|
||||
|
||||
class CompressedResult(TypedDict):
|
||||
messages: List[dict] # compressed messages (stubs replace low-relevance messages)
|
||||
messages: list[dict] # compressed messages (stubs replace low-relevance messages)
|
||||
original_tokens: int # token count before compression
|
||||
compressed_tokens: int # token count after compression
|
||||
compression_ratio: float # fraction reduced, e.g. 0.6 means 60% reduction
|
||||
cache: Dict[str, str] # key -> original content (for retrieval tool responses)
|
||||
tools: List[dict] # [litellm_content_retrieve tool definition]
|
||||
cache: dict[str, str] # key -> original content (for retrieval tool responses)
|
||||
tools: list[dict] # [litellm_content_retrieve tool definition]
|
||||
compression_skipped_reason: NotRequired[str]
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
from typing import Any, Dict, List, Literal, Optional
|
||||
from typing import Any, Literal
|
||||
|
||||
from pydantic import BaseModel
|
||||
from typing_extensions import TypedDict
|
||||
|
|
@ -18,12 +18,12 @@ class ContainerObject(BaseModel):
|
|||
object: Literal["container"]
|
||||
created_at: int
|
||||
status: str
|
||||
expires_after: Optional[ExpiresAfter] = None
|
||||
last_active_at: Optional[int] = None
|
||||
name: Optional[str] = None
|
||||
_hidden_params: Dict[str, Any] = {}
|
||||
expires_after: ExpiresAfter | None = None
|
||||
last_active_at: int | None = None
|
||||
name: str | None = None
|
||||
_hidden_params: dict[str, Any] = {}
|
||||
|
||||
def __contains__(self, key):
|
||||
def __contains__(self, key) -> bool:
|
||||
# Define custom behavior for the 'in' operator
|
||||
return hasattr(self, key)
|
||||
|
||||
|
|
@ -50,7 +50,7 @@ class DeleteContainerResult(BaseModel):
|
|||
object: Literal["container.deleted"]
|
||||
deleted: bool
|
||||
|
||||
def __contains__(self, key):
|
||||
def __contains__(self, key) -> bool:
|
||||
return hasattr(self, key)
|
||||
|
||||
def get(self, key, default=None):
|
||||
|
|
@ -70,12 +70,12 @@ class ContainerListResponse(BaseModel):
|
|||
"""Response object for list containers request."""
|
||||
|
||||
object: Literal["list"]
|
||||
data: List[ContainerObject]
|
||||
first_id: Optional[str] = None
|
||||
last_id: Optional[str] = None
|
||||
data: list[ContainerObject]
|
||||
first_id: str | None = None
|
||||
last_id: str | None = None
|
||||
has_more: bool
|
||||
|
||||
def __contains__(self, key):
|
||||
def __contains__(self, key) -> bool:
|
||||
return hasattr(self, key)
|
||||
|
||||
def get(self, key, default=None):
|
||||
|
|
@ -98,10 +98,10 @@ class ContainerCreateOptionalRequestParams(TypedDict, total=False):
|
|||
Params here: https://platform.openai.com/docs/api-reference/containers/create
|
||||
"""
|
||||
|
||||
expires_after: Optional[Dict[str, Any]] # ExpiresAfter object
|
||||
file_ids: Optional[List[str]]
|
||||
extra_headers: Optional[Dict[str, str]]
|
||||
extra_body: Optional[Dict[str, str]]
|
||||
expires_after: dict[str, Any] | None # ExpiresAfter object
|
||||
file_ids: list[str] | None
|
||||
extra_headers: dict[str, str] | None
|
||||
extra_body: dict[str, str] | None
|
||||
|
||||
|
||||
class ContainerCreateRequestParams(ContainerCreateOptionalRequestParams, total=False):
|
||||
|
|
@ -121,11 +121,11 @@ class ContainerListOptionalRequestParams(TypedDict, total=False):
|
|||
Params here: https://platform.openai.com/docs/api-reference/containers/list
|
||||
"""
|
||||
|
||||
after: Optional[str]
|
||||
limit: Optional[int]
|
||||
order: Optional[str]
|
||||
extra_headers: Optional[Dict[str, str]]
|
||||
extra_query: Optional[Dict[str, str]]
|
||||
after: str | None
|
||||
limit: int | None
|
||||
order: str | None
|
||||
extra_headers: dict[str, str] | None
|
||||
extra_query: dict[str, str] | None
|
||||
|
||||
|
||||
class ContainerFileObject(BaseModel):
|
||||
|
|
@ -134,13 +134,13 @@ class ContainerFileObject(BaseModel):
|
|||
id: str
|
||||
object: Literal["container.file", "container_file"] # OpenAI returns "container.file"
|
||||
container_id: str
|
||||
bytes: Optional[int] = None # Can be null for some files
|
||||
bytes: int | None = None # Can be null for some files
|
||||
created_at: int
|
||||
path: str
|
||||
source: str
|
||||
_hidden_params: Dict[str, Any] = {}
|
||||
_hidden_params: dict[str, Any] = {}
|
||||
|
||||
def __contains__(self, key):
|
||||
def __contains__(self, key) -> bool:
|
||||
return hasattr(self, key)
|
||||
|
||||
def get(self, key, default=None):
|
||||
|
|
@ -160,12 +160,12 @@ class ContainerFileListResponse(BaseModel):
|
|||
"""Response object for list container files request."""
|
||||
|
||||
object: Literal["list"]
|
||||
data: List[ContainerFileObject]
|
||||
first_id: Optional[str] = None
|
||||
last_id: Optional[str] = None
|
||||
data: list[ContainerFileObject]
|
||||
first_id: str | None = None
|
||||
last_id: str | None = None
|
||||
has_more: bool
|
||||
|
||||
def __contains__(self, key):
|
||||
def __contains__(self, key) -> bool:
|
||||
return hasattr(self, key)
|
||||
|
||||
def get(self, key, default=None):
|
||||
|
|
@ -189,7 +189,7 @@ class DeleteContainerFileResponse(BaseModel):
|
|||
object: Literal["container.file.deleted", "container_file.deleted"]
|
||||
deleted: bool
|
||||
|
||||
def __contains__(self, key):
|
||||
def __contains__(self, key) -> bool:
|
||||
return hasattr(self, key)
|
||||
|
||||
def get(self, key, default=None):
|
||||
|
|
|
|||
|
|
@ -1,21 +1,19 @@
|
|||
from typing import List, Optional, Union
|
||||
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
|
||||
|
||||
class EmbeddingRequest(BaseModel):
|
||||
model: str
|
||||
input: List[str] = []
|
||||
input: list[str] = []
|
||||
timeout: int = 600
|
||||
api_base: Optional[str] = None
|
||||
api_version: Optional[str] = None
|
||||
api_key: Optional[str] = None
|
||||
api_type: Optional[str] = None
|
||||
api_base: str | None = None
|
||||
api_version: str | None = None
|
||||
api_key: str | None = None
|
||||
api_type: str | None = None
|
||||
caching: bool = False
|
||||
user: Optional[str] = None
|
||||
custom_llm_provider: Optional[Union[str, dict]] = None
|
||||
litellm_call_id: Optional[str] = None
|
||||
litellm_logging_obj: Optional[dict] = None
|
||||
logger_fn: Optional[str] = None
|
||||
user: str | None = None
|
||||
custom_llm_provider: str | dict | None = None
|
||||
litellm_call_id: str | None = None
|
||||
litellm_logging_obj: dict | None = None
|
||||
logger_fn: str | None = None
|
||||
|
||||
model_config = ConfigDict(extra="allow")
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
from collections.abc import Mapping
|
||||
from enum import Enum
|
||||
from types import MappingProxyType
|
||||
from typing import Any, Dict, Final, List, Literal, Mapping, Set, Union
|
||||
from typing import Any, Final, Literal
|
||||
|
||||
from typing_extensions import Required, TypedDict
|
||||
|
||||
|
|
@ -54,7 +55,7 @@ class FileType(Enum):
|
|||
XLSX = "XLSX"
|
||||
|
||||
|
||||
FILE_EXTENSIONS: Final[Mapping[FileType, List[str]]] = MappingProxyType(
|
||||
FILE_EXTENSIONS: Final[Mapping[FileType, list[str]]] = MappingProxyType(
|
||||
{
|
||||
FileType.AAC: ["aac"],
|
||||
FileType.CSV: ["csv"],
|
||||
|
|
@ -249,7 +250,7 @@ Other FileType Groupings
|
|||
"""
|
||||
# Accepted file types for GEMINI 1.5 through Vertex AI
|
||||
# https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/send-multimodal-prompts#gemini-send-multimodal-samples-images-nodejs
|
||||
GEMINI_1_5_ACCEPTED_FILE_TYPES: Final[Set[FileType]] = {
|
||||
GEMINI_1_5_ACCEPTED_FILE_TYPES: Final[set[FileType]] = {
|
||||
# Image
|
||||
FileType.PNG,
|
||||
FileType.JPEG,
|
||||
|
|
@ -302,8 +303,8 @@ class TwoStepFileUploadRequest(TypedDict):
|
|||
|
||||
method: Required[str]
|
||||
url: Required[str]
|
||||
headers: Required[Dict[str, str]]
|
||||
data: Required[Union[str, bytes, Dict[str, Any]]]
|
||||
headers: Required[dict[str, str]]
|
||||
data: Required[str | bytes | dict[str, Any]]
|
||||
|
||||
|
||||
class TwoStepFileUploadConfig(TypedDict, total=False):
|
||||
|
|
|
|||
|
|
@ -1,8 +1,5 @@
|
|||
# Import types from the Google GenAI SDK
|
||||
from typing import TYPE_CHECKING, Any, Dict, List, Optional, TypeAlias
|
||||
|
||||
from pydantic import BaseModel
|
||||
from typing_extensions import TypedDict
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from litellm.types.llms.openai import BaseLiteLLMOpenAIResponseObject
|
||||
|
||||
|
|
@ -20,40 +17,39 @@ if TYPE_CHECKING:
|
|||
ToolConfigDict = _genai_types.ToolConfigDict
|
||||
|
||||
class GenerateContentRequestDict(GenerateContentRequestParametersDict): # type: ignore[misc, valid-type]
|
||||
generationConfig: Optional[Any]
|
||||
tools: Optional[ToolConfigDict] # type: ignore[assignment, valid-type]
|
||||
generationConfig: Any | None
|
||||
tools: ToolConfigDict | None # type: ignore[assignment, valid-type]
|
||||
|
||||
class GenerateContentResponse(GoogleGenAIGenerateContentResponse, BaseLiteLLMOpenAIResponseObject): # type: ignore[misc, valid-type]
|
||||
_hidden_params: dict = {}
|
||||
pass
|
||||
|
||||
else:
|
||||
# Fallback types when google.genai is not available
|
||||
ContentListUnion = Any
|
||||
ContentListUnionDict = Dict[str, Any]
|
||||
GenerateContentConfigOrDict = Dict[str, Any]
|
||||
GoogleGenAIGenerateContentResponse = Dict[str, Any]
|
||||
GenerateContentContentListUnionDict = Dict[str, Any]
|
||||
ContentListUnionDict = dict[str, Any]
|
||||
GenerateContentConfigOrDict = dict[str, Any]
|
||||
GoogleGenAIGenerateContentResponse = dict[str, Any]
|
||||
GenerateContentContentListUnionDict = dict[str, Any]
|
||||
|
||||
# Create a proper fallback class that can be instantiated
|
||||
class GenerateContentConfigDict(dict): # type: ignore[misc]
|
||||
def __init__(self, **kwargs): # type: ignore
|
||||
def __init__(self, **kwargs) -> None: # type: ignore
|
||||
super().__init__(**kwargs)
|
||||
|
||||
class GenerateContentRequestParametersDict(dict): # type: ignore[misc]
|
||||
def __init__(self, **kwargs): # type: ignore
|
||||
def __init__(self, **kwargs) -> None: # type: ignore
|
||||
super().__init__(**kwargs)
|
||||
|
||||
ToolConfigDict = Dict[str, Any]
|
||||
ToolConfigDict = dict[str, Any]
|
||||
|
||||
class GenerateContentRequestDict(GenerateContentRequestParametersDict): # type: ignore[misc]
|
||||
def __init__(self, **kwargs): # type: ignore
|
||||
def __init__(self, **kwargs) -> None: # type: ignore
|
||||
# Extract specific fields
|
||||
self.generationConfig = kwargs.get("generationConfig")
|
||||
self.tools = kwargs.get("tools")
|
||||
super().__init__(**kwargs)
|
||||
|
||||
class GenerateContentResponse(BaseLiteLLMOpenAIResponseObject): # type: ignore[misc]
|
||||
def __init__(self, **kwargs): # type: ignore
|
||||
def __init__(self, **kwargs) -> None: # type: ignore
|
||||
super().__init__(**kwargs)
|
||||
self._hidden_params = kwargs.get("_hidden_params", {})
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
from datetime import datetime
|
||||
from enum import Enum
|
||||
from typing import Any, Dict, Final, List, Literal, Optional, Union
|
||||
from typing import Any, Final, Literal
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator
|
||||
from typing_extensions import Required, TypedDict
|
||||
|
|
@ -11,12 +11,24 @@ from litellm.types.proxy.guardrails.guardrail_hooks.akto import (
|
|||
from litellm.types.proxy.guardrails.guardrail_hooks.block_code_execution import (
|
||||
BlockCodeExecutionGuardrailConfigModel,
|
||||
)
|
||||
from litellm.types.proxy.guardrails.guardrail_hooks.cisco_ai_defense import (
|
||||
CiscoAIDefenseGuardrailConfigModel,
|
||||
)
|
||||
from litellm.types.proxy.guardrails.guardrail_hooks.compresr import (
|
||||
CompresrGuardrailConfigModel,
|
||||
)
|
||||
from litellm.types.proxy.guardrails.guardrail_hooks.enkryptai import (
|
||||
EnkryptAIGuardrailConfigs,
|
||||
)
|
||||
from litellm.types.proxy.guardrails.guardrail_hooks.grayswan import (
|
||||
GraySwanGuardrailConfigModel,
|
||||
)
|
||||
from litellm.types.proxy.guardrails.guardrail_hooks.headroom import (
|
||||
HeadroomGuardrailConfigModel,
|
||||
)
|
||||
from litellm.types.proxy.guardrails.guardrail_hooks.hiddenlayer import (
|
||||
HiddenlayerGuardrailConfigModel,
|
||||
)
|
||||
from litellm.types.proxy.guardrails.guardrail_hooks.ibm import (
|
||||
IBMGuardrailsBaseConfigModel,
|
||||
)
|
||||
|
|
@ -29,38 +41,26 @@ from litellm.types.proxy.guardrails.guardrail_hooks.ovalix import (
|
|||
from litellm.types.proxy.guardrails.guardrail_hooks.promptguard import (
|
||||
PromptGuardConfigModel,
|
||||
)
|
||||
from litellm.types.proxy.guardrails.guardrail_hooks.xecguard import (
|
||||
XecGuardConfigModel,
|
||||
from litellm.types.proxy.guardrails.guardrail_hooks.qohash import (
|
||||
QostodianNexusConfigModel,
|
||||
)
|
||||
from litellm.types.proxy.guardrails.guardrail_hooks.qualifire import (
|
||||
QualifireGuardrailConfigModel,
|
||||
)
|
||||
from litellm.types.proxy.guardrails.guardrail_hooks.tool_permission import (
|
||||
ToolPermissionGuardrailConfigModel,
|
||||
)
|
||||
from litellm.types.proxy.guardrails.guardrail_hooks.hiddenlayer import (
|
||||
HiddenlayerGuardrailConfigModel,
|
||||
)
|
||||
from litellm.types.proxy.guardrails.guardrail_hooks.qohash import (
|
||||
QostodianNexusConfigModel,
|
||||
)
|
||||
from litellm.types.proxy.guardrails.guardrail_hooks.repelloai import (
|
||||
RepelloAIGuardrailConfigModel,
|
||||
)
|
||||
from litellm.types.proxy.guardrails.guardrail_hooks.vigil_guard import (
|
||||
VigilGuardGuardrailConfigModel,
|
||||
)
|
||||
from litellm.types.proxy.guardrails.guardrail_hooks.cisco_ai_defense import (
|
||||
CiscoAIDefenseGuardrailConfigModel,
|
||||
)
|
||||
from litellm.types.proxy.guardrails.guardrail_hooks.singulr import (
|
||||
SingulrGuardrailConfigModel,
|
||||
)
|
||||
from litellm.types.proxy.guardrails.guardrail_hooks.headroom import (
|
||||
HeadroomGuardrailConfigModel,
|
||||
from litellm.types.proxy.guardrails.guardrail_hooks.tool_permission import (
|
||||
ToolPermissionGuardrailConfigModel,
|
||||
)
|
||||
from litellm.types.proxy.guardrails.guardrail_hooks.compresr import (
|
||||
CompresrGuardrailConfigModel,
|
||||
from litellm.types.proxy.guardrails.guardrail_hooks.vigil_guard import (
|
||||
VigilGuardGuardrailConfigModel,
|
||||
)
|
||||
from litellm.types.proxy.guardrails.guardrail_hooks.xecguard import (
|
||||
XecGuardConfigModel,
|
||||
)
|
||||
|
||||
"""
|
||||
|
|
@ -145,32 +145,34 @@ default_roles: Final = [Role.SYSTEM, Role.ASSISTANT, Role.USER]
|
|||
|
||||
|
||||
class GuardrailItemSpec(TypedDict, total=False):
|
||||
callbacks: Required[List[str]]
|
||||
callbacks: Required[list[str]]
|
||||
default_on: bool
|
||||
logging_only: Optional[bool]
|
||||
enabled_roles: Optional[List[Role]]
|
||||
callback_args: Dict[str, Dict]
|
||||
logging_only: bool | None
|
||||
enabled_roles: list[Role] | None
|
||||
callback_args: dict[str, dict]
|
||||
|
||||
|
||||
class GuardrailItem(BaseModel):
|
||||
callbacks: List[str]
|
||||
callbacks: list[str]
|
||||
default_on: bool
|
||||
logging_only: Optional[bool]
|
||||
logging_only: bool | None
|
||||
guardrail_name: str
|
||||
callback_args: Dict[str, Dict]
|
||||
enabled_roles: Optional[List[Role]]
|
||||
callback_args: dict[str, dict]
|
||||
enabled_roles: list[Role] | None
|
||||
|
||||
model_config = ConfigDict(use_enum_values=True)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
callbacks: List[str],
|
||||
callbacks: list[str],
|
||||
guardrail_name: str,
|
||||
default_on: bool = False,
|
||||
logging_only: Optional[bool] = None,
|
||||
enabled_roles: Optional[List[Role]] = default_roles,
|
||||
callback_args: Dict[str, Dict] = {},
|
||||
):
|
||||
logging_only: bool | None = None,
|
||||
enabled_roles: list[Role] | None = default_roles,
|
||||
callback_args: dict[str, dict] | None = None,
|
||||
) -> None:
|
||||
if callback_args is None:
|
||||
callback_args = {}
|
||||
super().__init__(
|
||||
callbacks=callbacks,
|
||||
default_on=default_on,
|
||||
|
|
@ -322,7 +324,7 @@ PII_ENTITY_CATEGORIES_MAP: Final = {
|
|||
|
||||
class PiiEntityCategoryMap(TypedDict):
|
||||
category: str
|
||||
entities: List[str]
|
||||
entities: list[str]
|
||||
|
||||
|
||||
class GuardrailParamUITypes(str, Enum):
|
||||
|
|
@ -335,31 +337,31 @@ class GuardrailParamUITypes(str, Enum):
|
|||
class PresidioPresidioConfigModelUserInterface(BaseModel):
|
||||
"""Configuration parameters for the Presidio PII masking guardrail on LiteLLM UI"""
|
||||
|
||||
presidio_analyzer_api_base: Optional[str] = Field(
|
||||
presidio_analyzer_api_base: str | None = Field(
|
||||
default=None,
|
||||
description="Base URL for the Presidio analyzer API",
|
||||
)
|
||||
presidio_anonymizer_api_base: Optional[str] = Field(
|
||||
presidio_anonymizer_api_base: str | None = Field(
|
||||
default=None,
|
||||
description="Base URL for the Presidio anonymizer API",
|
||||
)
|
||||
presidio_filter_scope: Optional[Literal["input", "output", "both"]] = Field(
|
||||
presidio_filter_scope: Literal["input", "output", "both"] | None = Field(
|
||||
default=None,
|
||||
description=(
|
||||
"Where to apply Presidio checks: 'input' (user -> model), 'output' (model -> user), or 'both' (default)."
|
||||
),
|
||||
)
|
||||
output_parse_pii: Optional[bool] = Field(
|
||||
output_parse_pii: bool | None = Field(
|
||||
default=None,
|
||||
description="When True, LiteLLM will replace the masked text with the original text in the response",
|
||||
# extra param to let the ui know this is a boolean
|
||||
json_schema_extra={"ui_type": GuardrailParamUITypes.BOOL},
|
||||
)
|
||||
presidio_language: Optional[str] = Field(
|
||||
presidio_language: str | None = Field(
|
||||
default="en",
|
||||
description="Language code for Presidio PII analysis (e.g., 'en', 'de', 'es', 'fr')",
|
||||
)
|
||||
presidio_run_on: Optional[Literal["input", "output", "both"]] = Field(
|
||||
presidio_run_on: Literal["input", "output", "both"] | None = Field(
|
||||
default=None,
|
||||
description="Where to apply Presidio checks: input, output, or both (default).",
|
||||
)
|
||||
|
|
@ -368,18 +370,18 @@ class PresidioPresidioConfigModelUserInterface(BaseModel):
|
|||
class PresidioConfigModel(PresidioPresidioConfigModelUserInterface):
|
||||
"""Configuration parameters for the Presidio PII masking guardrail"""
|
||||
|
||||
pii_entities_config: Optional[Dict[Union[PiiEntityType, str], PiiAction]] = Field(
|
||||
pii_entities_config: dict[PiiEntityType | str, PiiAction] | None = Field(
|
||||
default=None, description="Configuration for PII entity types and actions"
|
||||
)
|
||||
|
||||
presidio_score_thresholds: Optional[Dict[Union[PiiEntityType, str], float]] = Field(
|
||||
presidio_score_thresholds: dict[PiiEntityType | str, float] | None = Field(
|
||||
default=None,
|
||||
description=(
|
||||
"Optional per-entity minimum confidence scores for Presidio detections. "
|
||||
"Entities below the threshold are ignored."
|
||||
),
|
||||
)
|
||||
presidio_entities_deny_list: Optional[List[Union[PiiEntityType, str]]] = Field(
|
||||
presidio_entities_deny_list: list[PiiEntityType | str] | None = Field(
|
||||
default=None,
|
||||
description=(
|
||||
"List of entity types to exclude from Presidio detection results. "
|
||||
|
|
@ -387,11 +389,11 @@ class PresidioConfigModel(PresidioPresidioConfigModelUserInterface):
|
|||
"Useful for suppressing false positives (e.g., US_DRIVER_LICENSE on coding routes)."
|
||||
),
|
||||
)
|
||||
presidio_ad_hoc_recognizers: Optional[str] = Field(
|
||||
presidio_ad_hoc_recognizers: str | None = Field(
|
||||
default=None,
|
||||
description="Path to a JSON file containing ad-hoc recognizers for Presidio",
|
||||
)
|
||||
mock_redacted_text: Optional[dict] = Field(default=None, description="Mock redacted text for testing")
|
||||
mock_redacted_text: dict | None = Field(default=None, description="Mock redacted text for testing")
|
||||
|
||||
|
||||
BedrockChecksContentFilterCategory = Literal["VIOLENCE", "HATE", "SEXUAL", "MISCONDUCT", "INSULTS"]
|
||||
|
|
@ -477,27 +479,25 @@ class BedrockChecksConfigModel(BaseModel):
|
|||
class BedrockGuardrailConfigModel(BaseModel):
|
||||
"""Configuration parameters for the AWS Bedrock guardrail"""
|
||||
|
||||
guardrailIdentifier: Optional[str] = Field(default=None, description="The ID of your guardrail on Bedrock")
|
||||
guardrailVersion: Optional[str] = Field(
|
||||
guardrailIdentifier: str | None = Field(default=None, description="The ID of your guardrail on Bedrock")
|
||||
guardrailVersion: str | None = Field(
|
||||
default=None,
|
||||
description="The version of your Bedrock guardrail (e.g., DRAFT or version number)",
|
||||
)
|
||||
disable_exception_on_block: Optional[bool] = Field(
|
||||
disable_exception_on_block: bool | None = Field(
|
||||
default=False,
|
||||
description="If True, will not raise an exception when the guardrail is blocked. Useful for OpenWebUI where exceptions can end the chat flow.",
|
||||
)
|
||||
aws_region_name: Optional[str] = Field(default=None, description="AWS region where your guardrail is deployed")
|
||||
aws_access_key_id: Optional[str] = Field(default=None, description="AWS access key ID for authentication")
|
||||
aws_secret_access_key: Optional[str] = Field(default=None, description="AWS secret access key for authentication")
|
||||
aws_session_token: Optional[str] = Field(default=None, description="AWS session token for temporary credentials")
|
||||
aws_session_name: Optional[str] = Field(default=None, description="Name of the AWS session")
|
||||
aws_profile_name: Optional[str] = Field(default=None, description="AWS profile name for credential retrieval")
|
||||
aws_role_name: Optional[str] = Field(default=None, description="AWS role name for assuming roles")
|
||||
aws_web_identity_token: Optional[str] = Field(
|
||||
default=None, description="Web identity token for AWS role assumption"
|
||||
)
|
||||
aws_sts_endpoint: Optional[str] = Field(default=None, description="AWS STS endpoint URL")
|
||||
aws_bedrock_runtime_endpoint: Optional[str] = Field(default=None, description="AWS Bedrock runtime endpoint URL")
|
||||
aws_region_name: str | None = Field(default=None, description="AWS region where your guardrail is deployed")
|
||||
aws_access_key_id: str | None = Field(default=None, description="AWS access key ID for authentication")
|
||||
aws_secret_access_key: str | None = Field(default=None, description="AWS secret access key for authentication")
|
||||
aws_session_token: str | None = Field(default=None, description="AWS session token for temporary credentials")
|
||||
aws_session_name: str | None = Field(default=None, description="Name of the AWS session")
|
||||
aws_profile_name: str | None = Field(default=None, description="AWS profile name for credential retrieval")
|
||||
aws_role_name: str | None = Field(default=None, description="AWS role name for assuming roles")
|
||||
aws_web_identity_token: str | None = Field(default=None, description="Web identity token for AWS role assumption")
|
||||
aws_sts_endpoint: str | None = Field(default=None, description="AWS STS endpoint URL")
|
||||
aws_bedrock_runtime_endpoint: str | None = Field(default=None, description="AWS Bedrock runtime endpoint URL")
|
||||
checks: BedrockChecksConfigModel | None = Field(
|
||||
default=None,
|
||||
description="Inline safeguards for the resource-less InvokeGuardrailChecks API "
|
||||
|
|
@ -532,17 +532,17 @@ class BedrockGuardrailConfigModel(BaseModel):
|
|||
class LakeraV2GuardrailConfigModel(BaseModel):
|
||||
"""Configuration parameters for the Lakera AI v2 guardrail"""
|
||||
|
||||
api_key: Optional[str] = Field(default=None, description="API key for the Lakera AI service")
|
||||
api_base: Optional[str] = Field(default=None, description="Base URL for the Lakera AI API")
|
||||
project_id: Optional[str] = Field(default=None, description="Project ID for the Lakera AI project")
|
||||
payload: Optional[bool] = Field(default=True, description="Whether to include payload in the response")
|
||||
breakdown: Optional[bool] = Field(default=True, description="Whether to include breakdown in the response")
|
||||
metadata: Optional[Dict] = Field(default=None, description="Additional metadata to include in the request")
|
||||
dev_info: Optional[bool] = Field(
|
||||
api_key: str | None = Field(default=None, description="API key for the Lakera AI service")
|
||||
api_base: str | None = Field(default=None, description="Base URL for the Lakera AI API")
|
||||
project_id: str | None = Field(default=None, description="Project ID for the Lakera AI project")
|
||||
payload: bool | None = Field(default=True, description="Whether to include payload in the response")
|
||||
breakdown: bool | None = Field(default=True, description="Whether to include breakdown in the response")
|
||||
metadata: dict | None = Field(default=None, description="Additional metadata to include in the request")
|
||||
dev_info: bool | None = Field(
|
||||
default=True,
|
||||
description="Whether to include developer information in the response",
|
||||
)
|
||||
on_flagged: Optional[Literal["block", "monitor"]] = Field(
|
||||
on_flagged: Literal["block", "monitor"] | None = Field(
|
||||
default="block",
|
||||
description="Action to take when content is flagged: 'block' (raise exception) or 'monitor' (log only)",
|
||||
)
|
||||
|
|
@ -551,15 +551,15 @@ class LakeraV2GuardrailConfigModel(BaseModel):
|
|||
class LassoGuardrailConfigModel(BaseModel):
|
||||
"""Configuration parameters for the Lasso guardrail"""
|
||||
|
||||
lasso_user_id: Optional[str] = Field(default=None, description="User ID for the Lasso guardrail")
|
||||
lasso_conversation_id: Optional[str] = Field(default=None, description="Conversation ID for the Lasso guardrail")
|
||||
mask: Optional[bool] = Field(default=False, description="Enable content masking using Lasso classifix API")
|
||||
lasso_user_id: str | None = Field(default=None, description="User ID for the Lasso guardrail")
|
||||
lasso_conversation_id: str | None = Field(default=None, description="Conversation ID for the Lasso guardrail")
|
||||
mask: bool | None = Field(default=False, description="Enable content masking using Lasso classifix API")
|
||||
|
||||
|
||||
class DeepKeepGuardrailConfigModel(BaseModel):
|
||||
"""Configuration parameters for the DeepKeep AI Firewall guardrail"""
|
||||
|
||||
deepkeep_firewall_id: Optional[str] = Field(
|
||||
deepkeep_firewall_id: str | None = Field(
|
||||
default=None,
|
||||
description=(
|
||||
"The DeepKeep Firewall ID to use for guardrail evaluation. "
|
||||
|
|
@ -571,23 +571,23 @@ class DeepKeepGuardrailConfigModel(BaseModel):
|
|||
class PillarGuardrailConfigModel(BaseModel):
|
||||
"""Configuration parameters for the Pillar Security guardrail"""
|
||||
|
||||
on_flagged_action: Optional[str] = Field(
|
||||
on_flagged_action: str | None = Field(
|
||||
default="monitor",
|
||||
description="Action to take when content is flagged: 'block' (raise exception) or 'monitor' (log only)",
|
||||
)
|
||||
async_mode: Optional[bool] = Field(
|
||||
async_mode: bool | None = Field(
|
||||
default=None,
|
||||
description="Set to True to request asynchronous analysis (sets `plr_async` header). Defaults to provider behaviour when omitted.",
|
||||
)
|
||||
persist_session: Optional[bool] = Field(
|
||||
persist_session: bool | None = Field(
|
||||
default=None,
|
||||
description="Controls Pillar session persistence (sets `plr_persist` header). Set to False to disable persistence.",
|
||||
)
|
||||
include_scanners: Optional[bool] = Field(
|
||||
include_scanners: bool | None = Field(
|
||||
default=True,
|
||||
description="Include scanner category summaries in responses (sets `plr_scanners` header).",
|
||||
)
|
||||
include_evidence: Optional[bool] = Field(
|
||||
include_evidence: bool | None = Field(
|
||||
default=True,
|
||||
description="Include detailed evidence payloads in responses (sets `plr_evidence` header).",
|
||||
)
|
||||
|
|
@ -596,23 +596,23 @@ class PillarGuardrailConfigModel(BaseModel):
|
|||
class NomaGuardrailConfigModel(BaseModel):
|
||||
"""Configuration parameters for the Noma Security guardrail"""
|
||||
|
||||
use_v2: Optional[bool] = Field(
|
||||
use_v2: bool | None = Field(
|
||||
default=False,
|
||||
description="If True and guardrail='noma', route to the new Noma v2 implementation instead of the legacy implementation.",
|
||||
)
|
||||
application_id: Optional[str] = Field(
|
||||
application_id: str | None = Field(
|
||||
default=None,
|
||||
description="Application ID for Noma Security. Defaults to 'litellm' if not provided",
|
||||
)
|
||||
monitor_mode: Optional[bool] = Field(
|
||||
monitor_mode: bool | None = Field(
|
||||
default=None,
|
||||
description="If True, logs violations without blocking. Defaults to False if not provided",
|
||||
)
|
||||
block_failures: Optional[bool] = Field(
|
||||
block_failures: bool | None = Field(
|
||||
default=None,
|
||||
description="If True, blocks requests on API failures. Defaults to True if not provided",
|
||||
)
|
||||
anonymize_input: Optional[bool] = Field(
|
||||
anonymize_input: bool | None = Field(
|
||||
default=None,
|
||||
description="If True, replaces sensitive content with anonymized version when only PII/PCI/secrets are detected. Only applies in blocking mode. Defaults to False if not provided",
|
||||
)
|
||||
|
|
@ -621,17 +621,17 @@ class NomaGuardrailConfigModel(BaseModel):
|
|||
class ZscalerAIGuardConfigModel(BaseModel):
|
||||
"""Configuration parameters for the Zscaler AI Guard guardrail"""
|
||||
|
||||
policy_id: Optional[int] = Field(
|
||||
policy_id: int | None = Field(
|
||||
default=None,
|
||||
description="Policy ID for Zscaler AI Guard. Can also be set via ZSCALER_AI_GUARD_POLICY_ID environment variable",
|
||||
)
|
||||
send_user_api_key_alias: Optional[bool] = Field(
|
||||
send_user_api_key_alias: bool | None = Field(
|
||||
default=False, description="Whether to send user_API_key_alias in headers"
|
||||
)
|
||||
send_user_api_key_user_id: Optional[bool] = Field(
|
||||
send_user_api_key_user_id: bool | None = Field(
|
||||
default=False, description="Whether to send user_API_key_user_id in headers"
|
||||
)
|
||||
send_user_api_key_team_id: Optional[bool] = Field(
|
||||
send_user_api_key_team_id: bool | None = Field(
|
||||
default=False, description="Whether to send user_API_key_team_id in headers"
|
||||
)
|
||||
|
||||
|
|
@ -639,11 +639,11 @@ class ZscalerAIGuardConfigModel(BaseModel):
|
|||
class JavelinGuardrailConfigModel(BaseModel):
|
||||
"""Configuration parameters for the Javelin guardrail"""
|
||||
|
||||
guard_name: Optional[str] = Field(default=None, description="Name of the Javelin guard to use")
|
||||
api_version: Optional[str] = Field(default="v1", description="API version for Javelin service")
|
||||
metadata: Optional[Dict] = Field(default=None, description="Additional metadata to send with requests")
|
||||
application: Optional[str] = Field(default=None, description="Application name for Javelin service")
|
||||
config: Optional[Dict] = Field(default=None, description="Additional configuration for the guardrail")
|
||||
guard_name: str | None = Field(default=None, description="Name of the Javelin guard to use")
|
||||
api_version: str | None = Field(default="v1", description="API version for Javelin service")
|
||||
metadata: dict | None = Field(default=None, description="Additional metadata to send with requests")
|
||||
application: str | None = Field(default=None, description="Application name for Javelin service")
|
||||
config: dict | None = Field(default=None, description="Additional configuration for the guardrail")
|
||||
|
||||
|
||||
class ContentFilterAction(str, Enum):
|
||||
|
|
@ -658,7 +658,7 @@ class BlockedWord(BaseModel):
|
|||
|
||||
keyword: str = Field(description="The keyword to block or mask")
|
||||
action: ContentFilterAction = Field(description="Action to take when keyword is detected (BLOCK or MASK)")
|
||||
description: Optional[str] = Field(
|
||||
description: str | None = Field(
|
||||
default=None,
|
||||
description="Optional description explaining why this keyword is sensitive",
|
||||
)
|
||||
|
|
@ -670,15 +670,15 @@ class ContentFilterPattern(BaseModel):
|
|||
pattern_type: Literal["prebuilt", "regex"] = Field(
|
||||
description="Type of pattern: 'prebuilt' for predefined patterns or 'regex' for custom"
|
||||
)
|
||||
pattern_name: Optional[str] = Field(
|
||||
pattern_name: str | None = Field(
|
||||
default=None,
|
||||
description="Name of prebuilt pattern (e.g., 'us_ssn', 'credit_card'). Required if pattern_type is 'prebuilt'",
|
||||
)
|
||||
pattern: Optional[str] = Field(
|
||||
pattern: str | None = Field(
|
||||
default=None,
|
||||
description="Custom regex pattern. Required if pattern_type is 'regex'",
|
||||
)
|
||||
name: Optional[str] = Field(
|
||||
name: str | None = Field(
|
||||
default=None,
|
||||
description="Name for this pattern (used in logging and error messages)",
|
||||
)
|
||||
|
|
@ -688,44 +688,42 @@ class ContentFilterPattern(BaseModel):
|
|||
class ContentFilterConfigModel(BaseModel):
|
||||
"""Configuration parameters for the content filter guardrail"""
|
||||
|
||||
patterns: Optional[List[ContentFilterPattern]] = Field(
|
||||
patterns: list[ContentFilterPattern] | None = Field(
|
||||
default=None,
|
||||
description="List of patterns (prebuilt or custom regex) to detect",
|
||||
)
|
||||
blocked_words: Optional[List[BlockedWord]] = Field(
|
||||
blocked_words: list[BlockedWord] | None = Field(
|
||||
default=None, description="List of blocked words with individual actions"
|
||||
)
|
||||
blocked_words_file: Optional[str] = Field(
|
||||
default=None, description="Path to YAML file containing blocked_words list"
|
||||
)
|
||||
categories: Optional[List[ContentFilterCategoryConfig]] = Field(
|
||||
blocked_words_file: str | None = Field(default=None, description="Path to YAML file containing blocked_words list")
|
||||
categories: list[ContentFilterCategoryConfig] | None = Field(
|
||||
default=None,
|
||||
description="List of prebuilt categories to enable (harmful_*, bias_*)",
|
||||
)
|
||||
severity_threshold: Optional[str] = Field(
|
||||
severity_threshold: str | None = Field(
|
||||
default=None,
|
||||
description="Minimum severity to block (high, medium, low)",
|
||||
)
|
||||
pattern_redaction_format: Optional[str] = Field(
|
||||
pattern_redaction_format: str | None = Field(
|
||||
default=None,
|
||||
description="Format string for pattern redaction (use {pattern_name} placeholder)",
|
||||
)
|
||||
keyword_redaction_tag: Optional[str] = Field(
|
||||
keyword_redaction_tag: str | None = Field(
|
||||
default=None,
|
||||
description="Tag to use for keyword redaction",
|
||||
)
|
||||
|
||||
|
||||
class BaseLitellmParams(ContentFilterConfigModel): # works for new and patch update guardrails
|
||||
api_key: Optional[str] = Field(default=None, description="API key for the guardrail service")
|
||||
api_base: Optional[str] = Field(default=None, description="Base URL for the guardrail service API")
|
||||
api_key: str | None = Field(default=None, description="API key for the guardrail service")
|
||||
api_base: str | None = Field(default=None, description="Base URL for the guardrail service API")
|
||||
|
||||
experimental_use_latest_role_message_only: Optional[bool] = Field(
|
||||
experimental_use_latest_role_message_only: bool | None = Field(
|
||||
default=False,
|
||||
description="When True, guardrails only receive the latest message for the relevant role (e.g., newest user input pre-call, newest assistant output post-call)",
|
||||
)
|
||||
|
||||
only_scan_new_messages: Optional[bool] = Field(
|
||||
only_scan_new_messages: bool | None = Field(
|
||||
default=False,
|
||||
description=(
|
||||
"When True, the guardrail only scans messages that have not already been scanned "
|
||||
|
|
@ -737,7 +735,7 @@ class BaseLitellmParams(ContentFilterConfigModel): # works for new and patch up
|
|||
),
|
||||
)
|
||||
|
||||
skip_system_message_in_guardrail: Optional[bool] = Field(
|
||||
skip_system_message_in_guardrail: bool | None = Field(
|
||||
default=None,
|
||||
description=(
|
||||
"When True, unified guardrails skip system-role messages when building "
|
||||
|
|
@ -747,7 +745,7 @@ class BaseLitellmParams(ContentFilterConfigModel): # works for new and patch up
|
|||
),
|
||||
)
|
||||
|
||||
skip_tool_message_in_guardrail: Optional[bool] = Field(
|
||||
skip_tool_message_in_guardrail: bool | None = Field(
|
||||
default=None,
|
||||
description=(
|
||||
"When True, unified guardrails skip tool-role messages when building "
|
||||
|
|
@ -758,70 +756,68 @@ class BaseLitellmParams(ContentFilterConfigModel): # works for new and patch up
|
|||
)
|
||||
|
||||
# Lakera specific params
|
||||
category_thresholds: Optional[LakeraCategoryThresholds] = Field(
|
||||
category_thresholds: LakeraCategoryThresholds | None = Field(
|
||||
default=None,
|
||||
description="Threshold configuration for Lakera guardrail categories",
|
||||
)
|
||||
|
||||
# hide secrets params
|
||||
detect_secrets_config: Optional[dict] = Field(
|
||||
default=None, description="Configuration for detect-secrets guardrail"
|
||||
)
|
||||
detect_secrets_config: dict | None = Field(default=None, description="Configuration for detect-secrets guardrail")
|
||||
|
||||
# guardrails ai params
|
||||
guard_name: Optional[str] = Field(default=None, description="Name of the guardrail in guardrails.ai")
|
||||
default_on: Optional[bool] = Field(default=None, description="Whether the guardrail is enabled by default")
|
||||
guard_name: str | None = Field(default=None, description="Name of the guardrail in guardrails.ai")
|
||||
default_on: bool | None = Field(default=None, description="Whether the guardrail is enabled by default")
|
||||
|
||||
################## PII control params #################
|
||||
########################################################
|
||||
mask_request_content: Optional[bool] = Field(
|
||||
mask_request_content: bool | None = Field(
|
||||
default=None,
|
||||
description="Will mask request content if guardrail makes any changes",
|
||||
)
|
||||
mask_response_content: Optional[bool] = Field(
|
||||
mask_response_content: bool | None = Field(
|
||||
default=None,
|
||||
description="Will mask response content if guardrail makes any changes",
|
||||
)
|
||||
|
||||
# pangea params
|
||||
pangea_input_recipe: Optional[str] = Field(default=None, description="Recipe for input (LLM request)")
|
||||
pangea_input_recipe: str | None = Field(default=None, description="Recipe for input (LLM request)")
|
||||
|
||||
pangea_output_recipe: Optional[str] = Field(default=None, description="Recipe for output (LLM response)")
|
||||
pangea_output_recipe: str | None = Field(default=None, description="Recipe for output (LLM response)")
|
||||
|
||||
model: Optional[str] = Field(
|
||||
model: str | None = Field(
|
||||
default=None,
|
||||
description="Optional field if guardrail requires a 'model' parameter",
|
||||
)
|
||||
|
||||
violation_message_template: Optional[str] = Field(
|
||||
violation_message_template: str | None = Field(
|
||||
default=None,
|
||||
description="Custom message when a guardrail blocks an action. Supports placeholders like {tool_name}, {rule_id}, and {default_message}.",
|
||||
)
|
||||
|
||||
################## Realtime API params ################
|
||||
########################################################
|
||||
end_session_after_n_fails: Optional[int] = Field(
|
||||
end_session_after_n_fails: int | None = Field(
|
||||
default=None,
|
||||
description="For /v1/realtime sessions: automatically close the session after this many guardrail violations.",
|
||||
)
|
||||
on_violation: Optional[Literal["warn", "end_session"]] = Field(
|
||||
on_violation: Literal["warn", "end_session"] | None = Field(
|
||||
default=None,
|
||||
description="For /v1/realtime sessions: 'warn' speaks the violation message and continues; 'end_session' speaks the message and closes the connection.",
|
||||
)
|
||||
realtime_violation_message: Optional[str] = Field(
|
||||
realtime_violation_message: str | None = Field(
|
||||
default=None,
|
||||
description="The message the bot speaks aloud when a /v1/realtime guardrail fires. Falls back to violation_message_template if not set.",
|
||||
)
|
||||
|
||||
# Model Armor params
|
||||
template_id: Optional[str] = Field(default=None, description="The ID of your Model Armor template")
|
||||
location: Optional[str] = Field(default=None, description="Google Cloud location/region (e.g., us-central1)")
|
||||
credentials: Optional[str] = Field(
|
||||
template_id: str | None = Field(default=None, description="The ID of your Model Armor template")
|
||||
location: str | None = Field(default=None, description="Google Cloud location/region (e.g., us-central1)")
|
||||
credentials: str | None = Field(
|
||||
default=None,
|
||||
description="Path to Google Cloud credentials JSON file or JSON string",
|
||||
)
|
||||
api_endpoint: Optional[str] = Field(default=None, description="Optional custom API endpoint for Model Armor")
|
||||
fail_on_error: Optional[bool] = Field(
|
||||
api_endpoint: str | None = Field(default=None, description="Optional custom API endpoint for Model Armor")
|
||||
fail_on_error: bool | None = Field(
|
||||
default=True,
|
||||
description=(
|
||||
"Whether to fail the request if the guardrail encounters an error. "
|
||||
|
|
@ -830,7 +826,7 @@ class BaseLitellmParams(ContentFilterConfigModel): # works for new and patch up
|
|||
"so only a valid guardrail response can block or modify it."
|
||||
),
|
||||
)
|
||||
skip_unscannable_attachments: Optional[bool] = Field(
|
||||
skip_unscannable_attachments: bool | None = Field(
|
||||
default=False,
|
||||
description=(
|
||||
"Implemented by guardrail='model_armor'. When True, attachment references that carry no "
|
||||
|
|
@ -838,7 +834,7 @@ class BaseLitellmParams(ContentFilterConfigModel): # works for new and patch up
|
|||
"while fail_on_error still governs real Model Armor API errors. Default False blocks them."
|
||||
),
|
||||
)
|
||||
sanitize_error_detail: Optional[bool] = Field(
|
||||
sanitize_error_detail: bool | None = Field(
|
||||
default=True,
|
||||
description=(
|
||||
"For guardrail='model_armor': omit the raw Model Armor response from "
|
||||
|
|
@ -846,7 +842,7 @@ class BaseLitellmParams(ContentFilterConfigModel): # works for new and patch up
|
|||
),
|
||||
)
|
||||
|
||||
additional_provider_specific_params: Optional[Dict[str, Any]] = Field(
|
||||
additional_provider_specific_params: dict[str, Any] | None = Field(
|
||||
default=None,
|
||||
description="Additional provider-specific parameters for generic guardrail APIs",
|
||||
)
|
||||
|
|
@ -860,7 +856,7 @@ class BaseLitellmParams(ContentFilterConfigModel): # works for new and patch up
|
|||
),
|
||||
)
|
||||
|
||||
extra_headers: Optional[List[str]] = Field(
|
||||
extra_headers: list[str] | None = Field(
|
||||
default=None,
|
||||
description=(
|
||||
"Header names to forward from the client request to the guardrail (e.g. x-request-id). "
|
||||
|
|
@ -870,12 +866,12 @@ class BaseLitellmParams(ContentFilterConfigModel): # works for new and patch up
|
|||
)
|
||||
|
||||
# Custom code guardrail params
|
||||
custom_code: Optional[str] = Field(
|
||||
custom_code: str | None = Field(
|
||||
default=None,
|
||||
description="Python-like code containing the apply_guardrail function for custom guardrail logic",
|
||||
)
|
||||
|
||||
timeout: Optional[float] = Field(
|
||||
timeout: float | None = Field(
|
||||
default=None,
|
||||
description=(
|
||||
"Per-request timeout for the guardrail provider API call (seconds). "
|
||||
|
|
@ -884,7 +880,7 @@ class BaseLitellmParams(ContentFilterConfigModel): # works for new and patch up
|
|||
),
|
||||
)
|
||||
|
||||
on_sensitive_data: Optional[Literal["block", "route"]] = Field(
|
||||
on_sensitive_data: Literal["block", "route"] | None = Field(
|
||||
default=None,
|
||||
description=(
|
||||
"Action to take when sensitive data is detected. "
|
||||
|
|
@ -893,7 +889,7 @@ class BaseLitellmParams(ContentFilterConfigModel): # works for new and patch up
|
|||
),
|
||||
)
|
||||
|
||||
sensitive_data_route_to_model: Optional[str] = Field(
|
||||
sensitive_data_route_to_model: str | None = Field(
|
||||
default=None,
|
||||
description=(
|
||||
"Model to route requests to when sensitive data is detected and on_sensitive_data='route'. "
|
||||
|
|
@ -902,7 +898,7 @@ class BaseLitellmParams(ContentFilterConfigModel): # works for new and patch up
|
|||
),
|
||||
)
|
||||
|
||||
sticky_session_routing: Optional[bool] = Field(
|
||||
sticky_session_routing: bool | None = Field(
|
||||
default=True,
|
||||
description=(
|
||||
"When True (default), after sensitive data is detected and routed, all subsequent "
|
||||
|
|
@ -910,7 +906,7 @@ class BaseLitellmParams(ContentFilterConfigModel): # works for new and patch up
|
|||
),
|
||||
)
|
||||
|
||||
run_in_parallel: Optional[bool] = Field(
|
||||
run_in_parallel: bool | None = Field(
|
||||
default=None,
|
||||
description=(
|
||||
"When True, this pre_call or post_call guardrail runs concurrently with other opted-in "
|
||||
|
|
@ -949,8 +945,8 @@ class BaseLitellmParams(ContentFilterConfigModel): # works for new and patch up
|
|||
|
||||
|
||||
class Mode(BaseModel):
|
||||
tags: Dict[str, Union[str, List[str]]] = Field(description="Tags for the guardrail mode")
|
||||
default: Optional[Union[str, List[str]]] = Field(default=None, description="Default mode when no tags match")
|
||||
tags: dict[str, str | list[str]] = Field(description="Tags for the guardrail mode")
|
||||
default: str | list[str] | None = Field(default=None, description="Default mode when no tags match")
|
||||
|
||||
|
||||
class LitellmParams(
|
||||
|
|
@ -984,7 +980,7 @@ class LitellmParams(
|
|||
SingulrGuardrailConfigModel,
|
||||
):
|
||||
guardrail: str = Field(description="The type of guardrail integration to use")
|
||||
mode: Union[str, List[str], Mode] = Field(
|
||||
mode: str | list[str] | Mode = Field(
|
||||
description="When to apply the guardrail (pre_call, post_call, during_call, logging_only)"
|
||||
)
|
||||
|
||||
|
|
@ -1000,7 +996,7 @@ class LitellmParams(
|
|||
except (TypeError, ValueError) as e:
|
||||
raise ValueError(f"timeout must be numeric, got {v!r}") from e
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
def __init__(self, **kwargs) -> None:
|
||||
default_on: Final = kwargs.pop("default_on", None)
|
||||
if default_on is not None:
|
||||
kwargs["default_on"] = default_on
|
||||
|
|
@ -1009,7 +1005,7 @@ class LitellmParams(
|
|||
|
||||
super().__init__(**kwargs)
|
||||
|
||||
def __contains__(self, key):
|
||||
def __contains__(self, key) -> bool:
|
||||
# Define custom behavior for the 'in' operator
|
||||
return hasattr(self, key)
|
||||
|
||||
|
|
@ -1023,17 +1019,17 @@ class LitellmParams(
|
|||
|
||||
|
||||
class Guardrail(TypedDict, total=False):
|
||||
guardrail_id: Optional[str]
|
||||
guardrail_id: str | None
|
||||
guardrail_name: Required[str]
|
||||
litellm_params: Required[LitellmParams]
|
||||
guardrail_info: Optional[Dict]
|
||||
policy_template: Optional[str]
|
||||
created_at: Optional[datetime]
|
||||
updated_at: Optional[datetime]
|
||||
guardrail_info: dict | None
|
||||
policy_template: str | None
|
||||
created_at: datetime | None
|
||||
updated_at: datetime | None
|
||||
|
||||
|
||||
class guardrailConfig(TypedDict):
|
||||
guardrails: List[Guardrail]
|
||||
guardrails: list[Guardrail]
|
||||
|
||||
|
||||
class GuardrailEventHooks(str, Enum):
|
||||
|
|
@ -1048,7 +1044,7 @@ class GuardrailEventHooks(str, Enum):
|
|||
|
||||
|
||||
class DynamicGuardrailParams(TypedDict):
|
||||
extra_body: Dict[str, Any]
|
||||
extra_body: dict[str, Any]
|
||||
|
||||
|
||||
class GUARDRAIL_DEFINITION_LOCATION(str, Enum):
|
||||
|
|
@ -1057,29 +1053,29 @@ class GUARDRAIL_DEFINITION_LOCATION(str, Enum):
|
|||
|
||||
|
||||
class GuardrailInfoResponse(BaseModel):
|
||||
guardrail_id: Optional[str] = None
|
||||
guardrail_id: str | None = None
|
||||
guardrail_name: str
|
||||
litellm_params: Optional[BaseLitellmParams] = None
|
||||
guardrail_info: Optional[Dict] = None
|
||||
created_at: Optional[datetime] = None
|
||||
updated_at: Optional[datetime] = None
|
||||
litellm_params: BaseLitellmParams | None = None
|
||||
guardrail_info: dict | None = None
|
||||
created_at: datetime | None = None
|
||||
updated_at: datetime | None = None
|
||||
guardrail_definition_location: GUARDRAIL_DEFINITION_LOCATION = GUARDRAIL_DEFINITION_LOCATION.CONFIG
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
def __init__(self, **kwargs) -> None:
|
||||
super().__init__(**kwargs)
|
||||
|
||||
|
||||
class ListGuardrailsResponse(BaseModel):
|
||||
guardrails: List[GuardrailInfoResponse]
|
||||
guardrails: list[GuardrailInfoResponse]
|
||||
|
||||
|
||||
class GuardrailUIAddGuardrailSettings(BaseModel):
|
||||
supported_entities: List[str]
|
||||
supported_actions: List[str]
|
||||
supported_modes: List[str]
|
||||
supported_modes_by_provider: Dict[str, List[str]]
|
||||
pii_entity_categories: List[PiiEntityCategoryMap]
|
||||
content_filter_settings: Optional[Dict[str, Any]] = None
|
||||
supported_entities: list[str]
|
||||
supported_actions: list[str]
|
||||
supported_modes: list[str]
|
||||
supported_modes_by_provider: dict[str, list[str]]
|
||||
pii_entity_categories: list[PiiEntityCategoryMap]
|
||||
content_filter_settings: dict[str, Any] | None = None
|
||||
|
||||
|
||||
class PresidioPerRequestConfig(BaseModel):
|
||||
|
|
@ -1087,18 +1083,18 @@ class PresidioPerRequestConfig(BaseModel):
|
|||
presdio params that can be controlled per request, api key
|
||||
"""
|
||||
|
||||
language: Optional[str] = None
|
||||
entities: Optional[List[PiiEntityType]] = None
|
||||
language: str | None = None
|
||||
entities: list[PiiEntityType] | None = None
|
||||
|
||||
|
||||
class ApplyGuardrailRequest(BaseModel):
|
||||
guardrail_name: str
|
||||
text: str
|
||||
language: Optional[str] = None
|
||||
entities: Optional[List[PiiEntityType]] = None
|
||||
language: str | None = None
|
||||
entities: list[PiiEntityType] | None = None
|
||||
input_type: str = "request"
|
||||
messages: Optional[List[Dict[str, Any]]] = None
|
||||
metadata: Dict[str, Any] | None = None
|
||||
messages: list[dict[str, Any]] | None = None
|
||||
metadata: dict[str, Any] | None = None
|
||||
|
||||
|
||||
class ApplyGuardrailResponse(BaseModel):
|
||||
|
|
@ -1106,6 +1102,6 @@ class ApplyGuardrailResponse(BaseModel):
|
|||
|
||||
|
||||
class PatchGuardrailRequest(BaseModel):
|
||||
guardrail_name: Optional[str] = None
|
||||
litellm_params: Optional[BaseLitellmParams] = None
|
||||
guardrail_info: Optional[Dict[str, Any]] = None
|
||||
guardrail_name: str | None = None
|
||||
litellm_params: BaseLitellmParams | None = None
|
||||
guardrail_info: dict[str, Any] | None = None
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
from typing import Any, Dict, List, Literal, Optional, Union
|
||||
from typing import Any, Literal
|
||||
|
||||
from typing_extensions import TypedDict
|
||||
|
||||
|
|
@ -12,15 +12,15 @@ class ImageEditOptionalRequestParams(TypedDict, total=False):
|
|||
Params here: https://platform.openai.com/docs/api-reference/images/createEdit
|
||||
"""
|
||||
|
||||
background: Optional[Literal["transparent", "opaque", "auto"]]
|
||||
input_fidelity: Optional[Literal["high", "low"]]
|
||||
mask: Optional[str]
|
||||
n: Optional[int]
|
||||
quality: Optional[Literal["high", "medium", "low", "standard", "auto"]]
|
||||
response_format: Optional[Literal["url", "b64_json"]]
|
||||
size: Optional[str]
|
||||
user: Optional[str]
|
||||
imageConfig: Optional[Dict[str, Any]]
|
||||
background: Literal["transparent", "opaque", "auto"] | None
|
||||
input_fidelity: Literal["high", "low"] | None
|
||||
mask: str | None
|
||||
n: int | None
|
||||
quality: Literal["high", "medium", "low", "standard", "auto"] | None
|
||||
response_format: Literal["url", "b64_json"] | None
|
||||
size: str | None
|
||||
user: str | None
|
||||
imageConfig: dict[str, Any] | None
|
||||
|
||||
|
||||
class ImageEditRequestParams(ImageEditOptionalRequestParams, total=False):
|
||||
|
|
@ -32,4 +32,4 @@ class ImageEditRequestParams(ImageEditOptionalRequestParams, total=False):
|
|||
|
||||
image: FileTypes
|
||||
prompt: str
|
||||
model: Optional[str]
|
||||
model: str | None
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
from typing import Final, Literal, Optional, Union
|
||||
from typing import Literal
|
||||
|
||||
from typing_extensions import NotRequired, TypedDict
|
||||
|
||||
|
|
@ -9,9 +9,9 @@ class CacheControlMessageInjectionPoint(TypedDict):
|
|||
"""Type for message-level injection points."""
|
||||
|
||||
location: Literal["message"]
|
||||
role: Optional[Literal["user", "system", "assistant"]] # Optional: target by role (user, system, assistant)
|
||||
index: Optional[Union[int, str]] # Optional: target by specific index
|
||||
control: Optional[ChatCompletionCachedContent]
|
||||
role: Literal["user", "system", "assistant"] | None # Optional: target by role (user, system, assistant)
|
||||
index: int | str | None # Optional: target by specific index
|
||||
control: ChatCompletionCachedContent | None
|
||||
_litellm_judged: NotRequired[bool] # Internal: written back by litellm once the client cache_control judgment ran
|
||||
|
||||
|
||||
|
|
@ -19,11 +19,8 @@ class CacheControlToolConfigInjectionPoint(TypedDict):
|
|||
"""Type for tool_config-level injection points (Bedrock)."""
|
||||
|
||||
location: Literal["tool_config"]
|
||||
control: Optional[ChatCompletionCachedContent]
|
||||
control: ChatCompletionCachedContent | None
|
||||
_litellm_judged: NotRequired[bool] # Internal: written back by litellm once the client cache_control judgment ran
|
||||
|
||||
|
||||
CacheControlInjectionPoint = Union[
|
||||
CacheControlMessageInjectionPoint,
|
||||
CacheControlToolConfigInjectionPoint,
|
||||
]
|
||||
CacheControlInjectionPoint = CacheControlMessageInjectionPoint | CacheControlToolConfigInjectionPoint
|
||||
|
|
|
|||
|
|
@ -1,17 +1,14 @@
|
|||
import os
|
||||
from datetime import datetime as dt
|
||||
from enum import Enum
|
||||
from typing import Any, Dict, Final, List, Literal, Optional, Set
|
||||
from typing import Any, Final
|
||||
|
||||
from typing_extensions import TypedDict
|
||||
|
||||
|
||||
class ArgillaItem(TypedDict):
|
||||
fields: Dict[str, Any]
|
||||
fields: dict[str, Any]
|
||||
|
||||
|
||||
class ArgillaPayload(TypedDict):
|
||||
items: List[ArgillaItem]
|
||||
items: list[ArgillaItem]
|
||||
|
||||
|
||||
class ArgillaCredentialsObject(TypedDict):
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
from typing import TYPE_CHECKING, Any, Literal, Optional
|
||||
from typing import TYPE_CHECKING, Any, Literal
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
|
@ -9,9 +9,9 @@ else:
|
|||
|
||||
|
||||
class ArizeConfig(BaseModel):
|
||||
space_id: Optional[str] = None
|
||||
space_key: Optional[str] = None
|
||||
api_key: Optional[str] = None
|
||||
space_id: str | None = None
|
||||
space_key: str | None = None
|
||||
api_key: str | None = None
|
||||
protocol: Protocol
|
||||
endpoint: str
|
||||
project_name: Optional[str] = None
|
||||
project_name: str | None = None
|
||||
|
|
|
|||
|
|
@ -1,12 +1,10 @@
|
|||
from typing import TYPE_CHECKING, Literal, Optional
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from .arize import Protocol
|
||||
|
||||
|
||||
class ArizePhoenixConfig(BaseModel):
|
||||
otlp_auth_headers: Optional[str] = None
|
||||
otlp_auth_headers: str | None = None
|
||||
protocol: Protocol
|
||||
endpoint: str
|
||||
project_name: Optional[str] = None
|
||||
project_name: str | None = None
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from typing import Optional
|
||||
|
||||
from litellm.types.integrations.custom_logger import StandardCustomLoggerInitParams
|
||||
|
||||
|
||||
|
|
@ -7,5 +5,3 @@ class AzureSentinelInitParams(StandardCustomLoggerInitParams):
|
|||
"""
|
||||
Params for initializing an Azure Sentinel logger on litellm
|
||||
"""
|
||||
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
from typing import Literal, Optional
|
||||
from typing import Literal
|
||||
|
||||
from typing_extensions import TypedDict
|
||||
|
||||
|
||||
class IntegrationHealthCheckStatus(TypedDict):
|
||||
status: Literal["healthy", "unhealthy"]
|
||||
error_message: Optional[str]
|
||||
error_message: str | None
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
from typing import Any, Dict, Final
|
||||
from typing import Any
|
||||
|
||||
|
||||
class CBFRecord(Dict[str, Any]):
|
||||
class CBFRecord(dict[str, Any]):
|
||||
"""CloudZero Billing Format (CBF) record structure.
|
||||
|
||||
This class represents a CBF record that is created from LiteLLM usage data
|
||||
|
|
@ -29,8 +29,6 @@ class CBFRecord(Dict[str, Any]):
|
|||
- resource/tag:{key}: Various resource tags for dimensions and metrics (Optional[str])
|
||||
"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
# Type alias for better readability in function signatures
|
||||
CBFRecordDict = Dict[str, Any]
|
||||
CBFRecordDict = dict[str, Any]
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Type definitions for Code Interpreter Interception integration.
|
||||
"""
|
||||
|
||||
from typing import List, TypedDict
|
||||
from typing import TypedDict
|
||||
|
||||
|
||||
class CodeInterpreterInterceptionConfig(TypedDict, total=False):
|
||||
|
|
@ -18,5 +18,5 @@ class CodeInterpreterInterceptionConfig(TypedDict, total=False):
|
|||
"""
|
||||
|
||||
enabled: bool
|
||||
enabled_providers: List[str]
|
||||
enabled_providers: list[str]
|
||||
sandbox_tool_name: str
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Type definitions for Compression Interception integration.
|
||||
"""
|
||||
|
||||
from typing import Any, Dict, Literal, Optional, TypedDict
|
||||
from typing import Any, Literal, TypedDict
|
||||
|
||||
|
||||
class CompressionInterceptionConfig(TypedDict, total=False):
|
||||
|
|
@ -22,9 +22,9 @@ class CompressionInterceptionConfig(TypedDict, total=False):
|
|||
|
||||
enabled: bool
|
||||
compression_trigger: int
|
||||
compression_target: Optional[int]
|
||||
embedding_model: Optional[str]
|
||||
embedding_model_params: Optional[Dict[str, Any]]
|
||||
compression_target: int | None
|
||||
embedding_model: str | None
|
||||
embedding_model_params: dict[str, Any] | None
|
||||
|
||||
|
||||
class CompressionSavingsMetadata(TypedDict):
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
from typing import Any, Dict, Final, List, Optional
|
||||
from typing import Any, Final
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
|
@ -28,7 +28,7 @@ class StandardCustomLoggerInitParams(BaseModel):
|
|||
Params for initializing a CustomLogger.
|
||||
"""
|
||||
|
||||
turn_off_message_logging: Optional[bool] = False
|
||||
turn_off_message_logging: bool | None = False
|
||||
|
||||
|
||||
class AgenticLoopRequestPatch(BaseModel):
|
||||
|
|
@ -36,12 +36,12 @@ class AgenticLoopRequestPatch(BaseModel):
|
|||
Patch returned by callbacks to request a follow-up LLM call.
|
||||
"""
|
||||
|
||||
model: Optional[str] = None
|
||||
messages: Optional[List[Dict[str, Any]]] = None
|
||||
tools: Optional[List[Dict[str, Any]]] = None
|
||||
max_tokens: Optional[int] = None
|
||||
optional_params: Dict[str, Any] = Field(default_factory=dict)
|
||||
kwargs: Dict[str, Any] = Field(default_factory=dict)
|
||||
model: str | None = None
|
||||
messages: list[dict[str, Any]] | None = None
|
||||
tools: list[dict[str, Any]] | None = None
|
||||
max_tokens: int | None = None
|
||||
optional_params: dict[str, Any] = Field(default_factory=dict)
|
||||
kwargs: dict[str, Any] = Field(default_factory=dict)
|
||||
|
||||
|
||||
class AgenticLoopPlan(BaseModel):
|
||||
|
|
@ -50,8 +50,8 @@ class AgenticLoopPlan(BaseModel):
|
|||
"""
|
||||
|
||||
run_agentic_loop: bool = False
|
||||
request_patch: Optional[AgenticLoopRequestPatch] = None
|
||||
response_override: Optional[Any] = None
|
||||
request_patch: AgenticLoopRequestPatch | None = None
|
||||
response_override: Any | None = None
|
||||
terminate: bool = False
|
||||
stop_reason: Optional[str] = None
|
||||
metadata: Dict[str, Any] = Field(default_factory=dict)
|
||||
stop_reason: str | None = None
|
||||
metadata: dict[str, Any] = Field(default_factory=dict)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
from enum import Enum
|
||||
from typing import Final, Optional
|
||||
from typing import Final
|
||||
|
||||
from typing_extensions import NotRequired, TypedDict
|
||||
|
||||
|
|
@ -40,12 +40,10 @@ class DatadogInitParams(StandardCustomLoggerInitParams):
|
|||
Params for initializing a DataDog logger on litellm
|
||||
"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class DatadogProxyFailureHookJsonMessage(TypedDict, total=False):
|
||||
exception: str
|
||||
error_class: str
|
||||
status_code: Optional[int]
|
||||
status_code: int | None
|
||||
traceback: str
|
||||
user_api_key_dict: dict
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
from typing import Dict, List, Optional, TypedDict
|
||||
|
||||
from typing import TypedDict
|
||||
|
||||
from litellm.types.integrations.custom_logger import StandardCustomLoggerInitParams
|
||||
|
||||
|
|
@ -9,7 +8,7 @@ class DatadogCostManagementInitParams(StandardCustomLoggerInitParams):
|
|||
Init params for Datadog Cost Management
|
||||
"""
|
||||
|
||||
cost_tag_keys: Optional[List[str]] = None
|
||||
cost_tag_keys: list[str] | None = None
|
||||
|
||||
|
||||
class DatadogFOCUSCostEntry(TypedDict):
|
||||
|
|
@ -24,4 +23,4 @@ class DatadogFOCUSCostEntry(TypedDict):
|
|||
ChargePeriodEnd: str
|
||||
BilledCost: float
|
||||
BillingCurrency: str
|
||||
Tags: Optional[Dict[str, str]]
|
||||
Tags: dict[str, str] | None
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ Payloads for Datadog LLM Observability Service (LLMObs)
|
|||
API Reference: https://docs.datadoghq.com/llm_observability/setup/api/?tab=example#api-standards
|
||||
"""
|
||||
|
||||
from typing import Any, Dict, List, Literal, Optional
|
||||
from typing import Any, Literal
|
||||
|
||||
from typing_extensions import TypedDict
|
||||
|
||||
|
|
@ -12,21 +12,21 @@ from litellm.types.integrations.custom_logger import StandardCustomLoggerInitPar
|
|||
|
||||
|
||||
class InputMeta(TypedDict):
|
||||
messages: List[
|
||||
Dict[str, Any] # changed to fit with tool calls
|
||||
messages: list[
|
||||
dict[str, Any] # changed to fit with tool calls
|
||||
] # Relevant Issue: https://github.com/BerriAI/litellm/issues/9494
|
||||
|
||||
|
||||
class OutputMeta(TypedDict):
|
||||
messages: List[Any]
|
||||
messages: list[Any]
|
||||
|
||||
|
||||
class DDLLMObsError(TypedDict, total=False):
|
||||
"""Error information on the span according to DD LLM Obs API spec"""
|
||||
|
||||
message: str # The error message
|
||||
stack: Optional[str] # The stack trace
|
||||
type: Optional[str] # The error type
|
||||
stack: str | None # The stack trace
|
||||
type: str | None # The error type
|
||||
|
||||
|
||||
class Meta(TypedDict, total=False):
|
||||
|
|
@ -34,8 +34,8 @@ class Meta(TypedDict, total=False):
|
|||
kind: Literal["llm", "tool", "task", "embedding", "retrieval"]
|
||||
input: InputMeta # The span's input information.
|
||||
output: OutputMeta # The span's output information.
|
||||
metadata: Dict[str, Any]
|
||||
error: Optional[DDLLMObsError] # Error information on the span
|
||||
metadata: dict[str, Any]
|
||||
error: DDLLMObsError | None # Error information on the span
|
||||
|
||||
|
||||
class LLMMetrics(TypedDict, total=False):
|
||||
|
|
@ -57,14 +57,14 @@ class LLMObsPayload(TypedDict, total=False):
|
|||
start_ns: int
|
||||
duration: int
|
||||
metrics: LLMMetrics
|
||||
tags: List
|
||||
tags: list
|
||||
status: Literal["ok", "error"] # Error status ("ok" or "error"). Defaults to "ok".
|
||||
|
||||
|
||||
class DDSpanAttributes(TypedDict):
|
||||
ml_app: str
|
||||
tags: List[str]
|
||||
spans: List[LLMObsPayload]
|
||||
tags: list[str]
|
||||
spans: list[LLMObsPayload]
|
||||
|
||||
|
||||
class DDIntakePayload(TypedDict):
|
||||
|
|
@ -77,8 +77,6 @@ class DatadogLLMObsInitParams(StandardCustomLoggerInitParams):
|
|||
Params for initializing a DatadogLLMObs logger on litellm
|
||||
"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class DDLLMObsLatencyMetrics(TypedDict, total=False):
|
||||
time_to_first_token_ms: float
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from typing import List, Optional
|
||||
|
||||
from typing_extensions import TypedDict
|
||||
|
||||
|
||||
|
|
@ -11,10 +9,10 @@ class DatadogMetricPoint(TypedDict):
|
|||
class DatadogMetricSeries(TypedDict, total=False):
|
||||
metric: str
|
||||
type: int # 0=unspecified, 1=count, 2=rate, 3=gauge
|
||||
points: List[DatadogMetricPoint]
|
||||
tags: List[str]
|
||||
interval: Optional[int] # Required for count (type=1) and rate (type=2) metrics
|
||||
points: list[DatadogMetricPoint]
|
||||
tags: list[str]
|
||||
interval: int | None # Required for count (type=1) and rate (type=2) metrics
|
||||
|
||||
|
||||
class DatadogMetricsPayload(TypedDict):
|
||||
series: List[DatadogMetricSeries]
|
||||
series: list[DatadogMetricSeries]
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
from typing import Any, Dict, Final, Optional, TYPE_CHECKING
|
||||
from typing import TYPE_CHECKING, Any, Final
|
||||
|
||||
from typing_extensions import TypedDict
|
||||
|
||||
|
|
@ -22,7 +22,7 @@ class GCSLoggingConfig(TypedDict):
|
|||
|
||||
bucket_name: str
|
||||
vertex_instance: VertexBase
|
||||
path_service_account: Optional[str]
|
||||
path_service_account: str | None
|
||||
|
||||
|
||||
class GCSLogQueueItem(TypedDict):
|
||||
|
|
@ -31,5 +31,5 @@ class GCSLogQueueItem(TypedDict):
|
|||
"""
|
||||
|
||||
payload: StandardLoggingPayload
|
||||
kwargs: Dict[str, Any]
|
||||
response_obj: Optional[Any]
|
||||
kwargs: dict[str, Any]
|
||||
response_obj: Any | None
|
||||
|
|
|
|||
|
|
@ -1,17 +1,15 @@
|
|||
from typing import Optional
|
||||
|
||||
from typing_extensions import TypedDict
|
||||
|
||||
|
||||
class LangfuseLoggingConfig(TypedDict):
|
||||
langfuse_secret: Optional[str]
|
||||
langfuse_public_key: Optional[str]
|
||||
langfuse_host: Optional[str]
|
||||
langfuse_secret: str | None
|
||||
langfuse_public_key: str | None
|
||||
langfuse_host: str | None
|
||||
|
||||
|
||||
class LangfuseUsageDetails(TypedDict):
|
||||
input: Optional[int]
|
||||
output: Optional[int]
|
||||
total: Optional[int]
|
||||
cache_creation_input_tokens: Optional[int]
|
||||
cache_read_input_tokens: Optional[int]
|
||||
input: int | None
|
||||
output: int | None
|
||||
total: int | None
|
||||
cache_creation_input_tokens: int | None
|
||||
cache_read_input_tokens: int | None
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
from enum import Enum
|
||||
from typing import TYPE_CHECKING, Any, Literal, Optional
|
||||
from typing import TYPE_CHECKING, Any, Literal
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
|
@ -10,7 +10,7 @@ else:
|
|||
|
||||
|
||||
class LangfuseOtelConfig(BaseModel):
|
||||
otlp_auth_headers: Optional[str] = None
|
||||
otlp_auth_headers: str | None = None
|
||||
protocol: Protocol = "otlp_http"
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,37 +1,37 @@
|
|||
from dataclasses import dataclass
|
||||
from datetime import datetime
|
||||
from typing import Any, Dict, List, NamedTuple, Optional
|
||||
from typing import Any, NamedTuple
|
||||
|
||||
from pydantic import BaseModel
|
||||
from typing_extensions import TypedDict
|
||||
|
||||
|
||||
class LangsmithInputs(BaseModel):
|
||||
model: Optional[str] = None
|
||||
messages: Optional[List[Any]] = None
|
||||
stream: Optional[bool] = None
|
||||
call_type: Optional[str] = None
|
||||
litellm_call_id: Optional[str] = None
|
||||
completion_start_time: Optional[datetime] = None
|
||||
temperature: Optional[float] = None
|
||||
max_tokens: Optional[int] = None
|
||||
custom_llm_provider: Optional[str] = None
|
||||
input: Optional[List[Any]] = None
|
||||
log_event_type: Optional[str] = None
|
||||
original_response: Optional[Any] = None
|
||||
response_cost: Optional[float] = None
|
||||
model: str | None = None
|
||||
messages: list[Any] | None = None
|
||||
stream: bool | None = None
|
||||
call_type: str | None = None
|
||||
litellm_call_id: str | None = None
|
||||
completion_start_time: datetime | None = None
|
||||
temperature: float | None = None
|
||||
max_tokens: int | None = None
|
||||
custom_llm_provider: str | None = None
|
||||
input: list[Any] | None = None
|
||||
log_event_type: str | None = None
|
||||
original_response: Any | None = None
|
||||
response_cost: float | None = None
|
||||
|
||||
# LiteLLM Virtual Key specific fields
|
||||
user_api_key: Optional[str] = None
|
||||
user_api_key_user_id: Optional[str] = None
|
||||
user_api_key_team_alias: Optional[str] = None
|
||||
user_api_key: str | None = None
|
||||
user_api_key_user_id: str | None = None
|
||||
user_api_key_team_alias: str | None = None
|
||||
|
||||
|
||||
class LangsmithCredentialsObject(TypedDict):
|
||||
LANGSMITH_API_KEY: Optional[str]
|
||||
LANGSMITH_PROJECT: Optional[str]
|
||||
LANGSMITH_API_KEY: str | None
|
||||
LANGSMITH_PROJECT: str | None
|
||||
LANGSMITH_BASE_URL: str
|
||||
LANGSMITH_TENANT_ID: Optional[str]
|
||||
LANGSMITH_TENANT_ID: str | None
|
||||
|
||||
|
||||
class LangsmithQueueObject(TypedDict):
|
||||
|
|
@ -43,7 +43,7 @@ class LangsmithQueueObject(TypedDict):
|
|||
- credentials[LangsmithCredentialsObject] - credentials to use for logging to langsmith
|
||||
"""
|
||||
|
||||
data: Dict
|
||||
data: dict
|
||||
credentials: LangsmithCredentialsObject
|
||||
|
||||
|
||||
|
|
@ -53,7 +53,7 @@ class CredentialsKey(NamedTuple):
|
|||
api_key: str
|
||||
project: str
|
||||
base_url: str
|
||||
tenant_id: Optional[str]
|
||||
tenant_id: str | None
|
||||
|
||||
|
||||
@dataclass
|
||||
|
|
@ -61,4 +61,4 @@ class BatchGroup:
|
|||
"""Groups credentials with their associated queue objects"""
|
||||
|
||||
credentials: LangsmithCredentialsObject
|
||||
queue_objects: List[LangsmithQueueObject]
|
||||
queue_objects: list[LangsmithQueueObject]
|
||||
|
|
|
|||
|
|
@ -5,5 +5,3 @@ class NewRelicInitParams(StandardCustomLoggerInitParams):
|
|||
"""
|
||||
Params for initializing a New Relic logger on litellm
|
||||
"""
|
||||
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
from datetime import datetime
|
||||
from typing import List, Literal, Optional, Union
|
||||
from typing import Literal
|
||||
|
||||
from typing_extensions import TypedDict
|
||||
|
||||
|
|
@ -8,35 +8,35 @@ from litellm.types.utils import StandardLoggingUserAPIKeyMetadata
|
|||
|
||||
class LinkDict(TypedDict, total=False):
|
||||
href: str
|
||||
text: Optional[str]
|
||||
text: str | None
|
||||
|
||||
|
||||
class ImageDict(TypedDict, total=False):
|
||||
src: str
|
||||
href: Optional[str]
|
||||
alt: Optional[str]
|
||||
href: str | None
|
||||
alt: str | None
|
||||
|
||||
|
||||
class PagerDutyPayload(TypedDict, total=False):
|
||||
summary: str
|
||||
timestamp: Optional[str] # ISO 8601 date-time format
|
||||
timestamp: str | None # ISO 8601 date-time format
|
||||
severity: Literal["critical", "warning", "error", "info"]
|
||||
source: str
|
||||
component: Optional[str]
|
||||
group: Optional[str]
|
||||
class_: Optional[str] # Using class_ since 'class' is a reserved keyword
|
||||
custom_details: Optional[dict]
|
||||
component: str | None
|
||||
group: str | None
|
||||
class_: str | None # Using class_ since 'class' is a reserved keyword
|
||||
custom_details: dict | None
|
||||
|
||||
|
||||
class PagerDutyRequestBody(TypedDict, total=False):
|
||||
payload: PagerDutyPayload
|
||||
routing_key: str
|
||||
event_action: Literal["trigger", "acknowledge", "resolve"]
|
||||
dedup_key: Optional[str]
|
||||
client: Optional[str]
|
||||
client_url: Optional[str]
|
||||
links: Optional[List[LinkDict]]
|
||||
images: Optional[List[ImageDict]]
|
||||
dedup_key: str | None
|
||||
client: str | None
|
||||
client_url: str | None
|
||||
links: list[LinkDict] | None
|
||||
images: list[ImageDict] | None
|
||||
|
||||
|
||||
class AlertingConfig(TypedDict, total=False):
|
||||
|
|
@ -61,6 +61,6 @@ class PagerDutyInternalEvent(StandardLoggingUserAPIKeyMetadata, total=False):
|
|||
|
||||
failure_event_type: Literal["failed_response", "hanging_response"]
|
||||
timestamp: datetime
|
||||
error_class: Optional[str]
|
||||
error_code: Optional[str]
|
||||
error_llm_provider: Optional[str]
|
||||
error_class: str | None
|
||||
error_code: str | None
|
||||
error_llm_provider: str | None
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
from typing import Any, Dict, Final, TypedDict
|
||||
from typing import Any, Final, TypedDict
|
||||
|
||||
POSTHOG_MAX_BATCH_SIZE: Final = 100
|
||||
|
||||
|
|
@ -7,7 +7,7 @@ class PostHogEventPayload(TypedDict):
|
|||
"""PostHog event payload structure"""
|
||||
|
||||
event: str # "$ai_generation" or "$ai_embedding"
|
||||
properties: Dict[str, Any]
|
||||
properties: dict[str, Any]
|
||||
distinct_id: str
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
import re
|
||||
from collections.abc import Mapping
|
||||
from dataclasses import MISSING, dataclass, field, fields
|
||||
from enum import Enum
|
||||
from types import MappingProxyType
|
||||
from typing import Any, ClassVar, Dict, Final, List, Literal, Mapping, Optional, Tuple, Union
|
||||
from typing import Any, ClassVar, Final, Literal
|
||||
|
||||
import litellm
|
||||
|
||||
|
|
@ -43,7 +44,7 @@ def _sanitize_prometheus_label_name(label: str) -> str:
|
|||
_PROMETHEUS_LABEL_VALUE_TRANSLATE_V1: Final = str.maketrans("\n", " ", "\r\u2028\u2029")
|
||||
|
||||
|
||||
def _sanitize_prometheus_label_value(value: Optional[Any]) -> Optional[str]:
|
||||
def _sanitize_prometheus_label_value(value: Any | None) -> str | None:
|
||||
"""
|
||||
Same semantics as :func:`_sanitize_prometheus_label_value`, implemented with
|
||||
``str.translate`` plus a single escape pass instead of chained ``replace``.
|
||||
|
|
@ -57,7 +58,7 @@ def _sanitize_prometheus_label_value(value: Optional[Any]) -> Optional[str]:
|
|||
if "\\" not in cleaned and '"' not in cleaned:
|
||||
return cleaned
|
||||
|
||||
parts: Final[List[str]] = []
|
||||
parts: Final[list[str]] = []
|
||||
append: Final = parts.append
|
||||
for ch in cleaned:
|
||||
if ch == "\\":
|
||||
|
|
@ -74,7 +75,7 @@ class MetricValidationError:
|
|||
"""Error for invalid metric name"""
|
||||
|
||||
metric_name: str
|
||||
valid_metrics: Tuple[str, ...]
|
||||
valid_metrics: tuple[str, ...]
|
||||
|
||||
@property
|
||||
def message(self) -> str:
|
||||
|
|
@ -86,8 +87,8 @@ class LabelValidationError:
|
|||
"""Error for invalid labels on a metric"""
|
||||
|
||||
metric_name: str
|
||||
invalid_labels: List[str]
|
||||
valid_labels: List[str]
|
||||
invalid_labels: list[str]
|
||||
valid_labels: list[str]
|
||||
|
||||
@property
|
||||
def message(self) -> str:
|
||||
|
|
@ -98,15 +99,15 @@ class LabelValidationError:
|
|||
class ValidationResults:
|
||||
"""Container for all validation results"""
|
||||
|
||||
metric_errors: List[MetricValidationError]
|
||||
label_errors: List[LabelValidationError]
|
||||
metric_errors: list[MetricValidationError]
|
||||
label_errors: list[LabelValidationError]
|
||||
|
||||
@property
|
||||
def has_errors(self) -> bool:
|
||||
return bool(self.metric_errors or self.label_errors)
|
||||
|
||||
@property
|
||||
def all_error_messages(self) -> List[str]:
|
||||
def all_error_messages(self) -> list[str]:
|
||||
messages: Final = [error.message for error in self.metric_errors]
|
||||
messages.extend([error.message for error in self.label_errors])
|
||||
return messages
|
||||
|
|
@ -333,9 +334,9 @@ class PrometheusMetricLabels:
|
|||
|
||||
# Guardrail metrics - these use custom labels (guardrail_name, status, error_type, hook_type)
|
||||
# which are not part of UserAPIKeyLabelNames
|
||||
litellm_guardrail_latency_seconds: List[str] = []
|
||||
litellm_guardrail_errors_total: List[str] = []
|
||||
litellm_guardrail_requests_total: List[str] = []
|
||||
litellm_guardrail_latency_seconds: list[str] = []
|
||||
litellm_guardrail_errors_total: list[str] = []
|
||||
litellm_guardrail_requests_total: list[str] = []
|
||||
|
||||
litellm_proxy_total_requests_metric = [
|
||||
UserAPIKeyLabelNames.END_USER.value,
|
||||
|
|
@ -681,15 +682,15 @@ class PrometheusMetricLabels:
|
|||
]
|
||||
|
||||
# Buffer monitoring metrics - these typically don't need additional labels
|
||||
litellm_pod_lock_manager_size: List[str] = []
|
||||
litellm_pod_lock_manager_size: list[str] = []
|
||||
|
||||
litellm_in_memory_daily_spend_update_queue_size: List[str] = []
|
||||
litellm_in_memory_daily_spend_update_queue_size: list[str] = []
|
||||
|
||||
litellm_redis_daily_spend_update_queue_size: List[str] = []
|
||||
litellm_redis_daily_spend_update_queue_size: list[str] = []
|
||||
|
||||
litellm_in_memory_spend_update_queue_size: List[str] = []
|
||||
litellm_in_memory_spend_update_queue_size: list[str] = []
|
||||
|
||||
litellm_redis_spend_update_queue_size: List[str] = []
|
||||
litellm_redis_spend_update_queue_size: list[str] = []
|
||||
|
||||
# Cache metrics - track cache hits, misses, and tokens served from cache
|
||||
_cache_metric_labels = [
|
||||
|
|
@ -742,7 +743,7 @@ class PrometheusMetricLabels:
|
|||
|
||||
litellm_managed_batch_created_total = _batch_user_labels
|
||||
|
||||
litellm_managed_file_size_bytes: List[str] = [] # labels: purpose, file_type, model, api_provider, user (custom)
|
||||
litellm_managed_file_size_bytes: list[str] = [] # labels: purpose, file_type, model, api_provider, user (custom)
|
||||
|
||||
litellm_managed_batch_duration_seconds = [
|
||||
UserAPIKeyLabelNames.v1_LITELLM_MODEL_NAME.value,
|
||||
|
|
@ -751,18 +752,18 @@ class PrometheusMetricLabels:
|
|||
|
||||
litellm_managed_file_created_total = _batch_user_labels
|
||||
|
||||
litellm_managed_file_deleted_total: List[str] = [] # only "result" label, added at metric creation
|
||||
litellm_managed_file_deleted_total: list[str] = [] # only "result" label, added at metric creation
|
||||
|
||||
litellm_check_batch_cost_jobs_polled: List[str] = []
|
||||
litellm_check_batch_cost_jobs_polled: list[str] = []
|
||||
|
||||
litellm_check_batch_cost_jobs_processed_total = [
|
||||
UserAPIKeyLabelNames.v1_LITELLM_MODEL_NAME.value,
|
||||
UserAPIKeyLabelNames.API_PROVIDER.value,
|
||||
]
|
||||
|
||||
litellm_check_batch_cost_errors_total: List[str] = [] # label: error_type (custom)
|
||||
litellm_check_batch_cost_errors_total: list[str] = [] # label: error_type (custom)
|
||||
|
||||
litellm_check_batch_cost_last_run_timestamp: List[str] = []
|
||||
litellm_check_batch_cost_last_run_timestamp: list[str] = []
|
||||
|
||||
# MCP tool call metrics
|
||||
litellm_mcp_tool_calls_total: list[str] = [
|
||||
|
|
@ -779,7 +780,7 @@ class PrometheusMetricLabels:
|
|||
litellm_mcp_tool_call_spend_metric: list[str] = list(litellm_mcp_tool_calls_total)
|
||||
|
||||
@staticmethod
|
||||
def get_labels(label_name: DEFINED_PROMETHEUS_METRICS) -> List[str]:
|
||||
def get_labels(label_name: DEFINED_PROMETHEUS_METRICS) -> list[str]:
|
||||
default_labels: Final = getattr(PrometheusMetricLabels, label_name)
|
||||
custom_labels: Final = []
|
||||
|
||||
|
|
@ -836,7 +837,7 @@ class PrometheusMetricLabels:
|
|||
return default_labels + custom_labels
|
||||
|
||||
|
||||
_USER_API_KEY_LABEL_VALUE_INIT_ALIASES: Final[Dict[str, str]] = {
|
||||
_USER_API_KEY_LABEL_VALUE_INIT_ALIASES: Final[dict[str, str]] = {
|
||||
# Some tests / call sites use ``api_key_hash``; Prometheus field is ``hashed_api_key``.
|
||||
"api_key_hash": "hashed_api_key",
|
||||
}
|
||||
|
|
@ -851,39 +852,39 @@ class UserAPIKeyLabelValues:
|
|||
``model_dump()`` is provided for call sites that still expect a Pydantic-like dict.
|
||||
"""
|
||||
|
||||
end_user: Optional[str] = None
|
||||
user: Optional[str] = None
|
||||
user_email: Optional[str] = None
|
||||
user_alias: Optional[str] = None
|
||||
hashed_api_key: Optional[str] = None
|
||||
api_key_alias: Optional[str] = None
|
||||
team: Optional[str] = None
|
||||
team_alias: Optional[str] = None
|
||||
model_group: Optional[str] = None
|
||||
requested_model: Optional[str] = None
|
||||
model: Optional[str] = None
|
||||
litellm_model_name: Optional[str] = None
|
||||
end_user: str | None = None
|
||||
user: str | None = None
|
||||
user_email: str | None = None
|
||||
user_alias: str | None = None
|
||||
hashed_api_key: str | None = None
|
||||
api_key_alias: str | None = None
|
||||
team: str | None = None
|
||||
team_alias: str | None = None
|
||||
model_group: str | None = None
|
||||
requested_model: str | None = None
|
||||
model: str | None = None
|
||||
litellm_model_name: str | None = None
|
||||
# Accept list/tuple at construction time; normalize to tuple in __post_init__.
|
||||
tags: Union[Tuple[str, ...], List[str]] = ()
|
||||
tags: tuple[str, ...] | list[str] = ()
|
||||
custom_metadata_labels: Mapping[str, str] = field(default_factory=dict)
|
||||
model_id: Optional[str] = None
|
||||
api_base: Optional[str] = None
|
||||
api_provider: Optional[str] = None
|
||||
exception_status: Optional[str] = None
|
||||
exception_class: Optional[str] = None
|
||||
rate_limit_category: Optional[str] = None
|
||||
rate_limit_type: Optional[str] = None
|
||||
status_code: Optional[str] = None
|
||||
fallback_model: Optional[str] = None
|
||||
route: Optional[str] = None
|
||||
client_ip: Optional[str] = None
|
||||
user_agent: Optional[str] = None
|
||||
stream: Optional[str] = None
|
||||
org_id: Optional[str] = None
|
||||
org_alias: Optional[str] = None
|
||||
mcp_tool_name: Optional[str] = None
|
||||
mcp_server_name: Optional[str] = None
|
||||
service_tier: Optional[str] = None
|
||||
model_id: str | None = None
|
||||
api_base: str | None = None
|
||||
api_provider: str | None = None
|
||||
exception_status: str | None = None
|
||||
exception_class: str | None = None
|
||||
rate_limit_category: str | None = None
|
||||
rate_limit_type: str | None = None
|
||||
status_code: str | None = None
|
||||
fallback_model: str | None = None
|
||||
route: str | None = None
|
||||
client_ip: str | None = None
|
||||
user_agent: str | None = None
|
||||
stream: str | None = None
|
||||
org_id: str | None = None
|
||||
org_alias: str | None = None
|
||||
mcp_tool_name: str | None = None
|
||||
mcp_server_name: str | None = None
|
||||
service_tier: str | None = None
|
||||
|
||||
# Added for test compatibility.
|
||||
def __init__(self, **kwargs: Any) -> None:
|
||||
|
|
@ -892,7 +893,7 @@ class UserAPIKeyLabelValues:
|
|||
``hashed_api_key``. This supports ``**standard_logging_payload`` in tests.
|
||||
"""
|
||||
field_names: Final = {f.name for f in fields(self)}
|
||||
merged: Final[Dict[str, Any]] = {}
|
||||
merged: Final[dict[str, Any]] = {}
|
||||
for f in fields(self):
|
||||
if f.default_factory is not MISSING:
|
||||
merged[f.name] = f.default_factory()
|
||||
|
|
@ -929,9 +930,9 @@ class UserAPIKeyLabelValues:
|
|||
# stays cheap. (Dataclass default `str()` delegates to `__repr__`.)
|
||||
return ""
|
||||
|
||||
def model_dump(self) -> Dict[str, Any]:
|
||||
def model_dump(self) -> dict[str, Any]:
|
||||
"""Same shape as the former Pydantic ``model_dump()`` (plain dict, list tags)."""
|
||||
d: Final[Dict[str, Any]] = {f.name: getattr(self, f.name) for f in fields(self)}
|
||||
d: Final[dict[str, Any]] = {f.name: getattr(self, f.name) for f in fields(self)}
|
||||
d["tags"] = list(self.tags)
|
||||
d["custom_metadata_labels"] = dict(self.custom_metadata_labels)
|
||||
return d
|
||||
|
|
@ -942,31 +943,31 @@ class PrometheusMetricsConfig:
|
|||
"""Configuration for filtering Prometheus metrics (parsed once from proxy config)."""
|
||||
|
||||
group: str
|
||||
metrics: List[str]
|
||||
include_labels: Optional[List[str]] = None
|
||||
metrics: list[str]
|
||||
include_labels: list[str] | None = None
|
||||
|
||||
|
||||
@dataclass
|
||||
class PrometheusSettings:
|
||||
"""Settings for Prometheus metrics configuration."""
|
||||
|
||||
prometheus_metrics_config: Optional[List[PrometheusMetricsConfig]] = None
|
||||
prometheus_metrics_config: list[PrometheusMetricsConfig] | None = None
|
||||
|
||||
|
||||
class NoOpMetric:
|
||||
"""A no-op metric that has the same interface as prometheus metrics but does nothing"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
def __init__(self, *args, **kwargs) -> None:
|
||||
pass
|
||||
|
||||
def labels(self, *args, **kwargs):
|
||||
return self
|
||||
|
||||
def inc(self, *args, **kwargs):
|
||||
def inc(self, *args, **kwargs) -> None:
|
||||
pass
|
||||
|
||||
def set(self, *args, **kwargs):
|
||||
def set(self, *args, **kwargs) -> None:
|
||||
pass
|
||||
|
||||
def observe(self, *args, **kwargs):
|
||||
def observe(self, *args, **kwargs) -> None:
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
from typing import Any, Dict, List, Literal, Optional, Union
|
||||
from typing import Any, Literal
|
||||
|
||||
from typing_extensions import TypedDict
|
||||
|
||||
|
|
@ -7,14 +7,14 @@ class BedrockKBLocation(TypedDict, total=False):
|
|||
"""Location information for a retrieved document."""
|
||||
|
||||
type: str
|
||||
s3Location: Optional[dict]
|
||||
webLocation: Optional[dict]
|
||||
kendraDocumentLocation: Optional[dict]
|
||||
salesforceLocation: Optional[dict]
|
||||
sharePointLocation: Optional[dict]
|
||||
confluenceLocation: Optional[dict]
|
||||
customDocumentLocation: Optional[dict]
|
||||
sqlLocation: Optional[dict]
|
||||
s3Location: dict | None
|
||||
webLocation: dict | None
|
||||
kendraDocumentLocation: dict | None
|
||||
salesforceLocation: dict | None
|
||||
sharePointLocation: dict | None
|
||||
confluenceLocation: dict | None
|
||||
customDocumentLocation: dict | None
|
||||
sqlLocation: dict | None
|
||||
|
||||
|
||||
class BedrockKBRowValue(TypedDict):
|
||||
|
|
@ -29,26 +29,26 @@ class BedrockKBContent(TypedDict, total=False):
|
|||
"""Content of a retrieved document."""
|
||||
|
||||
type: str
|
||||
text: Optional[str]
|
||||
byteContent: Optional[str]
|
||||
row: Optional[List[BedrockKBRowValue]]
|
||||
text: str | None
|
||||
byteContent: str | None
|
||||
row: list[BedrockKBRowValue] | None
|
||||
|
||||
|
||||
class BedrockKBRetrievalResult(TypedDict, total=False):
|
||||
"""Individual result from a knowledge base retrieval."""
|
||||
|
||||
content: Optional[BedrockKBContent]
|
||||
location: Optional[BedrockKBLocation]
|
||||
score: Optional[float]
|
||||
metadata: Optional[Dict[str, Any]]
|
||||
content: BedrockKBContent | None
|
||||
location: BedrockKBLocation | None
|
||||
score: float | None
|
||||
metadata: dict[str, Any] | None
|
||||
|
||||
|
||||
class BedrockKBResponse(TypedDict, total=False):
|
||||
"""Response from a Bedrock Knowledge Base retrieval request."""
|
||||
|
||||
guardrailAction: Optional[Literal["INTERVENED", "NONE"]]
|
||||
nextToken: Optional[str]
|
||||
retrievalResults: Optional[List[BedrockKBRetrievalResult]]
|
||||
guardrailAction: Literal["INTERVENED", "NONE"] | None
|
||||
nextToken: str | None
|
||||
retrievalResults: list[BedrockKBRetrievalResult] | None
|
||||
|
||||
|
||||
################ Bedrock Knowledge Base Request Types #################
|
||||
|
|
@ -59,80 +59,80 @@ class BedrockKBResponse(TypedDict, total=False):
|
|||
class BedrockKBMetadataAttribute(TypedDict, total=False):
|
||||
"""Metadata attribute configuration for implicit filtering."""
|
||||
|
||||
description: Optional[str]
|
||||
key: Optional[str]
|
||||
type: Optional[str]
|
||||
description: str | None
|
||||
key: str | None
|
||||
type: str | None
|
||||
|
||||
|
||||
class BedrockKBImplicitFilterConfiguration(TypedDict, total=False):
|
||||
"""Configuration for implicit filtering."""
|
||||
|
||||
metadataAttributes: Optional[List[BedrockKBMetadataAttribute]]
|
||||
modelArn: Optional[str]
|
||||
metadataAttributes: list[BedrockKBMetadataAttribute] | None
|
||||
modelArn: str | None
|
||||
|
||||
|
||||
class BedrockKBSelectiveModeConfiguration(TypedDict, total=False):
|
||||
"""Configuration for selective mode in reranking."""
|
||||
|
||||
pass # This can be expanded based on actual requirements
|
||||
# This can be expanded based on actual requirements
|
||||
|
||||
|
||||
class BedrockKBMetadataConfiguration(TypedDict, total=False):
|
||||
"""Metadata configuration for reranking."""
|
||||
|
||||
selectionMode: Optional[str]
|
||||
selectiveModeConfiguration: Optional[BedrockKBSelectiveModeConfiguration]
|
||||
selectionMode: str | None
|
||||
selectiveModeConfiguration: BedrockKBSelectiveModeConfiguration | None
|
||||
|
||||
|
||||
class BedrockKBModelConfiguration(TypedDict, total=False):
|
||||
"""Model configuration for reranking."""
|
||||
|
||||
additionalModelRequestFields: Optional[Dict[str, Any]]
|
||||
modelArn: Optional[str]
|
||||
additionalModelRequestFields: dict[str, Any] | None
|
||||
modelArn: str | None
|
||||
|
||||
|
||||
class BedrockKBRerankingConfiguration(TypedDict, total=False):
|
||||
"""Configuration for reranking in vector search."""
|
||||
|
||||
bedrockRerankingConfiguration: Optional[Dict[str, Any]] # This could be further typed if needed
|
||||
type: Optional[str]
|
||||
bedrockRerankingConfiguration: dict[str, Any] | None # This could be further typed if needed
|
||||
type: str | None
|
||||
|
||||
|
||||
class BedrockKBVectorSearchConfiguration(TypedDict, total=False):
|
||||
"""Configuration for vector search."""
|
||||
|
||||
filter: Optional[Dict[str, Any]]
|
||||
implicitFilterConfiguration: Optional[BedrockKBImplicitFilterConfiguration]
|
||||
numberOfResults: Optional[int]
|
||||
overrideSearchType: Optional[str]
|
||||
rerankingConfiguration: Optional[BedrockKBRerankingConfiguration]
|
||||
filter: dict[str, Any] | None
|
||||
implicitFilterConfiguration: BedrockKBImplicitFilterConfiguration | None
|
||||
numberOfResults: int | None
|
||||
overrideSearchType: str | None
|
||||
rerankingConfiguration: BedrockKBRerankingConfiguration | None
|
||||
|
||||
|
||||
class BedrockKBRetrievalConfiguration(TypedDict, total=False):
|
||||
"""Configuration for retrieval."""
|
||||
|
||||
vectorSearchConfiguration: Optional[BedrockKBVectorSearchConfiguration]
|
||||
vectorSearchConfiguration: BedrockKBVectorSearchConfiguration | None
|
||||
|
||||
|
||||
class BedrockKBRetrievalQuery(TypedDict, total=False):
|
||||
"""Query structure for retrieval."""
|
||||
|
||||
text: Optional[str]
|
||||
text: str | None
|
||||
|
||||
|
||||
class BedrockKBGuardrailConfiguration(TypedDict, total=False):
|
||||
"""Configuration for guardrails."""
|
||||
|
||||
guardrailId: Optional[str]
|
||||
guardrailVersion: Optional[str]
|
||||
guardrailId: str | None
|
||||
guardrailVersion: str | None
|
||||
|
||||
|
||||
class BedrockKBRequest(TypedDict, total=False):
|
||||
"""Complete request structure for Bedrock Knowledge Base retrieval."""
|
||||
|
||||
guardrailConfiguration: Optional[BedrockKBGuardrailConfiguration]
|
||||
nextToken: Optional[str]
|
||||
retrievalConfiguration: Optional[BedrockKBRetrievalConfiguration]
|
||||
guardrailConfiguration: BedrockKBGuardrailConfiguration | None
|
||||
nextToken: str | None
|
||||
retrievalConfiguration: BedrockKBRetrievalConfiguration | None
|
||||
retrievalQuery: BedrockKBRetrievalQuery
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from typing import Dict
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
|
|
@ -8,6 +6,6 @@ class s3BatchLoggingElement(BaseModel):
|
|||
Type of element stored in self.log_queue in S3Logger
|
||||
"""
|
||||
|
||||
payload: Dict
|
||||
payload: dict
|
||||
s3_object_key: str
|
||||
s3_object_download_filename: str
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import os
|
|||
import time
|
||||
from datetime import datetime as dt
|
||||
from enum import Enum
|
||||
from typing import Any, Dict, Final, List, Literal, Optional, Set, Union
|
||||
from typing import Any, Final, Literal, Optional, Union
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
from typing_extensions import TypedDict
|
||||
|
|
@ -18,7 +18,7 @@ HANGING_ALERT_BUFFER_TIME_SECONDS: Final = 60
|
|||
|
||||
|
||||
class BaseOutageModel(TypedDict):
|
||||
alerts: List[int]
|
||||
alerts: list[int]
|
||||
minor_alert_sent: bool
|
||||
major_alert_sent: bool
|
||||
last_updated_at: float
|
||||
|
|
@ -30,7 +30,7 @@ class OutageModel(BaseOutageModel):
|
|||
|
||||
class ProviderRegionOutageModel(BaseOutageModel):
|
||||
provider_region_id: str
|
||||
deployment_ids: Set[str]
|
||||
deployment_ids: set[str]
|
||||
|
||||
|
||||
# we use this for the email header, please send a test email if you change this. verify it looks good on email
|
||||
|
|
@ -106,7 +106,7 @@ class DeploymentMetrics(LiteLLMPydanticObjectBase):
|
|||
failed_request: bool
|
||||
"""did it fail the request?"""
|
||||
|
||||
latency_per_output_token: Optional[float]
|
||||
latency_per_output_token: float | None
|
||||
"""latency/output token of deployment"""
|
||||
|
||||
updated_at: dt
|
||||
|
|
@ -171,7 +171,7 @@ class AlertType(str, Enum):
|
|||
internal_user_deleted = "internal_user_deleted"
|
||||
|
||||
|
||||
DEFAULT_ALERT_TYPES: Final[List[AlertType]] = [
|
||||
DEFAULT_ALERT_TYPES: Final[list[AlertType]] = [
|
||||
# LLM related alerts
|
||||
AlertType.llm_exceptions,
|
||||
AlertType.llm_too_slow,
|
||||
|
|
@ -198,10 +198,10 @@ DEFAULT_ALERT_TYPES: Final[List[AlertType]] = [
|
|||
class HangingRequestData(BaseModel):
|
||||
request_id: str
|
||||
model: str
|
||||
api_base: Optional[str] = None
|
||||
key_alias: Optional[str] = None
|
||||
team_alias: Optional[str] = None
|
||||
alerting_metadata: Optional[dict] = None
|
||||
api_base: str | None = None
|
||||
key_alias: str | None = None
|
||||
team_alias: str | None = None
|
||||
alerting_metadata: dict | None = None
|
||||
created_at: float = Field(default_factory=time.time)
|
||||
alerted: bool = False
|
||||
|
||||
|
|
@ -230,4 +230,4 @@ class DigestEntry(TypedDict):
|
|||
count: int
|
||||
start_time: dt
|
||||
last_time: dt
|
||||
webhook_url: Union[str, List[str]]
|
||||
webhook_url: str | list[str]
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Type definitions for WebSearch Interception integration.
|
||||
"""
|
||||
|
||||
from typing import List, Optional, TypedDict
|
||||
from typing import TypedDict
|
||||
|
||||
|
||||
class WebSearchInterceptionConfig(TypedDict, total=False):
|
||||
|
|
@ -16,8 +16,8 @@ class WebSearchInterceptionConfig(TypedDict, total=False):
|
|||
search_tool_name: "my-perplexity-search"
|
||||
"""
|
||||
|
||||
enabled_providers: List[str]
|
||||
enabled_providers: list[str]
|
||||
"""List of LLM provider names to enable interception for (e.g., ['bedrock', 'vertex_ai'])"""
|
||||
|
||||
search_tool_name: Optional[str]
|
||||
search_tool_name: str | None
|
||||
"""Name of search tool configured in router's search_tools. If None, uses first available."""
|
||||
|
|
|
|||
|
|
@ -38,8 +38,8 @@ from litellm.types.interactions.generated import (
|
|||
Interaction,
|
||||
InteractionCompleted,
|
||||
InteractionCreated,
|
||||
InteractionEvent,
|
||||
InteractionEnvironment,
|
||||
InteractionEvent,
|
||||
InteractionInProgress,
|
||||
InteractionInput,
|
||||
InteractionRequiresAction,
|
||||
|
|
@ -57,11 +57,6 @@ from litellm.types.interactions.generated import (
|
|||
StepDelta,
|
||||
StepStart,
|
||||
StepStop,
|
||||
)
|
||||
from litellm.types.interactions.generated import (
|
||||
Status3 as InteractionStatus, # Main request/response types; Content types; Turn for multi-turn conversations; Tool types; Config types; Usage; Status enum; Events for streaming; Agent configs; Model/Agent options; Response modality; Annotation; LiteLLM types; Backwards compat aliases
|
||||
)
|
||||
from litellm.types.interactions.generated import (
|
||||
TextContent,
|
||||
ThoughtContent,
|
||||
Tool,
|
||||
|
|
@ -73,72 +68,75 @@ from litellm.types.interactions.generated import (
|
|||
Usage,
|
||||
VideoContent,
|
||||
)
|
||||
from litellm.types.interactions.generated import (
|
||||
Status3 as InteractionStatus, # Main request/response types; Content types; Turn for multi-turn conversations; Tool types; Config types; Usage; Status enum; Events for streaming; Agent configs; Model/Agent options; Response modality; Annotation; LiteLLM types; Backwards compat aliases
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
# Generated types
|
||||
"CreateModelInteractionParams",
|
||||
"CreateAgentInteractionParams",
|
||||
"Interaction",
|
||||
"Content",
|
||||
"TextContent",
|
||||
"ImageContent",
|
||||
"AgentOption",
|
||||
"Annotation",
|
||||
"AudioContent",
|
||||
"DocumentContent",
|
||||
"VideoContent",
|
||||
"ThoughtContent",
|
||||
"FunctionCallContent",
|
||||
"FunctionResultContent",
|
||||
"CancelInteractionResult",
|
||||
"CodeExecution",
|
||||
"CodeExecutionCallContent",
|
||||
"CodeExecutionResultContent",
|
||||
"UrlContextCallContent",
|
||||
"UrlContextResultContent",
|
||||
"ComputerUse",
|
||||
"Content",
|
||||
"ContentDelta",
|
||||
"ContentStart",
|
||||
"ContentStop",
|
||||
"CreateAgentInteractionParams",
|
||||
# Generated types
|
||||
"CreateModelInteractionParams",
|
||||
"DeepResearchAgentConfig",
|
||||
"DeleteInteractionResult",
|
||||
"DocumentContent",
|
||||
"DynamicAgentConfig",
|
||||
"ErrorEvent",
|
||||
"FileSearch",
|
||||
"FileSearchResultContent",
|
||||
"Function",
|
||||
"FunctionCallContent",
|
||||
"FunctionResultContent",
|
||||
"GenerationConfig",
|
||||
"GoogleSearch",
|
||||
"GoogleSearchCallContent",
|
||||
"GoogleSearchResultContent",
|
||||
"McpServerToolCallContent",
|
||||
"McpServerToolResultContent",
|
||||
"FileSearchResultContent",
|
||||
"Turn",
|
||||
"Tool",
|
||||
"Function",
|
||||
"GoogleSearch",
|
||||
"CodeExecution",
|
||||
"UrlContext",
|
||||
"ComputerUse",
|
||||
"McpServer",
|
||||
"FileSearch",
|
||||
"GenerationConfig",
|
||||
"ToolChoiceConfig",
|
||||
"Usage",
|
||||
"InteractionStatus",
|
||||
"InteractionEvent",
|
||||
"InteractionSseEvent",
|
||||
"ContentStart",
|
||||
"ContentDelta",
|
||||
"ContentStop",
|
||||
"ErrorEvent",
|
||||
"DynamicAgentConfig",
|
||||
"DeepResearchAgentConfig",
|
||||
"ModelOption",
|
||||
"AgentOption",
|
||||
"ResponseModality",
|
||||
"Annotation",
|
||||
# New schema SSE event types (Api-Revision: 2026-05-20)
|
||||
"StepStart",
|
||||
"StepDelta",
|
||||
"StepStop",
|
||||
"InteractionCreated",
|
||||
"InteractionInProgress",
|
||||
"ImageContent",
|
||||
"Interaction",
|
||||
"InteractionCompleted",
|
||||
"InteractionRequiresAction",
|
||||
"InteractionCreated",
|
||||
# LiteLLM types
|
||||
"InteractionEnvironment",
|
||||
"InteractionEvent",
|
||||
"InteractionInProgress",
|
||||
"InteractionInput",
|
||||
"InteractionsAPIResponse",
|
||||
"InteractionsAPIStreamingResponse",
|
||||
"DeleteInteractionResult",
|
||||
"CancelInteractionResult",
|
||||
"InteractionsAPIOptionalRequestParams",
|
||||
"InteractionRequiresAction",
|
||||
"InteractionSseEvent",
|
||||
"InteractionStatus",
|
||||
# Backwards compat
|
||||
"InteractionTool",
|
||||
"InteractionToolChoiceConfig",
|
||||
"InteractionsAPIOptionalRequestParams",
|
||||
"InteractionsAPIResponse",
|
||||
"InteractionsAPIStreamingResponse",
|
||||
"McpServer",
|
||||
"McpServerToolCallContent",
|
||||
"McpServerToolResultContent",
|
||||
"ModelOption",
|
||||
"ResponseModality",
|
||||
"StepDelta",
|
||||
# New schema SSE event types (Api-Revision: 2026-05-20)
|
||||
"StepStart",
|
||||
"StepStop",
|
||||
"TextContent",
|
||||
"ThoughtContent",
|
||||
"Tool",
|
||||
"ToolChoiceConfig",
|
||||
"Turn",
|
||||
"UrlContext",
|
||||
"UrlContextCallContent",
|
||||
"UrlContextResultContent",
|
||||
"Usage",
|
||||
"VideoContent",
|
||||
]
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,5 +1,3 @@
|
|||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from typing_extensions import TypedDict
|
||||
|
||||
from ..utils import CompletionTokensDetails, PromptTokensDetailsWrapper, ServerToolUse
|
||||
|
|
@ -8,10 +6,10 @@ from ..utils import CompletionTokensDetails, PromptTokensDetailsWrapper, ServerT
|
|||
class UsagePerChunk(TypedDict):
|
||||
prompt_tokens: int
|
||||
completion_tokens: int
|
||||
cache_creation_input_tokens: Optional[int]
|
||||
cache_read_input_tokens: Optional[int]
|
||||
server_tool_use: Optional[ServerToolUse]
|
||||
web_search_requests: Optional[int]
|
||||
completion_tokens_details: Optional[CompletionTokensDetails]
|
||||
prompt_tokens_details: Optional[PromptTokensDetailsWrapper]
|
||||
cost: Optional[float]
|
||||
cache_creation_input_tokens: int | None
|
||||
cache_read_input_tokens: int | None
|
||||
server_tool_use: ServerToolUse | None
|
||||
web_search_requests: int | None
|
||||
completion_tokens_details: CompletionTokensDetails | None
|
||||
prompt_tokens_details: PromptTokensDetailsWrapper | None
|
||||
cost: float | None
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from typing import Dict, Optional, Union
|
||||
|
||||
from typing_extensions import TypedDict
|
||||
|
||||
|
||||
|
|
@ -19,11 +17,11 @@ class AimlImageGenerationRequestParams(TypedDict, total=False):
|
|||
|
||||
model: str # Required: flux-pro/v1.1
|
||||
prompt: str # Required: Text prompt (max 4000 chars)
|
||||
image_size: Union[
|
||||
AimlImageSize, str
|
||||
] # Custom size or predefined: square_hd, square, portrait_4_3, portrait_16_9, landscape_4_3, landscape_16_9
|
||||
safety_tolerance: Optional[str] # 1-6, default 2 (1=strict, 6=permissive)
|
||||
output_format: Optional[str] # jpeg or png, default jpeg
|
||||
num_images: Optional[int] # 1-4, default 1
|
||||
seed: Optional[int] # Min 1, for reproducibility
|
||||
enable_safety_checker: Optional[bool] # Default true
|
||||
image_size: (
|
||||
AimlImageSize | str
|
||||
) # Custom size or predefined: square_hd, square, portrait_4_3, portrait_16_9, landscape_4_3, landscape_16_9
|
||||
safety_tolerance: str | None # 1-6, default 2 (1=strict, 6=permissive)
|
||||
output_format: str | None # jpeg or png, default jpeg
|
||||
num_images: int | None # 1-4, default 1
|
||||
seed: int | None # Min 1, for reproducibility
|
||||
enable_safety_checker: bool | None # Default true
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
from collections.abc import Iterable
|
||||
from enum import Enum
|
||||
from typing import Any, Dict, Final, Iterable, List, Optional, Union
|
||||
from typing import Any, Final, Literal
|
||||
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
from typing_extensions import Literal, NotRequired, Required, TypedDict
|
||||
from typing_extensions import NotRequired, Required, TypedDict
|
||||
|
||||
from .openai import (
|
||||
ChatCompletionCachedContent,
|
||||
|
|
@ -20,12 +21,12 @@ class AnthropicMessagesToolChoice(TypedDict, total=False):
|
|||
AnthropicInputSchema = TypedDict(
|
||||
"AnthropicInputSchema",
|
||||
{
|
||||
"type": Optional[str],
|
||||
"properties": Optional[dict],
|
||||
"additionalProperties": Optional[bool],
|
||||
"required": Optional[List[str]],
|
||||
"$defs": Optional[Dict],
|
||||
"strict": Optional[bool],
|
||||
"type": str | None,
|
||||
"properties": dict | None,
|
||||
"additionalProperties": bool | None,
|
||||
"required": list[str] | None,
|
||||
"$defs": dict | None,
|
||||
"strict": bool | None,
|
||||
},
|
||||
total=False,
|
||||
)
|
||||
|
|
@ -46,67 +47,67 @@ class AnthropicOutputConfig(TypedDict, total=False):
|
|||
class AnthropicMessagesTool(TypedDict, total=False):
|
||||
name: Required[str]
|
||||
description: str
|
||||
input_schema: Optional[AnthropicInputSchema]
|
||||
input_schema: AnthropicInputSchema | None
|
||||
type: Literal["custom"]
|
||||
cache_control: Optional[Union[dict, ChatCompletionCachedContent]]
|
||||
cache_control: dict | ChatCompletionCachedContent | None
|
||||
defer_loading: bool
|
||||
allowed_callers: Optional[List[str]]
|
||||
input_examples: Optional[List[Dict[str, Any]]]
|
||||
allowed_callers: list[str] | None
|
||||
input_examples: list[dict[str, Any]] | None
|
||||
|
||||
|
||||
class AnthropicComputerTool(TypedDict, total=False):
|
||||
display_width_px: Required[int]
|
||||
display_height_px: Required[int]
|
||||
display_number: int
|
||||
cache_control: Optional[Union[dict, ChatCompletionCachedContent]]
|
||||
cache_control: dict | ChatCompletionCachedContent | None
|
||||
type: Required[str]
|
||||
name: Required[str]
|
||||
|
||||
|
||||
class AnthropicWebSearchUserLocation(TypedDict, total=False):
|
||||
city: Optional[str]
|
||||
country: Optional[str]
|
||||
region: Optional[str]
|
||||
timezone: Optional[str]
|
||||
city: str | None
|
||||
country: str | None
|
||||
region: str | None
|
||||
timezone: str | None
|
||||
type: Required[Literal["approximate"]]
|
||||
|
||||
|
||||
class AnthropicWebSearchTool(TypedDict, total=False):
|
||||
name: Required[Literal["web_search"]]
|
||||
type: Required[str]
|
||||
cache_control: Optional[Union[dict, ChatCompletionCachedContent]]
|
||||
max_uses: Optional[int]
|
||||
user_location: Optional[AnthropicWebSearchUserLocation]
|
||||
defer_loading: Optional[bool]
|
||||
allowed_callers: Optional[List[str]]
|
||||
input_examples: Optional[List[Dict[str, Any]]]
|
||||
cache_control: dict | ChatCompletionCachedContent | None
|
||||
max_uses: int | None
|
||||
user_location: AnthropicWebSearchUserLocation | None
|
||||
defer_loading: bool | None
|
||||
allowed_callers: list[str] | None
|
||||
input_examples: list[dict[str, Any]] | None
|
||||
|
||||
|
||||
class AnthropicHostedTools(TypedDict, total=False): # for bash_tool and text_editor
|
||||
type: Required[str]
|
||||
name: Required[str]
|
||||
cache_control: Optional[Union[dict, ChatCompletionCachedContent]]
|
||||
defer_loading: Optional[bool]
|
||||
allowed_callers: Optional[List[str]]
|
||||
input_examples: Optional[List[Dict[str, Any]]]
|
||||
cache_control: dict | ChatCompletionCachedContent | None
|
||||
defer_loading: bool | None
|
||||
allowed_callers: list[str] | None
|
||||
input_examples: list[dict[str, Any]] | None
|
||||
|
||||
|
||||
class AnthropicCodeExecutionTool(TypedDict, total=False):
|
||||
type: Required[str]
|
||||
name: Required[Literal["code_execution"]]
|
||||
cache_control: Optional[Union[dict, ChatCompletionCachedContent]]
|
||||
defer_loading: Optional[bool]
|
||||
allowed_callers: Optional[List[str]]
|
||||
input_examples: Optional[List[Dict[str, Any]]]
|
||||
cache_control: dict | ChatCompletionCachedContent | None
|
||||
defer_loading: bool | None
|
||||
allowed_callers: list[str] | None
|
||||
input_examples: list[dict[str, Any]] | None
|
||||
|
||||
|
||||
class AnthropicMemoryTool(TypedDict, total=False):
|
||||
type: Required[str]
|
||||
name: Required[Literal["memory"]]
|
||||
cache_control: Optional[Union[dict, ChatCompletionCachedContent]]
|
||||
defer_loading: Optional[bool]
|
||||
allowed_callers: Optional[List[str]]
|
||||
input_examples: Optional[List[Dict[str, Any]]]
|
||||
cache_control: dict | ChatCompletionCachedContent | None
|
||||
defer_loading: bool | None
|
||||
allowed_callers: list[str] | None
|
||||
input_examples: list[dict[str, Any]] | None
|
||||
|
||||
|
||||
class AnthropicToolSearchToolRegex(TypedDict, total=False):
|
||||
|
|
@ -121,13 +122,13 @@ class AnthropicToolSearchToolBM25(TypedDict, total=False):
|
|||
|
||||
type: Required[Literal["tool_search_tool_bm25_20251119"]]
|
||||
name: Required[str]
|
||||
cache_control: Optional[Union[dict, ChatCompletionCachedContent]]
|
||||
defer_loading: Optional[bool]
|
||||
allowed_callers: Optional[List[str]]
|
||||
input_examples: Optional[List[Dict[str, Any]]]
|
||||
cache_control: dict | ChatCompletionCachedContent | None
|
||||
defer_loading: bool | None
|
||||
allowed_callers: list[str] | None
|
||||
input_examples: list[dict[str, Any]] | None
|
||||
|
||||
|
||||
ANTHROPIC_ADVISOR_TOOL_TYPE: Final[Literal["advisor_20260301"]] = "advisor_20260301"
|
||||
ANTHROPIC_ADVISOR_TOOL_TYPE: Final = "advisor_20260301"
|
||||
|
||||
|
||||
class AnthropicAdvisorTool(TypedDict, total=False):
|
||||
|
|
@ -136,8 +137,8 @@ class AnthropicAdvisorTool(TypedDict, total=False):
|
|||
type: Required[Literal["advisor_20260301"]]
|
||||
name: Required[Literal["advisor"]]
|
||||
model: Required[str]
|
||||
max_uses: Optional[int]
|
||||
caching: Optional[dict]
|
||||
max_uses: int | None
|
||||
caching: dict | None
|
||||
|
||||
|
||||
class ToolReference(TypedDict, total=False):
|
||||
|
|
@ -160,31 +161,31 @@ class CodeExecutionToolCaller(TypedDict, total=False):
|
|||
tool_id: Required[str] # ID of the code execution tool that made the call
|
||||
|
||||
|
||||
ToolCaller = Union[DirectToolCaller, CodeExecutionToolCaller]
|
||||
ToolCaller = DirectToolCaller | CodeExecutionToolCaller
|
||||
|
||||
|
||||
class AnthropicContainer(TypedDict, total=False):
|
||||
"""Container metadata for code execution."""
|
||||
|
||||
id: Required[str]
|
||||
expires_at: Optional[str] # ISO 8601 timestamp
|
||||
expires_at: str | None # ISO 8601 timestamp
|
||||
|
||||
|
||||
AllAnthropicToolsValues = Union[
|
||||
AnthropicComputerTool,
|
||||
AnthropicHostedTools,
|
||||
AnthropicMessagesTool,
|
||||
AnthropicWebSearchTool,
|
||||
AnthropicCodeExecutionTool,
|
||||
AnthropicMemoryTool,
|
||||
AnthropicToolSearchToolRegex,
|
||||
AnthropicToolSearchToolBM25,
|
||||
AnthropicAdvisorTool,
|
||||
]
|
||||
AllAnthropicToolsValues = (
|
||||
AnthropicComputerTool
|
||||
| AnthropicHostedTools
|
||||
| AnthropicMessagesTool
|
||||
| AnthropicWebSearchTool
|
||||
| AnthropicCodeExecutionTool
|
||||
| AnthropicMemoryTool
|
||||
| AnthropicToolSearchToolRegex
|
||||
| AnthropicToolSearchToolBM25
|
||||
| AnthropicAdvisorTool
|
||||
)
|
||||
|
||||
|
||||
class AnthropicMcpServerToolConfiguration(TypedDict, total=False):
|
||||
allowed_tools: Optional[List[str]]
|
||||
allowed_tools: list[str] | None
|
||||
|
||||
|
||||
class AnthropicMcpServerTool(TypedDict, total=False):
|
||||
|
|
@ -198,7 +199,7 @@ class AnthropicMcpServerTool(TypedDict, total=False):
|
|||
class AnthropicMessagesTextParam(TypedDict, total=False):
|
||||
type: Required[Literal["text"]]
|
||||
text: Required[str]
|
||||
cache_control: Optional[Union[dict, ChatCompletionCachedContent]]
|
||||
cache_control: dict | ChatCompletionCachedContent | None
|
||||
|
||||
|
||||
class AnthropicMessagesToolUseParam(TypedDict, total=False):
|
||||
|
|
@ -206,20 +207,20 @@ class AnthropicMessagesToolUseParam(TypedDict, total=False):
|
|||
id: str
|
||||
name: str
|
||||
input: dict
|
||||
cache_control: Optional[Union[dict, ChatCompletionCachedContent]]
|
||||
caller: Optional[ToolCaller]
|
||||
cache_control: dict | ChatCompletionCachedContent | None
|
||||
caller: ToolCaller | None
|
||||
|
||||
|
||||
AnthropicMessagesAssistantMessageValues = Union[
|
||||
AnthropicMessagesTextParam,
|
||||
AnthropicMessagesToolUseParam,
|
||||
ChatCompletionThinkingBlock,
|
||||
ChatCompletionRedactedThinkingBlock,
|
||||
]
|
||||
AnthropicMessagesAssistantMessageValues = (
|
||||
AnthropicMessagesTextParam
|
||||
| AnthropicMessagesToolUseParam
|
||||
| ChatCompletionThinkingBlock
|
||||
| ChatCompletionRedactedThinkingBlock
|
||||
)
|
||||
|
||||
|
||||
class AnthopicMessagesAssistantMessageParam(TypedDict, total=False):
|
||||
content: Required[Union[str, Iterable[AnthropicMessagesAssistantMessageValues]]]
|
||||
content: Required[str | Iterable[AnthropicMessagesAssistantMessageValues]]
|
||||
"""The contents of the system message."""
|
||||
|
||||
role: Required[Literal["assistant"]]
|
||||
|
|
@ -252,19 +253,13 @@ class AnthropicContentParamSourceFileId(TypedDict):
|
|||
class AnthropicMessagesContainerUploadParam(TypedDict, total=False):
|
||||
type: Required[Literal["container_upload"]]
|
||||
file_id: str
|
||||
cache_control: Optional[Union[dict, ChatCompletionCachedContent]]
|
||||
cache_control: dict | ChatCompletionCachedContent | None
|
||||
|
||||
|
||||
class AnthropicMessagesImageParam(TypedDict, total=False):
|
||||
type: Required[Literal["image"]]
|
||||
source: Required[
|
||||
Union[
|
||||
AnthropicContentParamSource,
|
||||
AnthropicContentParamSourceFileId,
|
||||
AnthropicContentParamSourceUrl,
|
||||
]
|
||||
]
|
||||
cache_control: Optional[Union[dict, ChatCompletionCachedContent]]
|
||||
source: Required[AnthropicContentParamSource | AnthropicContentParamSourceFileId | AnthropicContentParamSourceUrl]
|
||||
cache_control: dict | ChatCompletionCachedContent | None
|
||||
|
||||
|
||||
class CitationsObject(TypedDict):
|
||||
|
|
@ -280,7 +275,7 @@ class AnthropicCitationPageLocation(TypedDict, total=False):
|
|||
type: Literal["page_location"]
|
||||
cited_text: str # The exact text being cited (not counted towards output tokens)
|
||||
document_index: int # Index referencing the cited document
|
||||
document_title: Optional[str] # Title of the cited document
|
||||
document_title: str | None # Title of the cited document
|
||||
start_page_number: int # 1-indexed starting page
|
||||
end_page_number: int # Exclusive ending page
|
||||
|
||||
|
|
@ -294,65 +289,53 @@ class AnthropicCitationCharLocation(TypedDict, total=False):
|
|||
type: Literal["char_location"]
|
||||
cited_text: str # The exact text being cited (not counted towards output tokens)
|
||||
document_index: int # Index referencing the cited document
|
||||
document_title: Optional[str] # Title of the cited document
|
||||
document_title: str | None # Title of the cited document
|
||||
start_char_index: int # Starting character index for the citation
|
||||
end_char_index: int # Ending character index for the citation
|
||||
|
||||
|
||||
# Union type for all citation formats
|
||||
AnthropicCitation = Union[AnthropicCitationPageLocation, AnthropicCitationCharLocation]
|
||||
AnthropicCitation = AnthropicCitationPageLocation | AnthropicCitationCharLocation
|
||||
|
||||
|
||||
class AnthropicMessagesDocumentParam(TypedDict, total=False):
|
||||
type: Required[Literal["document"]]
|
||||
source: Required[
|
||||
Union[
|
||||
AnthropicContentParamSource,
|
||||
AnthropicContentParamSourceFileId,
|
||||
AnthropicContentParamSourceUrl,
|
||||
]
|
||||
]
|
||||
cache_control: Optional[Union[dict, ChatCompletionCachedContent]]
|
||||
source: Required[AnthropicContentParamSource | AnthropicContentParamSourceFileId | AnthropicContentParamSourceUrl]
|
||||
cache_control: dict | ChatCompletionCachedContent | None
|
||||
title: str
|
||||
context: str
|
||||
citations: Optional[CitationsObject]
|
||||
citations: CitationsObject | None
|
||||
|
||||
|
||||
class AnthropicMessagesToolResultContent(TypedDict, total=False):
|
||||
type: Required[Literal["text"]]
|
||||
text: Required[str]
|
||||
cache_control: Optional[Union[dict, ChatCompletionCachedContent]]
|
||||
cache_control: dict | ChatCompletionCachedContent | None
|
||||
|
||||
|
||||
class AnthropicMessagesToolResultParam(TypedDict, total=False):
|
||||
type: Required[Literal["tool_result"]]
|
||||
tool_use_id: Required[str]
|
||||
is_error: bool
|
||||
content: Union[
|
||||
str,
|
||||
Iterable[
|
||||
Union[
|
||||
AnthropicMessagesToolResultContent,
|
||||
AnthropicMessagesImageParam,
|
||||
AnthropicMessagesDocumentParam,
|
||||
]
|
||||
],
|
||||
]
|
||||
cache_control: Optional[Union[dict, ChatCompletionCachedContent]]
|
||||
content: (
|
||||
str
|
||||
| Iterable[AnthropicMessagesToolResultContent | AnthropicMessagesImageParam | AnthropicMessagesDocumentParam]
|
||||
)
|
||||
cache_control: dict | ChatCompletionCachedContent | None
|
||||
|
||||
|
||||
AnthropicMessagesUserMessageValues = Union[
|
||||
AnthropicMessagesTextParam,
|
||||
AnthropicMessagesImageParam,
|
||||
AnthropicMessagesToolResultParam,
|
||||
AnthropicMessagesDocumentParam,
|
||||
AnthropicMessagesContainerUploadParam,
|
||||
]
|
||||
AnthropicMessagesUserMessageValues = (
|
||||
AnthropicMessagesTextParam
|
||||
| AnthropicMessagesImageParam
|
||||
| AnthropicMessagesToolResultParam
|
||||
| AnthropicMessagesDocumentParam
|
||||
| AnthropicMessagesContainerUploadParam
|
||||
)
|
||||
|
||||
|
||||
class AnthropicMessagesUserMessageParam(TypedDict, total=False):
|
||||
role: Required[Literal["user"]]
|
||||
content: Required[Union[str, Iterable[AnthropicMessagesUserMessageValues]]]
|
||||
content: Required[str | Iterable[AnthropicMessagesUserMessageValues]]
|
||||
|
||||
|
||||
class AnthropicMetadata(TypedDict, total=False):
|
||||
|
|
@ -362,38 +345,38 @@ class AnthropicMetadata(TypedDict, total=False):
|
|||
class AnthropicSystemMessageContent(TypedDict, total=False):
|
||||
type: str
|
||||
text: str
|
||||
cache_control: Optional[Union[dict, ChatCompletionCachedContent]]
|
||||
cache_control: dict | ChatCompletionCachedContent | None
|
||||
|
||||
|
||||
AllAnthropicMessageValues = Union[AnthropicMessagesUserMessageParam, AnthopicMessagesAssistantMessageParam]
|
||||
AllAnthropicMessageValues = AnthropicMessagesUserMessageParam | AnthopicMessagesAssistantMessageParam
|
||||
|
||||
|
||||
class AnthropicMessagesRequestOptionalParams(TypedDict, total=False):
|
||||
max_tokens: Optional[int]
|
||||
metadata: Optional[Union[AnthropicMetadata, Dict]]
|
||||
stop_sequences: Optional[List[str]]
|
||||
stream: Optional[bool]
|
||||
system: Optional[Union[str, List]]
|
||||
temperature: Optional[float]
|
||||
thinking: Optional[Dict]
|
||||
tool_choice: Optional[Union[AnthropicMessagesToolChoice, Dict]]
|
||||
tools: Optional[List[Union[AllAnthropicToolsValues, Dict]]]
|
||||
top_k: Optional[int]
|
||||
inference_geo: Optional[str]
|
||||
top_p: Optional[float]
|
||||
mcp_servers: Optional[List[AnthropicMcpServerTool]]
|
||||
context_management: Optional[Dict[str, Any]]
|
||||
container: Optional[Dict[str, Any]] # Container config with skills for code execution
|
||||
output_format: Optional[AnthropicOutputSchema] # Structured outputs support
|
||||
speed: Optional[str] # Fast mode support for Opus models
|
||||
output_config: Optional[AnthropicOutputConfig] # Configuration for Claude's output behavior
|
||||
cache_control: Optional[Dict[str, Any]] # Automatic prompt caching
|
||||
reasoning_effort: Optional[str]
|
||||
max_tokens: int | None
|
||||
metadata: AnthropicMetadata | dict | None
|
||||
stop_sequences: list[str] | None
|
||||
stream: bool | None
|
||||
system: str | list | None
|
||||
temperature: float | None
|
||||
thinking: dict | None
|
||||
tool_choice: AnthropicMessagesToolChoice | dict | None
|
||||
tools: list[AllAnthropicToolsValues | dict] | None
|
||||
top_k: int | None
|
||||
inference_geo: str | None
|
||||
top_p: float | None
|
||||
mcp_servers: list[AnthropicMcpServerTool] | None
|
||||
context_management: dict[str, Any] | None
|
||||
container: dict[str, Any] | None # Container config with skills for code execution
|
||||
output_format: AnthropicOutputSchema | None # Structured outputs support
|
||||
speed: str | None # Fast mode support for Opus models
|
||||
output_config: AnthropicOutputConfig | None # Configuration for Claude's output behavior
|
||||
cache_control: dict[str, Any] | None # Automatic prompt caching
|
||||
reasoning_effort: str | None
|
||||
|
||||
|
||||
class AnthropicMessagesRequest(AnthropicMessagesRequestOptionalParams, total=False):
|
||||
model: Required[str]
|
||||
messages: Required[Union[List[AllAnthropicMessageValues], List[Dict]]]
|
||||
messages: Required[list[AllAnthropicMessageValues] | list[dict]]
|
||||
# litellm param - used for tracking litellm proxy metadata in the request
|
||||
litellm_metadata: dict
|
||||
|
||||
|
|
@ -445,13 +428,13 @@ StreamingContentBlockDeltaType = Literal["text_delta", "input_json_delta", "thin
|
|||
class ContentBlockDelta(TypedDict):
|
||||
type: Literal["content_block_delta"]
|
||||
index: int
|
||||
delta: Union[
|
||||
ContentTextBlockDelta,
|
||||
ContentJsonBlockDelta,
|
||||
ContentCitationsBlockDelta,
|
||||
ContentThinkingBlockDelta,
|
||||
ContentThinkingSignatureBlockDelta,
|
||||
]
|
||||
delta: (
|
||||
ContentTextBlockDelta
|
||||
| ContentJsonBlockDelta
|
||||
| ContentCitationsBlockDelta
|
||||
| ContentThinkingBlockDelta
|
||||
| ContentThinkingSignatureBlockDelta
|
||||
)
|
||||
|
||||
|
||||
class ContentBlockStop(TypedDict):
|
||||
|
|
@ -471,7 +454,7 @@ class ToolUseBlock(TypedDict):
|
|||
name: str
|
||||
|
||||
type: Literal["tool_use"]
|
||||
caller: Optional[ToolCaller]
|
||||
caller: ToolCaller | None
|
||||
|
||||
|
||||
class TextBlock(TypedDict):
|
||||
|
|
@ -494,13 +477,13 @@ class ContentBlockStartText(TypedDict):
|
|||
content_block: TextBlock
|
||||
|
||||
|
||||
ContentBlockContentBlockDict = Union[ToolUseBlock, TextBlock, ChatCompletionThinkingBlock]
|
||||
ContentBlockContentBlockDict = ToolUseBlock | TextBlock | ChatCompletionThinkingBlock
|
||||
|
||||
ContentBlockStart = Union[ContentBlockStartToolUse, ContentBlockStartText]
|
||||
ContentBlockStart = ContentBlockStartToolUse | ContentBlockStartText
|
||||
|
||||
|
||||
class MessageDelta(TypedDict, total=False):
|
||||
stop_reason: Optional[str]
|
||||
stop_reason: str | None
|
||||
|
||||
|
||||
class UsageDelta(TypedDict, total=False):
|
||||
|
|
@ -521,20 +504,20 @@ class AppliedEdit(TypedDict, total=False):
|
|||
summary_input_tokens: int
|
||||
summary_output_tokens: int
|
||||
error: str
|
||||
warnings: List[str]
|
||||
warnings: list[str]
|
||||
|
||||
|
||||
class ContextManagementResponse(TypedDict, total=False):
|
||||
"""Response ``context_management`` with ``applied_edits``."""
|
||||
|
||||
applied_edits: List[AppliedEdit]
|
||||
applied_edits: list[AppliedEdit]
|
||||
|
||||
|
||||
class CompactionBlock(TypedDict, total=False):
|
||||
"""Synthesized ``compaction`` content block (compact_20260112)."""
|
||||
|
||||
type: Required[Literal["compaction"]]
|
||||
content: Optional[str]
|
||||
content: str | None
|
||||
|
||||
|
||||
class UsageIteration(TypedDict, total=False):
|
||||
|
|
@ -562,9 +545,9 @@ class MessageChunk(TypedDict, total=False):
|
|||
type: str
|
||||
role: str
|
||||
model: str
|
||||
content: List
|
||||
stop_reason: Optional[str]
|
||||
stop_sequence: Optional[str]
|
||||
content: list
|
||||
stop_reason: str | None
|
||||
stop_sequence: str | None
|
||||
usage: UsageDelta
|
||||
|
||||
|
||||
|
|
@ -603,7 +586,7 @@ class AnthropicResponseContentBlockToolUse(BaseModel):
|
|||
id: str
|
||||
name: str
|
||||
input: dict
|
||||
provider_specific_fields: Optional[Dict[str, Any]] = None
|
||||
provider_specific_fields: dict[str, Any] | None = None
|
||||
|
||||
model_config = ConfigDict(extra="allow") # Allow provider_specific_fields
|
||||
|
||||
|
|
@ -611,7 +594,7 @@ class AnthropicResponseContentBlockToolUse(BaseModel):
|
|||
class AnthropicResponseContentBlockThinking(BaseModel):
|
||||
type: Literal["thinking"]
|
||||
thinking: str
|
||||
signature: Optional[str]
|
||||
signature: str | None
|
||||
|
||||
|
||||
class AnthropicResponseContentBlockRedactedThinking(BaseModel):
|
||||
|
|
@ -639,23 +622,21 @@ class AnthropicResponse(BaseModel):
|
|||
role: Literal["assistant"]
|
||||
"""Conversational role of the generated message. This will always be "assistant"."""
|
||||
|
||||
content: List[
|
||||
Union[
|
||||
AnthropicResponseContentBlockText,
|
||||
AnthropicResponseContentBlockToolUse,
|
||||
AnthropicResponseContentBlockThinking,
|
||||
AnthropicResponseContentBlockRedactedThinking,
|
||||
]
|
||||
content: list[
|
||||
AnthropicResponseContentBlockText
|
||||
| AnthropicResponseContentBlockToolUse
|
||||
| AnthropicResponseContentBlockThinking
|
||||
| AnthropicResponseContentBlockRedactedThinking
|
||||
]
|
||||
"""Content generated by the model."""
|
||||
|
||||
model: str
|
||||
"""The model that handled the request."""
|
||||
|
||||
stop_reason: Optional[AnthropicFinishReason]
|
||||
stop_reason: AnthropicFinishReason | None
|
||||
"""The reason that we stopped."""
|
||||
|
||||
stop_sequence: Optional[str]
|
||||
stop_sequence: str | None
|
||||
"""Which custom stop sequence was generated, if any."""
|
||||
|
||||
usage: AnthropicResponseUsageBlock
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from typing import Optional
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
|
|
@ -10,4 +8,4 @@ class AnthropicMetadata(BaseModel):
|
|||
https://docs.anthropic.com/en/api/messages#body-metadata-user-id
|
||||
"""
|
||||
|
||||
user_id: Optional[str] = None
|
||||
user_id: str | None = None
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
from typing import Any, Dict, List, Literal, Optional, Union
|
||||
from typing import Any, Literal, TypeAlias
|
||||
|
||||
from typing_extensions import NotRequired, TypeAlias, TypedDict
|
||||
from typing_extensions import NotRequired, TypedDict
|
||||
|
||||
from litellm.types.llms.anthropic import (
|
||||
AnthropicResponseContentBlockText,
|
||||
|
|
@ -14,7 +14,7 @@ class AnthropicResponseTextBlock(TypedDict, total=False):
|
|||
Anthropic Response Text Block: https://docs.anthropic.com/en/api/messages
|
||||
"""
|
||||
|
||||
citations: Optional[List[Dict[str, Any]]]
|
||||
citations: list[dict[str, Any]] | None
|
||||
text: str
|
||||
type: Literal["text"]
|
||||
|
||||
|
|
@ -24,9 +24,9 @@ class AnthropicResponseToolUseBlock(TypedDict, total=False):
|
|||
Anthropic Response Tool Use Block: https://docs.anthropic.com/en/api/messages
|
||||
"""
|
||||
|
||||
id: Optional[str]
|
||||
input: Optional[str]
|
||||
name: Optional[str]
|
||||
id: str | None
|
||||
input: str | None
|
||||
name: str | None
|
||||
type: Literal["tool_use"]
|
||||
|
||||
|
||||
|
|
@ -35,8 +35,8 @@ class AnthropicResponseThinkingBlock(TypedDict, total=False):
|
|||
Anthropic Response Thinking Block: https://docs.anthropic.com/en/api/messages
|
||||
"""
|
||||
|
||||
signature: Optional[str]
|
||||
thinking: Optional[str]
|
||||
signature: str | None
|
||||
thinking: str | None
|
||||
type: Literal["thinking"]
|
||||
|
||||
|
||||
|
|
@ -45,16 +45,16 @@ class AnthropicResponseRedactedThinkingBlock(TypedDict, total=False):
|
|||
Anthropic Response Redacted Thinking Block: https://docs.anthropic.com/en/api/messages
|
||||
"""
|
||||
|
||||
data: Optional[str]
|
||||
data: str | None
|
||||
type: Literal["redacted_thinking"]
|
||||
|
||||
|
||||
AnthropicResponseContentBlock: TypeAlias = Union[
|
||||
AnthropicResponseTextBlock,
|
||||
AnthropicResponseToolUseBlock,
|
||||
AnthropicResponseThinkingBlock,
|
||||
AnthropicResponseRedactedThinkingBlock,
|
||||
]
|
||||
AnthropicResponseContentBlock: TypeAlias = (
|
||||
AnthropicResponseTextBlock
|
||||
| AnthropicResponseToolUseBlock
|
||||
| AnthropicResponseThinkingBlock
|
||||
| AnthropicResponseRedactedThinkingBlock
|
||||
)
|
||||
|
||||
|
||||
class AnthropicUsage(TypedDict, total=False):
|
||||
|
|
@ -77,20 +77,15 @@ class AnthropicMessagesResponse(TypedDict, total=False):
|
|||
Anthropic Messages API Response: https://docs.anthropic.com/en/api/messages
|
||||
"""
|
||||
|
||||
content: Optional[
|
||||
List[
|
||||
Union[
|
||||
AnthropicResponseContentBlock,
|
||||
AnthropicResponseContentBlockText,
|
||||
AnthropicResponseContentBlockToolUse,
|
||||
]
|
||||
]
|
||||
]
|
||||
content: (
|
||||
list[AnthropicResponseContentBlock | AnthropicResponseContentBlockText | AnthropicResponseContentBlockToolUse]
|
||||
| None
|
||||
)
|
||||
id: str
|
||||
model: Optional[str] # This represents the Model type from Anthropic
|
||||
role: Optional[Literal["assistant"]]
|
||||
stop_reason: Optional[Literal["end_turn", "max_tokens", "stop_sequence", "tool_use"]]
|
||||
stop_sequence: Optional[str]
|
||||
type: Optional[Literal["message"]]
|
||||
usage: Optional[AnthropicUsage]
|
||||
model: str | None # This represents the Model type from Anthropic
|
||||
role: Literal["assistant"] | None
|
||||
stop_reason: Literal["end_turn", "max_tokens", "stop_sequence", "tool_use"] | None
|
||||
stop_sequence: str | None
|
||||
type: Literal["message"] | None
|
||||
usage: AnthropicUsage | None
|
||||
context_management: NotRequired[ContextManagementResponse]
|
||||
|
|
|
|||
|
|
@ -2,33 +2,33 @@
|
|||
Type definitions for Anthropic Skills API
|
||||
"""
|
||||
|
||||
from typing import Any, Dict, List, Literal, Optional, Union
|
||||
from typing import Any
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
from typing_extensions import Required, TypedDict
|
||||
from pydantic import BaseModel
|
||||
from typing_extensions import TypedDict
|
||||
|
||||
|
||||
# Skills API Request Types
|
||||
class CreateSkillRequest(TypedDict, total=False):
|
||||
"""Request parameters for creating a skill"""
|
||||
|
||||
display_title: Optional[str]
|
||||
display_title: str | None
|
||||
"""Display title for the skill (optional)"""
|
||||
|
||||
files: Optional[List[Any]]
|
||||
files: list[Any] | None
|
||||
"""Files to upload for the skill. All files must be in the same top-level directory and must include a SKILL.md file at the root."""
|
||||
|
||||
|
||||
class ListSkillsParams(TypedDict, total=False):
|
||||
"""Query parameters for listing skills"""
|
||||
|
||||
limit: Optional[int]
|
||||
limit: int | None
|
||||
"""Number of results to return per page. Maximum value is 100. Defaults to 20."""
|
||||
|
||||
page: Optional[str]
|
||||
page: str | None
|
||||
"""Pagination token for fetching a specific page of results"""
|
||||
|
||||
source: Optional[str]
|
||||
source: str | None
|
||||
"""Filter skills by source ('custom' or 'anthropic')"""
|
||||
|
||||
|
||||
|
|
@ -42,10 +42,10 @@ class Skill(BaseModel):
|
|||
created_at: str
|
||||
"""ISO 8601 timestamp of when the skill was created"""
|
||||
|
||||
display_title: Optional[str] = None
|
||||
display_title: str | None = None
|
||||
"""Display title for the skill"""
|
||||
|
||||
latest_version: Optional[str] = None
|
||||
latest_version: str | None = None
|
||||
"""The latest version identifier for the skill"""
|
||||
|
||||
source: str
|
||||
|
|
@ -61,10 +61,10 @@ class Skill(BaseModel):
|
|||
class ListSkillsResponse(BaseModel):
|
||||
"""Response from listing skills"""
|
||||
|
||||
data: List[Skill]
|
||||
data: list[Skill]
|
||||
"""List of skills"""
|
||||
|
||||
next_page: Optional[str] = None
|
||||
next_page: str | None = None
|
||||
"""Pagination token for the next page"""
|
||||
|
||||
has_more: bool = False
|
||||
|
|
@ -85,16 +85,16 @@ class DeleteSkillResponse(BaseModel):
|
|||
class CreateSkillVersionRequest(TypedDict, total=False):
|
||||
"""Request parameters for creating a skill version"""
|
||||
|
||||
display_title: Optional[str]
|
||||
display_title: str | None
|
||||
"""Display title for this version"""
|
||||
|
||||
description: Optional[str]
|
||||
description: str | None
|
||||
"""Description of this version"""
|
||||
|
||||
instructions: Optional[str]
|
||||
instructions: str | None
|
||||
"""Instructions for this version"""
|
||||
|
||||
metadata: Optional[Dict[str, Any]]
|
||||
metadata: dict[str, Any] | None
|
||||
"""Additional metadata"""
|
||||
|
||||
|
||||
|
|
@ -110,16 +110,16 @@ class SkillVersion(BaseModel):
|
|||
created_at: str
|
||||
"""ISO 8601 timestamp of when the version was created"""
|
||||
|
||||
display_title: Optional[str] = None
|
||||
display_title: str | None = None
|
||||
"""Display title for this version"""
|
||||
|
||||
description: Optional[str] = None
|
||||
description: str | None = None
|
||||
"""Description of this version"""
|
||||
|
||||
instructions: Optional[str] = None
|
||||
instructions: str | None = None
|
||||
"""Instructions for this version"""
|
||||
|
||||
metadata: Optional[Dict[str, Any]] = None
|
||||
metadata: dict[str, Any] | None = None
|
||||
"""Additional metadata"""
|
||||
|
||||
type: str = "skill.version"
|
||||
|
|
@ -132,13 +132,13 @@ class ListSkillVersionsResponse(BaseModel):
|
|||
object: str = "list"
|
||||
"""Object type, always 'list'"""
|
||||
|
||||
data: List[SkillVersion]
|
||||
data: list[SkillVersion]
|
||||
"""List of skill versions"""
|
||||
|
||||
first_id: Optional[str] = None
|
||||
first_id: str | None = None
|
||||
"""ID of the first version in the list"""
|
||||
|
||||
last_id: Optional[str] = None
|
||||
last_id: str | None = None
|
||||
"""ID of the last version in the list"""
|
||||
|
||||
has_more: bool = False
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ Tool Search Beta Header Configuration
|
|||
Reference: https://platform.claude.com/docs/en/agents-and-tools/tool-use/tool-search-tool
|
||||
"""
|
||||
|
||||
from typing import Dict, Final
|
||||
from typing import Final
|
||||
|
||||
from litellm.types.utils import LlmProviders
|
||||
|
||||
|
|
@ -15,7 +15,7 @@ TOOL_SEARCH_BETA_HEADER_BEDROCK: Final = "tool-search-tool-2025-10-19"
|
|||
|
||||
|
||||
# Mapping of custom_llm_provider -> tool search beta header
|
||||
TOOL_SEARCH_BETA_HEADER_BY_PROVIDER: Final[Dict[str, str]] = {
|
||||
TOOL_SEARCH_BETA_HEADER_BY_PROVIDER: Final[dict[str, str]] = {
|
||||
LlmProviders.ANTHROPIC.value: TOOL_SEARCH_BETA_HEADER_ANTHROPIC,
|
||||
LlmProviders.AZURE.value: TOOL_SEARCH_BETA_HEADER_ANTHROPIC,
|
||||
LlmProviders.AZURE_AI.value: TOOL_SEARCH_BETA_HEADER_ANTHROPIC,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
from typing import Any, Dict, Final, Iterable, List, Literal, Optional, Union
|
||||
from typing import Literal
|
||||
|
||||
from typing_extensions import Required, TypedDict
|
||||
|
||||
|
|
@ -12,6 +12,6 @@ EncodingFormat = Literal["base64", "binary", "float", "int8", "ubinary", "uint8"
|
|||
|
||||
|
||||
class ImageEmbeddingRequest(TypedDict, total=False):
|
||||
input: Required[List[ImageEmbeddingInput]]
|
||||
input: Required[list[ImageEmbeddingInput]]
|
||||
dimensions: int
|
||||
encoding_format: EncodingFormat
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
from typing import Any, Final, Optional, Union
|
||||
from typing import Any, Final
|
||||
|
||||
from openai._models import BaseModel as OpenAIObject
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
|
|
@ -11,14 +11,14 @@ class LiteLLMPydanticObjectBase(BaseModel):
|
|||
|
||||
def json(self, **kwargs): # type: ignore
|
||||
try:
|
||||
return self.model_dump(**kwargs) # noqa
|
||||
return self.model_dump(**kwargs)
|
||||
except Exception:
|
||||
# if using pydantic v1
|
||||
return self.dict(**kwargs)
|
||||
|
||||
def fields_set(self):
|
||||
try:
|
||||
return self.model_fields_set # noqa
|
||||
return self.model_fields_set
|
||||
except Exception:
|
||||
# if using pydantic v1
|
||||
return self.__fields_set__
|
||||
|
|
@ -35,7 +35,7 @@ class BaseLiteLLMOpenAIResponseObject(BaseModel):
|
|||
def get(self, key, default=None):
|
||||
return self.__dict__.get(key, default)
|
||||
|
||||
def __contains__(self, key):
|
||||
def __contains__(self, key) -> bool:
|
||||
return key in self.__dict__
|
||||
|
||||
def items(self):
|
||||
|
|
@ -43,11 +43,11 @@ class BaseLiteLLMOpenAIResponseObject(BaseModel):
|
|||
|
||||
|
||||
class HiddenParams(OpenAIObject):
|
||||
original_response: Optional[Union[str, Any]] = None
|
||||
model_id: Optional[str] = None # used in Router for individual deployments
|
||||
api_base: Optional[str] = None # returns api base used for making completion call
|
||||
_response_ms: Optional[float] = None
|
||||
response_cost: Optional[float] = None
|
||||
original_response: str | Any | None = None
|
||||
model_id: str | None = None # used in Router for individual deployments
|
||||
api_base: str | None = None # returns api base used for making completion call
|
||||
_response_ms: float | None = None
|
||||
response_cost: float | None = None
|
||||
|
||||
model_config = ConfigDict(extra="allow", protected_namespaces=())
|
||||
|
||||
|
|
@ -59,13 +59,13 @@ class HiddenParams(OpenAIObject):
|
|||
# Allow dictionary-style access to attributes
|
||||
return getattr(self, key)
|
||||
|
||||
def __setitem__(self, key, value):
|
||||
def __setitem__(self, key, value) -> None:
|
||||
# Allow dictionary-style assignment of attributes
|
||||
setattr(self, key, value)
|
||||
|
||||
def json(self, **kwargs): # type: ignore
|
||||
try:
|
||||
return self.model_dump() # noqa
|
||||
return self.model_dump()
|
||||
except Exception:
|
||||
# if using pydantic v1
|
||||
return self.dict()
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import json
|
||||
from typing import Any, Dict, Final, List, Literal, Optional, Union
|
||||
from typing import TYPE_CHECKING, Any, Final, Literal
|
||||
|
||||
from typing_extensions import TYPE_CHECKING, Required, TypedDict, override
|
||||
from typing_extensions import Required, TypedDict, override
|
||||
|
||||
from .openai import ChatCompletionToolCallChunk
|
||||
|
||||
|
|
@ -17,14 +17,14 @@ class SystemContentBlock(TypedDict, total=False):
|
|||
|
||||
|
||||
class SourceBlock(TypedDict):
|
||||
bytes: Optional[str] # base 64 encoded string
|
||||
bytes: str | None # base 64 encoded string
|
||||
|
||||
|
||||
BedrockImageTypes = Literal["png", "jpeg", "gif", "webp"]
|
||||
|
||||
|
||||
class ImageBlock(TypedDict):
|
||||
format: Union[BedrockImageTypes, str]
|
||||
format: BedrockImageTypes | str
|
||||
source: SourceBlock
|
||||
|
||||
|
||||
|
|
@ -32,7 +32,7 @@ BedrockVideoTypes = Literal["mp4", "mov", "mkv", "webm", "flv", "mpeg", "mpg", "
|
|||
|
||||
|
||||
class VideoBlock(TypedDict):
|
||||
format: Union[BedrockVideoTypes, str]
|
||||
format: BedrockVideoTypes | str
|
||||
source: SourceBlock
|
||||
|
||||
|
||||
|
|
@ -40,7 +40,7 @@ BedrockDocumentTypes = Literal["pdf", "csv", "doc", "docx", "xls", "xlsx", "html
|
|||
|
||||
|
||||
class DocumentBlock(TypedDict):
|
||||
format: Union[BedrockDocumentTypes, str]
|
||||
format: BedrockDocumentTypes | str
|
||||
source: SourceBlock
|
||||
name: str
|
||||
|
||||
|
|
@ -55,7 +55,7 @@ class SearchResultBlock(TypedDict, total=False):
|
|||
|
||||
source: str
|
||||
title: str
|
||||
content: List[dict]
|
||||
content: list[dict]
|
||||
citations: dict
|
||||
|
||||
|
||||
|
|
@ -68,7 +68,7 @@ class ToolResultContentBlock(TypedDict, total=False):
|
|||
|
||||
|
||||
class ToolResultBlock(TypedDict, total=False):
|
||||
content: Required[List[ToolResultContentBlock]]
|
||||
content: Required[list[ToolResultContentBlock]]
|
||||
toolUseId: Required[str]
|
||||
status: Literal["success", "error"]
|
||||
|
||||
|
|
@ -185,8 +185,8 @@ class CitationsContentBlock(TypedDict, total=False):
|
|||
}
|
||||
"""
|
||||
|
||||
content: List[CitationGeneratedContentBlock]
|
||||
citations: List[CitationReferenceBlock]
|
||||
content: list[CitationGeneratedContentBlock]
|
||||
citations: list[CitationReferenceBlock]
|
||||
|
||||
|
||||
class ContentBlock(TypedDict, total=False):
|
||||
|
|
@ -203,7 +203,7 @@ class ContentBlock(TypedDict, total=False):
|
|||
|
||||
|
||||
class MessageBlock(TypedDict):
|
||||
content: List[ContentBlock]
|
||||
content: list[ContentBlock]
|
||||
role: Literal["user", "assistant"]
|
||||
|
||||
|
||||
|
|
@ -212,7 +212,7 @@ class ConverseMetricsBlock(TypedDict):
|
|||
|
||||
|
||||
class ConverseResponseOutputBlock(TypedDict):
|
||||
message: Optional[MessageBlock]
|
||||
message: MessageBlock | None
|
||||
|
||||
|
||||
class ConverseTokenUsageBlock(TypedDict):
|
||||
|
|
@ -241,12 +241,12 @@ class ConverseResponseBlock(TypedDict, total=False):
|
|||
class ToolJsonSchemaBlock(TypedDict, total=False):
|
||||
type: Literal["object"]
|
||||
properties: dict
|
||||
required: List[str]
|
||||
required: list[str]
|
||||
additionalProperties: bool
|
||||
|
||||
|
||||
class ToolInputSchemaBlock(TypedDict):
|
||||
json: Optional[ToolJsonSchemaBlock]
|
||||
json: ToolJsonSchemaBlock | None
|
||||
|
||||
|
||||
class ToolSpecBlock(TypedDict, total=False):
|
||||
|
|
@ -272,9 +272,9 @@ class SystemToolBlock(TypedDict, total=False):
|
|||
|
||||
|
||||
class ToolBlock(TypedDict, total=False):
|
||||
toolSpec: Optional[ToolSpecBlock]
|
||||
systemTool: Optional[SystemToolBlock]
|
||||
cachePoint: Optional[CachePointBlock]
|
||||
toolSpec: ToolSpecBlock | None
|
||||
systemTool: SystemToolBlock | None
|
||||
cachePoint: CachePointBlock | None
|
||||
|
||||
|
||||
class BedrockToolSpec(dict):
|
||||
|
|
@ -284,7 +284,7 @@ class BedrockToolSpec(dict):
|
|||
name: str,
|
||||
description: str,
|
||||
parameters: dict,
|
||||
strict: Optional[bool],
|
||||
strict: bool | None,
|
||||
supports_strict_tools: bool,
|
||||
) -> None:
|
||||
json_schema: Final[ToolJsonSchemaBlock] = {
|
||||
|
|
@ -318,8 +318,8 @@ class ToolChoiceValuesBlock(TypedDict, total=False):
|
|||
|
||||
|
||||
class ToolConfigBlock(TypedDict, total=False):
|
||||
tools: Required[List[ToolBlock]]
|
||||
toolChoice: Union[str, ToolChoiceValuesBlock]
|
||||
tools: Required[list[ToolBlock]]
|
||||
toolChoice: str | ToolChoiceValuesBlock
|
||||
|
||||
|
||||
class GuardrailConfigBlock(TypedDict, total=False):
|
||||
|
|
@ -330,7 +330,7 @@ class GuardrailConfigBlock(TypedDict, total=False):
|
|||
|
||||
class InferenceConfig(TypedDict, total=False):
|
||||
maxTokens: int
|
||||
stopSequences: List[str]
|
||||
stopSequences: list[str]
|
||||
temperature: float
|
||||
topP: float
|
||||
topK: int
|
||||
|
|
@ -346,7 +346,7 @@ class ToolUseBlockStartEvent(TypedDict):
|
|||
|
||||
|
||||
class ContentBlockStartEvent(TypedDict, total=False):
|
||||
toolUse: Optional[ToolUseBlockStartEvent]
|
||||
toolUse: ToolUseBlockStartEvent | None
|
||||
reasoningContent: BedrockConverseReasoningContentBlockDelta
|
||||
|
||||
|
||||
|
|
@ -395,19 +395,19 @@ class OutputConfigBlock(TypedDict, total=False):
|
|||
|
||||
class CommonRequestObject(TypedDict, total=False): # common request object across sync + async flows
|
||||
additionalModelRequestFields: dict
|
||||
additionalModelResponseFieldPaths: List[str]
|
||||
additionalModelResponseFieldPaths: list[str]
|
||||
inferenceConfig: InferenceConfig
|
||||
system: List[SystemContentBlock]
|
||||
system: list[SystemContentBlock]
|
||||
toolConfig: ToolConfigBlock
|
||||
guardrailConfig: Optional[GuardrailConfigBlock]
|
||||
performanceConfig: Optional[PerformanceConfigBlock]
|
||||
serviceTier: Optional[ServiceTierBlock]
|
||||
requestMetadata: Optional[Dict[str, str]]
|
||||
outputConfig: Optional[OutputConfigBlock]
|
||||
guardrailConfig: GuardrailConfigBlock | None
|
||||
performanceConfig: PerformanceConfigBlock | None
|
||||
serviceTier: ServiceTierBlock | None
|
||||
requestMetadata: dict[str, str] | None
|
||||
outputConfig: OutputConfigBlock | None
|
||||
|
||||
|
||||
class RequestObject(CommonRequestObject, total=False):
|
||||
messages: Required[List[MessageBlock]]
|
||||
messages: Required[list[MessageBlock]]
|
||||
|
||||
|
||||
class BedrockInvokeNovaRequest(TypedDict, total=False):
|
||||
|
|
@ -415,19 +415,19 @@ class BedrockInvokeNovaRequest(TypedDict, total=False):
|
|||
Request object for sending `nova` requests to `/bedrock/invoke/`
|
||||
"""
|
||||
|
||||
messages: List[MessageBlock]
|
||||
messages: list[MessageBlock]
|
||||
inferenceConfig: InferenceConfig
|
||||
system: List[SystemContentBlock]
|
||||
system: list[SystemContentBlock]
|
||||
toolConfig: ToolConfigBlock
|
||||
guardrailConfig: Optional[GuardrailConfigBlock]
|
||||
guardrailConfig: GuardrailConfigBlock | None
|
||||
|
||||
|
||||
class GenericStreamingChunk(TypedDict):
|
||||
text: Required[str]
|
||||
tool_use: Optional[ChatCompletionToolCallChunk]
|
||||
tool_use: ChatCompletionToolCallChunk | None
|
||||
is_finished: Required[bool]
|
||||
finish_reason: Required[str]
|
||||
usage: Optional[ConverseTokenUsageBlock]
|
||||
usage: ConverseTokenUsageBlock | None
|
||||
index: int
|
||||
|
||||
|
||||
|
|
@ -440,10 +440,10 @@ class ServerSentEvent:
|
|||
def __init__(
|
||||
self,
|
||||
*,
|
||||
event: Optional[str] = None,
|
||||
data: Optional[str] = None,
|
||||
id: Optional[str] = None,
|
||||
retry: Optional[int] = None,
|
||||
event: str | None = None,
|
||||
data: str | None = None,
|
||||
id: str | None = None,
|
||||
retry: int | None = None,
|
||||
) -> None:
|
||||
if data is None:
|
||||
data = ""
|
||||
|
|
@ -454,15 +454,15 @@ class ServerSentEvent:
|
|||
self._retry = retry
|
||||
|
||||
@property
|
||||
def event(self) -> Optional[str]:
|
||||
def event(self) -> str | None:
|
||||
return self._event
|
||||
|
||||
@property
|
||||
def id(self) -> Optional[str]:
|
||||
def id(self) -> str | None:
|
||||
return self._id
|
||||
|
||||
@property
|
||||
def retry(self) -> Optional[int]:
|
||||
def retry(self) -> int | None:
|
||||
return self._retry
|
||||
|
||||
@property
|
||||
|
|
@ -481,8 +481,8 @@ COHERE_EMBEDDING_INPUT_TYPES = Literal["search_document", "search_query", "class
|
|||
|
||||
|
||||
class CohereEmbeddingRequest(TypedDict, total=False):
|
||||
texts: List[str]
|
||||
images: List[str]
|
||||
texts: list[str]
|
||||
images: list[str]
|
||||
input_type: Required[COHERE_EMBEDDING_INPUT_TYPES]
|
||||
truncate: Literal["NONE", "START", "END"]
|
||||
embedding_types: Literal["float", "int8", "uint8", "binary", "ubinary"]
|
||||
|
|
@ -494,26 +494,26 @@ class CohereEmbeddingRequestWithModel(CohereEmbeddingRequest):
|
|||
|
||||
|
||||
class CohereEmbeddingResponse(TypedDict):
|
||||
embeddings: List[List[float]]
|
||||
embeddings: list[list[float]]
|
||||
id: str
|
||||
response_type: Literal["embedding_floats"]
|
||||
texts: List[str]
|
||||
texts: list[str]
|
||||
|
||||
|
||||
class AmazonTitanV2EmbeddingRequest(TypedDict, total=False):
|
||||
inputText: Required[str]
|
||||
dimensions: int
|
||||
normalize: bool
|
||||
embeddingTypes: List[Literal["float", "binary"]]
|
||||
embeddingTypes: list[Literal["float", "binary"]]
|
||||
|
||||
|
||||
class AmazonTitanV2EmbeddingsByType(TypedDict, total=False):
|
||||
binary: List[int] # Array of integers for binary format
|
||||
float: List[float] # Array of floats for float format
|
||||
binary: list[int] # Array of integers for binary format
|
||||
float: list[float] # Array of floats for float format
|
||||
|
||||
|
||||
class AmazonTitanV2EmbeddingResponse(TypedDict, total=False):
|
||||
embedding: List[float] # Legacy field - array of floats (backward compatibility)
|
||||
embedding: list[float] # Legacy field - array of floats (backward compatibility)
|
||||
embeddingsByType: AmazonTitanV2EmbeddingsByType # New format per AWS schema
|
||||
inputTextTokenCount: Required[int] # Always present in AWS response
|
||||
|
||||
|
|
@ -523,7 +523,7 @@ class AmazonTitanG1EmbeddingRequest(TypedDict):
|
|||
|
||||
|
||||
class AmazonTitanG1EmbeddingResponse(TypedDict):
|
||||
embedding: List[float]
|
||||
embedding: list[float]
|
||||
inputTextTokenCount: int
|
||||
|
||||
|
||||
|
|
@ -538,7 +538,7 @@ class AmazonTitanMultimodalEmbeddingRequest(TypedDict, total=False):
|
|||
|
||||
|
||||
class AmazonTitanMultimodalEmbeddingResponse(TypedDict):
|
||||
embedding: List[float]
|
||||
embedding: list[float]
|
||||
inputTextTokenCount: int
|
||||
message: str # Specifies any errors that occur during generation.
|
||||
|
||||
|
|
@ -567,11 +567,11 @@ class TwelveLabsMarengoEmbeddingRequest(TypedDict, total=False):
|
|||
lengthSec: float
|
||||
useFixedLengthSec: float
|
||||
minClipSec: int
|
||||
embeddingOption: List[TWELVELABS_EMBEDDING_OPTIONS]
|
||||
embeddingOption: list[TWELVELABS_EMBEDDING_OPTIONS]
|
||||
|
||||
|
||||
class TwelveLabsMarengoEmbeddingResponse(TypedDict):
|
||||
embedding: List[float]
|
||||
embedding: list[float]
|
||||
embeddingOption: TWELVELABS_EMBEDDING_OPTIONS
|
||||
startSec: float
|
||||
endSec: float
|
||||
|
|
@ -597,10 +597,10 @@ class TwelveLabsAsyncInvokeStatusResponse(TypedDict):
|
|||
status: str # "InProgress" | "Completed" | "Failed"
|
||||
submitTime: str
|
||||
lastModifiedTime: str
|
||||
endTime: Optional[str]
|
||||
endTime: str | None
|
||||
outputDataConfig: TwelveLabsOutputDataConfig
|
||||
clientRequestToken: Optional[str]
|
||||
failureMessage: Optional[str]
|
||||
clientRequestToken: str | None
|
||||
failureMessage: str | None
|
||||
|
||||
|
||||
# Amazon Nova Multimodal Embeddings types
|
||||
|
|
@ -706,12 +706,12 @@ class NovaEmbeddingRequest(TypedDict, total=False):
|
|||
|
||||
class NovaEmbeddingItem(TypedDict, total=False):
|
||||
embeddingType: NOVA_EMBEDDING_TYPES
|
||||
embedding: Required[List[float]]
|
||||
embedding: Required[list[float]]
|
||||
truncatedCharLength: int # Only for text
|
||||
|
||||
|
||||
class NovaEmbeddingResponse(TypedDict):
|
||||
embeddings: List[NovaEmbeddingItem]
|
||||
embeddings: list[NovaEmbeddingItem]
|
||||
|
||||
|
||||
class NovaS3OutputDataConfig(TypedDict):
|
||||
|
|
@ -728,11 +728,9 @@ class NovaAsyncInvokeRequest(TypedDict):
|
|||
outputDataConfig: NovaOutputDataConfig
|
||||
|
||||
|
||||
AmazonEmbeddingRequest = Union[
|
||||
AmazonTitanMultimodalEmbeddingRequest,
|
||||
AmazonTitanV2EmbeddingRequest,
|
||||
AmazonTitanG1EmbeddingRequest,
|
||||
]
|
||||
AmazonEmbeddingRequest = (
|
||||
AmazonTitanMultimodalEmbeddingRequest | AmazonTitanV2EmbeddingRequest | AmazonTitanG1EmbeddingRequest
|
||||
)
|
||||
|
||||
|
||||
class AmazonStability3TextToImageRequest(TypedDict, total=False):
|
||||
|
|
@ -757,9 +755,9 @@ class AmazonStability3TextToImageResponse(TypedDict, total=False):
|
|||
Ref: https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-diffusion-3-text-image.html
|
||||
"""
|
||||
|
||||
images: List[str]
|
||||
seeds: List[str]
|
||||
finish_reasons: List[str]
|
||||
images: list[str]
|
||||
seeds: list[str]
|
||||
finish_reasons: list[str]
|
||||
|
||||
|
||||
class AmazonTitanTextToImageParams(TypedDict, total=False):
|
||||
|
|
@ -776,8 +774,6 @@ class AmazonNovaCanvasRequestBase(TypedDict, total=False):
|
|||
Base class for Amazon Nova Canvas API requests
|
||||
"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class AmazonNovaCanvasImageGenerationConfig(TypedDict, total=False):
|
||||
"""
|
||||
|
|
@ -823,7 +819,7 @@ class AmazonNovaCanvasColorGuidedGenerationParams(TypedDict, total=False):
|
|||
Params for Amazon Nova Canvas Color Guided Generation API
|
||||
"""
|
||||
|
||||
colors: List[str]
|
||||
colors: list[str]
|
||||
referenceImage: str
|
||||
text: str
|
||||
negativeText: str
|
||||
|
|
@ -848,7 +844,7 @@ class AmazonNovaCanvasTextToImageResponse(TypedDict, total=False):
|
|||
Ref: https://docs.aws.amazon.com/nova/latest/userguide/image-gen-req-resp-structure.html
|
||||
"""
|
||||
|
||||
images: List[str]
|
||||
images: list[str]
|
||||
|
||||
|
||||
class AmazonNovaCanvasInpaintingParams(TypedDict, total=False):
|
||||
|
|
@ -945,15 +941,15 @@ class BedrockRerankRequest(TypedDict):
|
|||
Request for Bedrock Rerank API
|
||||
"""
|
||||
|
||||
queries: List[BedrockRerankQuery]
|
||||
queries: list[BedrockRerankQuery]
|
||||
rerankingConfiguration: BedrockRerankConfiguration
|
||||
sources: List[BedrockRerankSource]
|
||||
sources: list[BedrockRerankSource]
|
||||
|
||||
|
||||
class AmazonDeepSeekR1StreamingResponse(TypedDict):
|
||||
generation: str
|
||||
generation_token_count: int
|
||||
stop_reason: Optional[str]
|
||||
stop_reason: str | None
|
||||
prompt_token_count: int
|
||||
|
||||
|
||||
|
|
@ -976,7 +972,7 @@ class BedrockS3OutputDataConfig(TypedDict, total=False):
|
|||
"""S3 output data configuration for Bedrock batch jobs."""
|
||||
|
||||
s3Uri: str
|
||||
s3EncryptionKeyId: Optional[str]
|
||||
s3EncryptionKeyId: str | None
|
||||
|
||||
|
||||
class BedrockOutputDataConfig(TypedDict):
|
||||
|
|
@ -1002,9 +998,9 @@ class BedrockCreateBatchRequest(TypedDict, total=False):
|
|||
modelId: str
|
||||
inputDataConfig: BedrockInputDataConfig
|
||||
outputDataConfig: BedrockOutputDataConfig
|
||||
timeoutDurationInHours: Optional[int]
|
||||
clientRequestToken: Optional[str]
|
||||
tags: Optional[List[BedrockTag]]
|
||||
timeoutDurationInHours: int | None
|
||||
clientRequestToken: str | None
|
||||
tags: list[BedrockTag] | None
|
||||
|
||||
|
||||
BedrockBatchJobStatus = Literal["Submitted", "InProgress", "Completed", "Failed", "Stopping", "Stopped"]
|
||||
|
|
@ -1034,20 +1030,20 @@ class BedrockGetBatchResponse(TypedDict, total=False):
|
|||
modelId: str
|
||||
roleArn: str
|
||||
status: BedrockBatchJobStatus
|
||||
message: Optional[str]
|
||||
submitTime: Optional[str]
|
||||
lastModifiedTime: Optional[str]
|
||||
endTime: Optional[str]
|
||||
message: str | None
|
||||
submitTime: str | None
|
||||
lastModifiedTime: str | None
|
||||
endTime: str | None
|
||||
inputDataConfig: BedrockInputDataConfig
|
||||
outputDataConfig: BedrockOutputDataConfig
|
||||
timeoutDurationInHours: Optional[int]
|
||||
clientRequestToken: Optional[str]
|
||||
timeoutDurationInHours: int | None
|
||||
clientRequestToken: str | None
|
||||
|
||||
|
||||
class BedrockToolBlock(TypedDict, total=False):
|
||||
toolSpec: Optional[ToolSpecBlock]
|
||||
systemTool: Optional[SystemToolBlock] # For Nova grounding
|
||||
cachePoint: Optional[CachePointBlock]
|
||||
toolSpec: ToolSpecBlock | None
|
||||
systemTool: SystemToolBlock | None # For Nova grounding
|
||||
cachePoint: CachePointBlock | None
|
||||
|
||||
|
||||
class BedrockInvokeAnthropicMessagesRequest(TypedDict, total=False):
|
||||
|
|
@ -1079,9 +1075,9 @@ class BedrockInvokeAnthropicMessagesRequest(TypedDict, total=False):
|
|||
messages: list
|
||||
|
||||
# Documented optional fields
|
||||
anthropic_beta: List[str]
|
||||
anthropic_beta: list[str]
|
||||
system: object # str or list[TextBlock]
|
||||
stop_sequences: List[str]
|
||||
stop_sequences: list[str]
|
||||
temperature: float
|
||||
top_p: float
|
||||
top_k: int
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@ Type definitions for AWS Bedrock AgentCore API.
|
|||
https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agentcore_InvokeAgentRuntime.html
|
||||
"""
|
||||
|
||||
from typing import Dict, List, Optional
|
||||
from typing import Literal
|
||||
|
||||
from typing_extensions import Literal, TypedDict
|
||||
from typing_extensions import TypedDict
|
||||
|
||||
|
||||
# Request Types
|
||||
|
|
@ -85,25 +85,25 @@ class AgentCoreEventPayload(TypedDict, total=False):
|
|||
"""Union payload for different event types."""
|
||||
|
||||
# messageStart event
|
||||
messageStart: Optional[AgentCoreMessageStart]
|
||||
messageStart: AgentCoreMessageStart | None
|
||||
|
||||
# contentBlockDelta event
|
||||
contentBlockDelta: Optional[AgentCoreContentBlockDeltaEvent]
|
||||
contentBlockDelta: AgentCoreContentBlockDeltaEvent | None
|
||||
|
||||
# contentBlockStop event
|
||||
contentBlockStop: Optional[AgentCoreContentBlockStop]
|
||||
contentBlockStop: AgentCoreContentBlockStop | None
|
||||
|
||||
# messageStop event
|
||||
messageStop: Optional[AgentCoreMessageStop]
|
||||
messageStop: AgentCoreMessageStop | None
|
||||
|
||||
# metadata event
|
||||
metadata: Optional[AgentCoreMetadata]
|
||||
metadata: AgentCoreMetadata | None
|
||||
|
||||
|
||||
class AgentCoreEvent(TypedDict, total=False):
|
||||
"""SSE event structure from AgentCore."""
|
||||
|
||||
event: Optional[AgentCoreEventPayload]
|
||||
event: AgentCoreEventPayload | None
|
||||
|
||||
|
||||
class AgentCoreContentBlock(TypedDict):
|
||||
|
|
@ -116,7 +116,7 @@ class AgentCoreMessage(TypedDict):
|
|||
"""Complete message structure."""
|
||||
|
||||
role: Literal["assistant"]
|
||||
content: List[AgentCoreContentBlock]
|
||||
content: list[AgentCoreContentBlock]
|
||||
|
||||
|
||||
class AgentCoreFinalMessage(TypedDict):
|
||||
|
|
@ -130,5 +130,5 @@ class AgentCoreParsedResponse(TypedDict):
|
|||
"""Parsed response from SSE stream."""
|
||||
|
||||
content: str
|
||||
usage: Optional[AgentCoreUsage]
|
||||
final_message: Optional[AgentCoreMessage]
|
||||
usage: AgentCoreUsage | None
|
||||
final_message: AgentCoreMessage | None
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ Type definitions for AWS Bedrock Invoke Agent API responses.
|
|||
https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_InvokeAgent.html
|
||||
"""
|
||||
|
||||
from typing import Any, Dict, Final, List, Optional, Union
|
||||
from typing import Any, Final
|
||||
|
||||
from typing_extensions import TypedDict
|
||||
|
||||
|
|
@ -22,58 +22,58 @@ class InvokeAgentUsage(TypedDict):
|
|||
|
||||
inputTokens: int
|
||||
outputTokens: int
|
||||
model: Optional[str]
|
||||
model: str | None
|
||||
|
||||
|
||||
class InvokeAgentMetadata(TypedDict, total=False):
|
||||
"""Metadata from model invocation."""
|
||||
|
||||
clientRequestId: Optional[str]
|
||||
endTime: Optional[str]
|
||||
startTime: Optional[str]
|
||||
totalTimeMs: Optional[int]
|
||||
usage: Optional[InvokeAgentUsage]
|
||||
clientRequestId: str | None
|
||||
endTime: str | None
|
||||
startTime: str | None
|
||||
totalTimeMs: int | None
|
||||
usage: InvokeAgentUsage | None
|
||||
|
||||
|
||||
class InvokeAgentModelInvocationInput(TypedDict, total=False):
|
||||
"""Model invocation input details."""
|
||||
|
||||
foundationModel: Optional[str]
|
||||
inferenceConfiguration: Optional[Dict[str, Any]]
|
||||
text: Optional[str]
|
||||
traceId: Optional[str]
|
||||
type: Optional[str]
|
||||
foundationModel: str | None
|
||||
inferenceConfiguration: dict[str, Any] | None
|
||||
text: str | None
|
||||
traceId: str | None
|
||||
type: str | None
|
||||
|
||||
|
||||
class InvokeAgentModelInvocationOutput(TypedDict, total=False):
|
||||
"""Model invocation output details."""
|
||||
|
||||
metadata: Optional[InvokeAgentMetadata]
|
||||
parsedResponse: Optional[Dict[str, Any]]
|
||||
rawResponse: Optional[Dict[str, Any]]
|
||||
reasoningContent: Optional[Dict[str, Any]]
|
||||
traceId: Optional[str]
|
||||
metadata: InvokeAgentMetadata | None
|
||||
parsedResponse: dict[str, Any] | None
|
||||
rawResponse: dict[str, Any] | None
|
||||
reasoningContent: dict[str, Any] | None
|
||||
traceId: str | None
|
||||
|
||||
|
||||
class InvokeAgentOrchestrationTrace(TypedDict, total=False):
|
||||
"""Orchestration trace information."""
|
||||
|
||||
modelInvocationInput: Optional[InvokeAgentModelInvocationInput]
|
||||
modelInvocationOutput: Optional[InvokeAgentModelInvocationOutput]
|
||||
modelInvocationInput: InvokeAgentModelInvocationInput | None
|
||||
modelInvocationOutput: InvokeAgentModelInvocationOutput | None
|
||||
|
||||
|
||||
class InvokeAgentPreProcessingTrace(TypedDict, total=False):
|
||||
"""Pre-processing trace information."""
|
||||
|
||||
modelInvocationInput: Optional[InvokeAgentModelInvocationInput]
|
||||
modelInvocationOutput: Optional[InvokeAgentModelInvocationOutput]
|
||||
modelInvocationInput: InvokeAgentModelInvocationInput | None
|
||||
modelInvocationOutput: InvokeAgentModelInvocationOutput | None
|
||||
|
||||
|
||||
class InvokeAgentTrace(TypedDict, total=False):
|
||||
"""Trace information container."""
|
||||
|
||||
orchestrationTrace: Optional[InvokeAgentOrchestrationTrace]
|
||||
preProcessingTrace: Optional[InvokeAgentPreProcessingTrace]
|
||||
orchestrationTrace: InvokeAgentOrchestrationTrace | None
|
||||
preProcessingTrace: InvokeAgentPreProcessingTrace | None
|
||||
|
||||
|
||||
class InvokeAgentCallerChain(TypedDict, total=False):
|
||||
|
|
@ -88,7 +88,7 @@ class InvokeAgentTracePayload(TypedDict, total=False):
|
|||
agentAliasId: str
|
||||
agentId: str
|
||||
agentVersion: str
|
||||
callerChain: List[InvokeAgentCallerChain]
|
||||
callerChain: list[InvokeAgentCallerChain]
|
||||
eventTime: str
|
||||
sessionId: str
|
||||
trace: InvokeAgentTrace
|
||||
|
|
@ -104,26 +104,26 @@ class InvokeAgentEventPayload(TypedDict, total=False):
|
|||
"""Union type for different event payload types."""
|
||||
|
||||
# Trace event fields
|
||||
agentAliasId: Optional[str]
|
||||
agentId: Optional[str]
|
||||
agentVersion: Optional[str]
|
||||
callerChain: Optional[List[InvokeAgentCallerChain]]
|
||||
eventTime: Optional[str]
|
||||
sessionId: Optional[str]
|
||||
trace: Optional[InvokeAgentTrace]
|
||||
agentAliasId: str | None
|
||||
agentId: str | None
|
||||
agentVersion: str | None
|
||||
callerChain: list[InvokeAgentCallerChain] | None
|
||||
eventTime: str | None
|
||||
sessionId: str | None
|
||||
trace: InvokeAgentTrace | None
|
||||
|
||||
# Chunk event fields
|
||||
bytes: Optional[str]
|
||||
bytes: str | None
|
||||
|
||||
|
||||
class InvokeAgentEvent(TypedDict, total=False):
|
||||
"""Complete event structure for AWS Invoke Agent responses."""
|
||||
|
||||
headers: InvokeAgentEventHeaders
|
||||
payload: Optional[InvokeAgentEventPayload]
|
||||
payload: InvokeAgentEventPayload | None
|
||||
|
||||
|
||||
# Type aliases for convenience
|
||||
InvokeAgentEventList = List[InvokeAgentEvent]
|
||||
InvokeAgentEventList = list[InvokeAgentEvent]
|
||||
InvokeAgentTraceEvent: Final = InvokeAgentEvent # When headers.event_type == 'trace'
|
||||
InvokeAgentChunkEvent: Final = InvokeAgentEvent # When headers.event_type == 'chunk'
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
from typing import Final, Iterable, List, Optional, Union
|
||||
from typing import Literal
|
||||
|
||||
from typing_extensions import Literal, Required, TypedDict
|
||||
from typing_extensions import Required, TypedDict
|
||||
|
||||
|
||||
class CallObject(TypedDict):
|
||||
|
|
@ -10,12 +10,12 @@ class CallObject(TypedDict):
|
|||
|
||||
class ToolResultObject(TypedDict):
|
||||
call: CallObject
|
||||
outputs: List[dict]
|
||||
outputs: list[dict]
|
||||
|
||||
|
||||
class ChatHistoryToolResult(TypedDict, total=False):
|
||||
role: Required[Literal["TOOL"]]
|
||||
tool_results: List[ToolResultObject]
|
||||
tool_results: list[ToolResultObject]
|
||||
|
||||
|
||||
class ToolCallObject(TypedDict):
|
||||
|
|
@ -26,22 +26,22 @@ class ToolCallObject(TypedDict):
|
|||
class ChatHistoryUser(TypedDict, total=False):
|
||||
role: Required[Literal["USER"]]
|
||||
message: str
|
||||
tool_calls: List[ToolCallObject]
|
||||
tool_calls: list[ToolCallObject]
|
||||
|
||||
|
||||
class ChatHistorySystem(TypedDict, total=False):
|
||||
role: Required[Literal["SYSTEM"]]
|
||||
message: str
|
||||
tool_calls: List[ToolCallObject]
|
||||
tool_calls: list[ToolCallObject]
|
||||
|
||||
|
||||
class ChatHistoryChatBot(TypedDict, total=False):
|
||||
role: Required[Literal["CHATBOT"]]
|
||||
message: str
|
||||
tool_calls: List[ToolCallObject]
|
||||
tool_calls: list[ToolCallObject]
|
||||
|
||||
|
||||
ChatHistory = List[Union[ChatHistorySystem, ChatHistoryChatBot, ChatHistoryUser, ChatHistoryToolResult]]
|
||||
ChatHistory = list[ChatHistorySystem | ChatHistoryChatBot | ChatHistoryUser | ChatHistoryToolResult]
|
||||
|
||||
|
||||
class CohereV2ChatResponseMessageToolCallFunction(TypedDict, total=False):
|
||||
|
|
@ -63,10 +63,10 @@ class CohereV2ChatResponseMessageContent(TypedDict):
|
|||
|
||||
class CohereV2ChatResponseMessage(TypedDict, total=False):
|
||||
role: Required[Literal["assistant"]]
|
||||
tool_calls: List[CohereV2ChatResponseMessageToolCall]
|
||||
tool_calls: list[CohereV2ChatResponseMessageToolCall]
|
||||
tool_plan: str
|
||||
content: List[CohereV2ChatResponseMessageContent]
|
||||
citations: List[dict]
|
||||
content: list[CohereV2ChatResponseMessageContent]
|
||||
citations: list[dict]
|
||||
|
||||
|
||||
class CohereV2ChatResponseUsageBilledUnits(TypedDict, total=False):
|
||||
|
|
@ -87,9 +87,9 @@ class CohereV2ChatResponseUsage(TypedDict, total=False):
|
|||
|
||||
|
||||
class CohereV2ChatResponseLogProbs(TypedDict, total=False):
|
||||
token_ids: Required[List[int]]
|
||||
token_ids: Required[list[int]]
|
||||
text: str
|
||||
logprobs: List[float]
|
||||
logprobs: list[float]
|
||||
|
||||
|
||||
class CohereV2ChatResponse(TypedDict):
|
||||
|
|
|
|||
|
|
@ -33,4 +33,4 @@ class httpxSpecialProvider(str, Enum):
|
|||
ModelCostMap = "model_cost_map"
|
||||
|
||||
|
||||
VerifyTypes = Union[str, bool, ssl.SSLContext]
|
||||
VerifyTypes = str | bool | ssl.SSLContext
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
from typing import List
|
||||
|
||||
from typing_extensions import Dict, Required, TypedDict, override
|
||||
from typing_extensions import TypedDict
|
||||
|
||||
from litellm.llms.custom_llm import CustomLLM
|
||||
|
||||
|
|
|
|||
|
|
@ -1,34 +1,27 @@
|
|||
import json
|
||||
from typing import Any, Dict, Final, List, Literal, Optional, Union
|
||||
from typing import Any, Literal
|
||||
|
||||
from pydantic import BaseModel
|
||||
from typing_extensions import (
|
||||
Protocol,
|
||||
Required,
|
||||
Self,
|
||||
TypedDict,
|
||||
TypeGuard,
|
||||
get_origin,
|
||||
override,
|
||||
runtime_checkable,
|
||||
)
|
||||
|
||||
from .openai import ChatCompletionToolCallChunk, ChatCompletionUsageBlock
|
||||
from .openai import ChatCompletionUsageBlock
|
||||
|
||||
|
||||
class GenericStreamingChunk(TypedDict, total=False):
|
||||
text: Required[str]
|
||||
is_finished: Required[bool]
|
||||
finish_reason: Required[Optional[str]]
|
||||
logprobs: Optional[BaseModel]
|
||||
original_chunk: Optional[BaseModel]
|
||||
usage: Optional[BaseModel]
|
||||
finish_reason: Required[str | None]
|
||||
logprobs: BaseModel | None
|
||||
original_chunk: BaseModel | None
|
||||
usage: BaseModel | None
|
||||
|
||||
|
||||
class DatabricksTextContent(TypedDict, total=False):
|
||||
type: Literal["text"]
|
||||
text: Required[str]
|
||||
citations: Optional[List[Dict[str, Any]]]
|
||||
citations: list[dict[str, Any]] | None
|
||||
|
||||
|
||||
class DatabricksReasoningSummary(TypedDict):
|
||||
|
|
@ -39,18 +32,18 @@ class DatabricksReasoningSummary(TypedDict):
|
|||
|
||||
class DatabricksReasoningContent(TypedDict, total=False):
|
||||
type: Literal["reasoning"]
|
||||
summary: Required[List[DatabricksReasoningSummary]]
|
||||
citations: Optional[List[Dict[str, Any]]]
|
||||
summary: Required[list[DatabricksReasoningSummary]]
|
||||
citations: list[dict[str, Any]] | None
|
||||
|
||||
|
||||
AllDatabricksContentListValues = Union[DatabricksTextContent, DatabricksReasoningContent]
|
||||
AllDatabricksContentListValues = DatabricksTextContent | DatabricksReasoningContent
|
||||
|
||||
AllDatabricksContentValues = Union[str, List[AllDatabricksContentListValues]]
|
||||
AllDatabricksContentValues = str | list[AllDatabricksContentListValues]
|
||||
|
||||
|
||||
class DatabricksFunction(TypedDict, total=False):
|
||||
name: Required[str]
|
||||
description: Union[dict, str]
|
||||
description: dict | str
|
||||
parameters: dict
|
||||
strict: bool
|
||||
|
||||
|
|
@ -63,13 +56,13 @@ class DatabricksTool(TypedDict):
|
|||
class DatabricksMessage(TypedDict, total=False):
|
||||
role: Required[str]
|
||||
content: Required[AllDatabricksContentValues]
|
||||
tool_calls: Optional[List[DatabricksTool]]
|
||||
tool_calls: list[DatabricksTool] | None
|
||||
|
||||
|
||||
class DatabricksChoice(TypedDict, total=False):
|
||||
index: Required[int]
|
||||
message: Required[DatabricksMessage]
|
||||
finish_reason: Required[Optional[str]]
|
||||
finish_reason: Required[str | None]
|
||||
extra_fields: str
|
||||
|
||||
|
||||
|
|
@ -78,5 +71,5 @@ class DatabricksResponse(TypedDict):
|
|||
object: str
|
||||
created: int
|
||||
model: str
|
||||
choices: List[DatabricksChoice]
|
||||
choices: list[DatabricksChoice]
|
||||
usage: ChatCompletionUsageBlock
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
from enum import Enum
|
||||
from typing import Any, Dict, Final, List, Literal, Optional
|
||||
from typing import Any, Literal
|
||||
|
||||
from typing_extensions import Required, TypedDict
|
||||
|
||||
|
|
@ -128,7 +128,7 @@ class BidiGenerateContentSetup(TypedDict, total=False):
|
|||
systemInstruction: HttpxContentType
|
||||
"""The system instruction to be used for the realtime session."""
|
||||
|
||||
tools: List[Tools]
|
||||
tools: list[Tools]
|
||||
"""The tools to be used for the realtime session."""
|
||||
|
||||
realtimeInputConfig: BidiGenerateContentRealtimeInputConfig
|
||||
|
|
@ -163,51 +163,51 @@ class GeminiImageGenerationInstance(TypedDict):
|
|||
class GeminiImageGenerationParameters(BaseModel):
|
||||
"""Parameters for Gemini image generation request"""
|
||||
|
||||
sampleCount: Optional[int] = None
|
||||
sampleCount: int | None = None
|
||||
"""Number of images to generate (maps to OpenAI 'n' parameter)"""
|
||||
|
||||
aspectRatio: Optional[str] = None
|
||||
aspectRatio: str | None = None
|
||||
"""Aspect ratio for generated images (e.g., '1:1', '16:9', '9:16', '4:3', '3:4')"""
|
||||
|
||||
imageSize: Optional[str] = None
|
||||
imageSize: str | None = None
|
||||
"""Image size for generated images (e.g., '1K', '2K')"""
|
||||
|
||||
personGeneration: Optional[str] = None
|
||||
personGeneration: str | None = None
|
||||
"""Controls person generation in images"""
|
||||
|
||||
# Additional parameters that might be passed through
|
||||
background: Optional[str] = None
|
||||
background: str | None = None
|
||||
"""Background specification"""
|
||||
|
||||
input_fidelity: Optional[str] = None
|
||||
input_fidelity: str | None = None
|
||||
"""Input fidelity specification"""
|
||||
|
||||
moderation: Optional[str] = None
|
||||
moderation: str | None = None
|
||||
"""Moderation settings"""
|
||||
|
||||
output_compression: Optional[str] = None
|
||||
output_compression: str | None = None
|
||||
"""Output compression settings"""
|
||||
|
||||
output_format: Optional[str] = None
|
||||
output_format: str | None = None
|
||||
"""Output format specification"""
|
||||
|
||||
quality: Optional[str] = None
|
||||
quality: str | None = None
|
||||
"""Quality settings"""
|
||||
|
||||
response_format: Optional[str] = None
|
||||
response_format: str | None = None
|
||||
"""Response format specification"""
|
||||
|
||||
style: Optional[str] = None
|
||||
style: str | None = None
|
||||
"""Style specification"""
|
||||
|
||||
user: Optional[str] = None
|
||||
user: str | None = None
|
||||
"""User specification"""
|
||||
|
||||
|
||||
class GeminiImageGenerationRequest(BaseModel):
|
||||
"""Complete request body for Gemini image generation"""
|
||||
|
||||
instances: List[GeminiImageGenerationInstance]
|
||||
instances: list[GeminiImageGenerationInstance]
|
||||
parameters: GeminiImageGenerationParameters
|
||||
|
||||
|
||||
|
|
@ -221,13 +221,13 @@ class GeminiGeneratedImage(TypedDict):
|
|||
class GeminiImageGenerationPrediction(TypedDict):
|
||||
"""Prediction object containing generated images"""
|
||||
|
||||
generatedImages: List[GeminiGeneratedImage]
|
||||
generatedImages: list[GeminiGeneratedImage]
|
||||
|
||||
|
||||
class GeminiImageGenerationResponse(TypedDict):
|
||||
"""Complete response body from Gemini image generation API"""
|
||||
|
||||
predictions: List[GeminiImageGenerationPrediction]
|
||||
predictions: list[GeminiImageGenerationPrediction]
|
||||
|
||||
|
||||
# Video Generation Types
|
||||
|
|
@ -235,7 +235,7 @@ class GeminiVideoGenerationInstance(TypedDict, total=False):
|
|||
"""Instance data for Gemini video generation request"""
|
||||
|
||||
prompt: Required[str]
|
||||
image: Dict[str, Any]
|
||||
image: dict[str, Any]
|
||||
|
||||
|
||||
class GeminiVideoGenerationParameters(BaseModel):
|
||||
|
|
@ -245,43 +245,43 @@ class GeminiVideoGenerationParameters(BaseModel):
|
|||
See: Veo 3/3.1 parameter guide.
|
||||
"""
|
||||
|
||||
aspectRatio: Optional[str] = None
|
||||
aspectRatio: str | None = None
|
||||
"""Aspect ratio for generated video (e.g., '16:9', '9:16')."""
|
||||
|
||||
durationSeconds: Optional[int] = None
|
||||
durationSeconds: int | None = None
|
||||
"""
|
||||
Length of the generated video in seconds (e.g., 4, 5, 6, 8).
|
||||
Must be 8 when using extension/interpolation or referenceImages.
|
||||
"""
|
||||
|
||||
resolution: Optional[str] = None
|
||||
resolution: str | None = None
|
||||
"""
|
||||
Video resolution (e.g., '720p', '1080p').
|
||||
'1080p' only supports 8s duration; extension only supports '720p'.
|
||||
"""
|
||||
|
||||
negativePrompt: Optional[str] = None
|
||||
negativePrompt: str | None = None
|
||||
"""Text describing what not to include in the video."""
|
||||
|
||||
lastFrame: Optional[Any] = None
|
||||
lastFrame: Any | None = None
|
||||
"""
|
||||
The final image for interpolation video to transition.
|
||||
Should be used with the 'image' parameter.
|
||||
"""
|
||||
|
||||
referenceImages: Optional[list] = None
|
||||
referenceImages: list | None = None
|
||||
"""
|
||||
Up to three images to be used as style/content references.
|
||||
Only supported in Veo 3.1 (list of VideoGenerationReferenceImage objects).
|
||||
"""
|
||||
|
||||
video: Optional[Any] = None
|
||||
video: Any | None = None
|
||||
"""
|
||||
Video to be used for video extension (Video object).
|
||||
Only supported in Veo 3.1 & Veo 3 Fast.
|
||||
"""
|
||||
|
||||
personGeneration: Optional[str] = None
|
||||
personGeneration: str | None = None
|
||||
"""
|
||||
Controls the generation of people.
|
||||
Text-to-video & Extension: "allow_all" only
|
||||
|
|
@ -293,8 +293,8 @@ class GeminiVideoGenerationParameters(BaseModel):
|
|||
class GeminiVideoGenerationRequest(BaseModel):
|
||||
"""Complete request body for Gemini video generation"""
|
||||
|
||||
instances: List[GeminiVideoGenerationInstance]
|
||||
parameters: Optional[GeminiVideoGenerationParameters] = None
|
||||
instances: list[GeminiVideoGenerationInstance]
|
||||
parameters: GeminiVideoGenerationParameters | None = None
|
||||
|
||||
|
||||
# Video Generation Operation Response Types
|
||||
|
|
@ -315,7 +315,7 @@ class GeminiGeneratedVideoSample(BaseModel):
|
|||
class GeminiGenerateVideoResponse(BaseModel):
|
||||
"""Generate video response containing the samples"""
|
||||
|
||||
generatedSamples: List[GeminiGeneratedVideoSample]
|
||||
generatedSamples: list[GeminiGeneratedVideoSample]
|
||||
"""List of generated video samples"""
|
||||
|
||||
|
||||
|
|
@ -329,9 +329,9 @@ class GeminiOperationResponse(BaseModel):
|
|||
class GeminiOperationMetadata(BaseModel):
|
||||
"""Metadata for the operation"""
|
||||
|
||||
createTime: Optional[str] = None
|
||||
createTime: str | None = None
|
||||
"""Creation timestamp"""
|
||||
model: Optional[str] = None
|
||||
model: str | None = None
|
||||
"""Model used for generation"""
|
||||
|
||||
|
||||
|
|
@ -348,11 +348,11 @@ class GeminiLongRunningOperationResponse(BaseModel):
|
|||
done: bool = False
|
||||
"""Whether the operation is complete"""
|
||||
|
||||
metadata: Optional[GeminiOperationMetadata] = None
|
||||
metadata: GeminiOperationMetadata | None = None
|
||||
"""Operation metadata"""
|
||||
|
||||
response: Optional[GeminiOperationResponse] = None
|
||||
response: GeminiOperationResponse | None = None
|
||||
"""Response object when operation is complete"""
|
||||
|
||||
error: Optional[Dict[str, Any]] = None
|
||||
error: dict[str, Any] | None = None
|
||||
"""Error details if operation failed"""
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@ Type definitions for LangGraph API.
|
|||
LangGraph provides a streaming and non-streaming API for running agents.
|
||||
"""
|
||||
|
||||
from typing import Any, Dict, List, Optional
|
||||
from typing import Any, Literal
|
||||
|
||||
from typing_extensions import Literal, TypedDict
|
||||
from typing_extensions import TypedDict
|
||||
|
||||
|
||||
# Request Types
|
||||
|
|
@ -20,7 +20,7 @@ class LangGraphMessage(TypedDict, total=False):
|
|||
class LangGraphInput(TypedDict, total=False):
|
||||
"""Input structure for LangGraph request."""
|
||||
|
||||
messages: List[LangGraphMessage]
|
||||
messages: list[LangGraphMessage]
|
||||
|
||||
|
||||
class LangGraphRequest(TypedDict, total=False):
|
||||
|
|
@ -28,9 +28,9 @@ class LangGraphRequest(TypedDict, total=False):
|
|||
|
||||
assistant_id: str
|
||||
input: LangGraphInput
|
||||
stream_mode: Optional[str]
|
||||
config: Optional[Dict[str, Any]]
|
||||
metadata: Optional[Dict[str, Any]]
|
||||
stream_mode: str | None
|
||||
config: dict[str, Any] | None
|
||||
metadata: dict[str, Any] | None
|
||||
|
||||
|
||||
# Response Types - Streaming
|
||||
|
|
@ -47,15 +47,15 @@ class LangGraphResponseMessage(TypedDict, total=False):
|
|||
|
||||
type: str
|
||||
content: str
|
||||
id: Optional[str]
|
||||
name: Optional[str]
|
||||
id: str | None
|
||||
name: str | None
|
||||
|
||||
|
||||
class LangGraphResponse(TypedDict, total=False):
|
||||
"""Non-streaming response structure from LangGraph."""
|
||||
|
||||
messages: List[LangGraphResponseMessage]
|
||||
values: Dict[str, Any]
|
||||
messages: list[LangGraphResponseMessage]
|
||||
values: dict[str, Any]
|
||||
|
||||
|
||||
# Parsed response for internal use
|
||||
|
|
@ -64,4 +64,4 @@ class LangGraphParsedResponse(TypedDict):
|
|||
|
||||
content: str
|
||||
role: str
|
||||
usage: Optional[Dict[str, int]]
|
||||
usage: dict[str, int] | None
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
from typing import List, Literal, Optional, Union
|
||||
from typing import Literal
|
||||
|
||||
from typing_extensions import TypedDict
|
||||
|
||||
|
||||
class FunctionCall(TypedDict):
|
||||
name: Optional[str]
|
||||
arguments: Optional[Union[str, dict]]
|
||||
name: str | None
|
||||
arguments: str | dict | None
|
||||
|
||||
|
||||
class MistralToolCallMessage(TypedDict):
|
||||
id: Optional[str]
|
||||
id: str | None
|
||||
type: Literal["function"]
|
||||
function: Optional[FunctionCall]
|
||||
function: FunctionCall | None
|
||||
|
||||
|
||||
class MistralTextBlock(TypedDict):
|
||||
|
|
@ -21,4 +21,4 @@ class MistralTextBlock(TypedDict):
|
|||
|
||||
class MistralThinkingBlock(TypedDict):
|
||||
type: Literal["thinking"]
|
||||
thinking: List[MistralTextBlock]
|
||||
thinking: list[MistralTextBlock]
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from enum import Enum
|
||||
from typing import Any, Dict, Final, List, Literal, Optional, Union
|
||||
from typing import Any, Literal
|
||||
|
||||
from pydantic import BaseModel, SerializeAsAny
|
||||
|
||||
|
|
@ -24,8 +24,6 @@ class OCIVendors(Enum):
|
|||
class OCIContentPart(BaseModel):
|
||||
"""Base model for content parts in an OCI message."""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class OCITextContentPart(OCIContentPart):
|
||||
"""Text content part for the OCI API."""
|
||||
|
|
@ -38,7 +36,7 @@ class OCIImageUrl(BaseModel):
|
|||
"""ImageUrl object for OCI API. See: https://docs.oracle.com/en-us/iaas/tools/python/latest/api/generative_ai_inference/models/oci.generative_ai_inference.models.ImageUrl.html"""
|
||||
|
||||
url: str
|
||||
detail: Optional[Literal["AUTO", "HIGH", "LOW"]] = None
|
||||
detail: Literal["AUTO", "HIGH", "LOW"] | None = None
|
||||
|
||||
|
||||
class OCIImageContentPart(OCIContentPart):
|
||||
|
|
@ -48,7 +46,7 @@ class OCIImageContentPart(OCIContentPart):
|
|||
imageUrl: OCIImageUrl
|
||||
|
||||
|
||||
OCIContentPartUnion = Union[OCITextContentPart, OCIImageContentPart]
|
||||
OCIContentPartUnion = OCITextContentPart | OCIImageContentPart
|
||||
|
||||
# --- Models for Tools and Tool Calls ---
|
||||
|
||||
|
|
@ -56,7 +54,7 @@ OCIContentPartUnion = Union[OCITextContentPart, OCIImageContentPart]
|
|||
class OCIToolCall(BaseModel):
|
||||
"""Represents a tool call made by the model."""
|
||||
|
||||
id: Optional[str] = None # absent in some provider responses (e.g. Google via OCI)
|
||||
id: str | None = None # absent in some provider responses (e.g. Google via OCI)
|
||||
type: Literal["FUNCTION"] = "FUNCTION"
|
||||
name: str
|
||||
arguments: str # Arguments should be a JSON-serialized string
|
||||
|
|
@ -66,9 +64,9 @@ class OCIToolDefinition(BaseModel):
|
|||
"""Defines a tool that can be used by the model."""
|
||||
|
||||
type: Literal["FUNCTION"] = "FUNCTION"
|
||||
name: Optional[str] = None
|
||||
description: Optional[str] = None
|
||||
parameters: Optional[dict] = None
|
||||
name: str | None = None
|
||||
description: str | None = None
|
||||
parameters: dict | None = None
|
||||
|
||||
|
||||
# --- Message Models (Request and Response) ---
|
||||
|
|
@ -78,9 +76,9 @@ class OCIMessage(BaseModel):
|
|||
"""Model for a single message in the request/response payload."""
|
||||
|
||||
role: OCIRoles
|
||||
content: Optional[List[OCIContentPartUnion]] = None
|
||||
toolCalls: Optional[List[OCIToolCall]] = None
|
||||
toolCallId: Optional[str] = None
|
||||
content: list[OCIContentPartUnion] | None = None
|
||||
toolCalls: list[OCIToolCall] | None = None
|
||||
toolCallId: str | None = None
|
||||
|
||||
|
||||
# --- Request Payload Models ---
|
||||
|
|
@ -90,35 +88,35 @@ class OCIChatRequestPayload(BaseModel):
|
|||
"""Internal 'chatRequest' payload for the OCI API."""
|
||||
|
||||
apiFormat: str
|
||||
messages: List[OCIMessage]
|
||||
tools: Optional[List[OCIToolDefinition]] = None
|
||||
messages: list[OCIMessage]
|
||||
tools: list[OCIToolDefinition] | None = None
|
||||
isStream: bool = False
|
||||
numGenerations: Optional[int] = None
|
||||
maxTokens: Optional[int] = None
|
||||
numGenerations: int | None = None
|
||||
maxTokens: int | None = None
|
||||
# GPT-5+ on OCI rejects maxTokens and requires maxCompletionTokens.
|
||||
maxCompletionTokens: Optional[int] = None
|
||||
temperature: Optional[float] = None
|
||||
topP: Optional[float] = None
|
||||
stop: Optional[List[str]] = None
|
||||
seed: Optional[int] = None
|
||||
frequencyPenalty: Optional[float] = None
|
||||
presencePenalty: Optional[float] = None
|
||||
maxCompletionTokens: int | None = None
|
||||
temperature: float | None = None
|
||||
topP: float | None = None
|
||||
stop: list[str] | None = None
|
||||
seed: int | None = None
|
||||
frequencyPenalty: float | None = None
|
||||
presencePenalty: float | None = None
|
||||
# Reasoning-token budget knob (OCI: NONE/MINIMAL/LOW/MEDIUM/HIGH).
|
||||
# Honoured by GPT-5 family, Gemini 2.5, Grok reasoning variants,
|
||||
# Cohere Command-A-Reasoning. Ignored by non-reasoning models.
|
||||
reasoningEffort: Optional[str] = None
|
||||
responseFormat: Optional[Dict[str, Any]] = None
|
||||
toolChoice: Optional[Union[str, Dict[str, Any]]] = None
|
||||
logitBias: Optional[Dict[str, Any]] = None
|
||||
logProbs: Optional[int] = None
|
||||
reasoningEffort: str | None = None
|
||||
responseFormat: dict[str, Any] | None = None
|
||||
toolChoice: str | dict[str, Any] | None = None
|
||||
logitBias: dict[str, Any] | None = None
|
||||
logProbs: int | None = None
|
||||
|
||||
|
||||
class OCIServingMode(BaseModel):
|
||||
"""Defines the serving mode and the model to be used."""
|
||||
|
||||
servingType: str
|
||||
endpointId: Optional[str] = None
|
||||
modelId: Optional[str] = None
|
||||
endpointId: str | None = None
|
||||
modelId: str | None = None
|
||||
|
||||
|
||||
class OCICompletionPayload(BaseModel):
|
||||
|
|
@ -126,7 +124,7 @@ class OCICompletionPayload(BaseModel):
|
|||
|
||||
compartmentId: str
|
||||
servingMode: OCIServingMode
|
||||
chatRequest: Union[OCIChatRequestPayload, CohereChatRequest]
|
||||
chatRequest: OCIChatRequestPayload | CohereChatRequest
|
||||
|
||||
|
||||
# --- API Response Models (Non-streaming) ---
|
||||
|
|
@ -135,14 +133,14 @@ class OCICompletionPayload(BaseModel):
|
|||
class OCICompletionTokenDetails(BaseModel):
|
||||
"""Completion token details in the OCI response."""
|
||||
|
||||
acceptedPredictionTokens: Optional[int] = None
|
||||
reasoningTokens: Optional[int] = None
|
||||
acceptedPredictionTokens: int | None = None
|
||||
reasoningTokens: int | None = None
|
||||
|
||||
|
||||
class OCIPromptTokensDetails(BaseModel):
|
||||
"""Prompt token details in the OCI response."""
|
||||
|
||||
cachedTokens: Optional[int] = None
|
||||
cachedTokens: int | None = None
|
||||
|
||||
|
||||
class OCIResponseUsage(BaseModel):
|
||||
|
|
@ -151,10 +149,10 @@ class OCIResponseUsage(BaseModel):
|
|||
promptTokens: int
|
||||
# completionTokens may be absent for reasoning models when all the output
|
||||
# budget is consumed by reasoning tokens before any visible content is produced.
|
||||
completionTokens: Optional[int] = None
|
||||
completionTokens: int | None = None
|
||||
totalTokens: int
|
||||
completionTokensDetails: Optional[OCICompletionTokenDetails] = None
|
||||
promptTokensDetails: Optional[OCIPromptTokensDetails] = None
|
||||
completionTokensDetails: OCICompletionTokenDetails | None = None
|
||||
promptTokensDetails: OCIPromptTokensDetails | None = None
|
||||
|
||||
|
||||
class OCIResponseChoice(BaseModel):
|
||||
|
|
@ -163,9 +161,9 @@ class OCIResponseChoice(BaseModel):
|
|||
index: int
|
||||
# message is absent when a reasoning model exhausts max_tokens in the
|
||||
# reasoning phase without producing any visible content.
|
||||
message: Optional[OCIMessage] = None
|
||||
finishReason: Optional[str] = None
|
||||
logprobs: Optional[Dict[str, Any]] = None
|
||||
message: OCIMessage | None = None
|
||||
finishReason: str | None = None
|
||||
logprobs: dict[str, Any] | None = None
|
||||
|
||||
|
||||
class OCIChatResponse(BaseModel):
|
||||
|
|
@ -173,7 +171,7 @@ class OCIChatResponse(BaseModel):
|
|||
|
||||
apiFormat: str
|
||||
timeCreated: str
|
||||
choices: List[OCIResponseChoice]
|
||||
choices: list[OCIResponseChoice]
|
||||
usage: OCIResponseUsage
|
||||
|
||||
|
||||
|
|
@ -191,18 +189,18 @@ class OCICompletionResponse(BaseModel):
|
|||
class OCIStreamDelta(BaseModel):
|
||||
"""The content delta in a streaming chunk."""
|
||||
|
||||
content: Optional[List[OCIContentPartUnion]] = None
|
||||
role: Optional[str] = None
|
||||
toolCalls: Optional[List[OCIToolCall]] = None
|
||||
content: list[OCIContentPartUnion] | None = None
|
||||
role: str | None = None
|
||||
toolCalls: list[OCIToolCall] | None = None
|
||||
|
||||
|
||||
class OCIStreamChunk(BaseModel):
|
||||
"""Model for a single SSE event chunk from OCI."""
|
||||
|
||||
finishReason: Optional[str] = None
|
||||
message: Optional[OCIStreamDelta] = None
|
||||
pad: Optional[str] = None
|
||||
index: Optional[int] = None
|
||||
finishReason: str | None = None
|
||||
message: OCIStreamDelta | None = None
|
||||
pad: str | None = None
|
||||
index: int | None = None
|
||||
|
||||
|
||||
# --- Cohere-Specific Models ---
|
||||
|
|
@ -212,20 +210,20 @@ class CohereStreamChunk(BaseModel):
|
|||
"""Model for a single SSE event chunk from OCI Cohere API."""
|
||||
|
||||
apiFormat: str
|
||||
text: Optional[str] = None
|
||||
chatHistory: Optional[List[CohereMessage]] = None
|
||||
finishReason: Optional[str] = None
|
||||
toolCalls: Optional[List[CohereToolCall]] = None
|
||||
pad: Optional[str] = None
|
||||
index: Optional[int] = None
|
||||
text: str | None = None
|
||||
chatHistory: list[CohereMessage] | None = None
|
||||
finishReason: str | None = None
|
||||
toolCalls: list[CohereToolCall] | None = None
|
||||
pad: str | None = None
|
||||
index: int | None = None
|
||||
|
||||
|
||||
class CohereMessage(BaseModel):
|
||||
"""Base model for Cohere messages."""
|
||||
|
||||
role: str
|
||||
message: Optional[str] = None
|
||||
toolCalls: Optional[List[CohereToolCall]] = None
|
||||
message: str | None = None
|
||||
toolCalls: list[CohereToolCall] | None = None
|
||||
|
||||
|
||||
class CohereUserMessage(CohereMessage):
|
||||
|
|
@ -254,7 +252,7 @@ class CohereToolMessage(CohereMessage):
|
|||
"""
|
||||
|
||||
role: Literal["TOOL"] = "TOOL"
|
||||
toolResults: List[CohereToolResult]
|
||||
toolResults: list[CohereToolResult]
|
||||
|
||||
|
||||
class CohereParameterDefinition(BaseModel):
|
||||
|
|
@ -270,14 +268,14 @@ class CohereTool(BaseModel):
|
|||
|
||||
name: str
|
||||
description: str
|
||||
parameterDefinitions: Dict[str, CohereParameterDefinition]
|
||||
parameterDefinitions: dict[str, CohereParameterDefinition]
|
||||
|
||||
|
||||
class CohereToolCall(BaseModel):
|
||||
"""Tool call made by Cohere model."""
|
||||
|
||||
name: str
|
||||
parameters: Dict[str, Any]
|
||||
parameters: dict[str, Any]
|
||||
|
||||
|
||||
class CohereToolResult(BaseModel):
|
||||
|
|
@ -288,7 +286,7 @@ class CohereToolResult(BaseModel):
|
|||
"""
|
||||
|
||||
call: CohereToolCall
|
||||
outputs: List[Dict[str, Any]]
|
||||
outputs: list[dict[str, Any]]
|
||||
|
||||
|
||||
class CohereChatRequest(BaseModel):
|
||||
|
|
@ -303,16 +301,16 @@ class CohereChatRequest(BaseModel):
|
|||
# on ``CohereToolMessage``) when this request is serialized via ``model_dump``.
|
||||
# Without it, Pydantic v2 would serialize each element using the declared
|
||||
# ``CohereMessage`` schema and silently drop subclass fields.
|
||||
chatHistory: Optional[List[SerializeAsAny[CohereMessage]]] = None
|
||||
maxTokens: Optional[int] = None
|
||||
temperature: Optional[float] = None
|
||||
topP: Optional[float] = None
|
||||
topK: Optional[int] = None
|
||||
frequencyPenalty: Optional[float] = None
|
||||
presencePenalty: Optional[float] = None
|
||||
stopSequences: Optional[List[str]] = None
|
||||
seed: Optional[int] = None
|
||||
tools: Optional[List[CohereTool]] = None
|
||||
chatHistory: list[SerializeAsAny[CohereMessage]] | None = None
|
||||
maxTokens: int | None = None
|
||||
temperature: float | None = None
|
||||
topP: float | None = None
|
||||
topK: int | None = None
|
||||
frequencyPenalty: float | None = None
|
||||
presencePenalty: float | None = None
|
||||
stopSequences: list[str] | None = None
|
||||
seed: int | None = None
|
||||
tools: list[CohereTool] | None = None
|
||||
# NOTE: OCI's Cohere chat endpoint does not accept ``toolChoice`` — see
|
||||
# ``OCIChatConfig.openai_to_oci_cohere_param_map`` which marks
|
||||
# ``tool_choice`` as unsupported. The field is intentionally absent here
|
||||
|
|
@ -320,22 +318,22 @@ class CohereChatRequest(BaseModel):
|
|||
# OCI Cohere responseFormat is {"type": "TEXT" | "JSON_OBJECT", "schema"?: ...};
|
||||
# there is no JSON_SCHEMA type. The shape is built in
|
||||
# OCIChatConfig._normalize_response_format.
|
||||
responseFormat: Optional[Dict[str, Any]] = None
|
||||
preambleOverride: Optional[str] = None
|
||||
documents: Optional[List[Dict[str, Any]]] = None
|
||||
searchQueriesOnly: Optional[bool] = None
|
||||
searchEntryPoint: Optional[str] = None
|
||||
grounding: Optional[Dict[str, Any]] = None
|
||||
isEcho: Optional[bool] = None
|
||||
isSearchQueriesOnly: Optional[bool] = None
|
||||
isRawPrompting: Optional[bool] = None
|
||||
isForceSingleStep: Optional[bool] = None
|
||||
promptTruncation: Optional[str] = None
|
||||
safetyMode: Optional[str] = None
|
||||
citationQuality: Optional[str] = None
|
||||
maxInputTokens: Optional[int] = None
|
||||
isStream: Optional[bool] = None
|
||||
streamOptions: Optional[Dict[str, Any]] = None
|
||||
responseFormat: dict[str, Any] | None = None
|
||||
preambleOverride: str | None = None
|
||||
documents: list[dict[str, Any]] | None = None
|
||||
searchQueriesOnly: bool | None = None
|
||||
searchEntryPoint: str | None = None
|
||||
grounding: dict[str, Any] | None = None
|
||||
isEcho: bool | None = None
|
||||
isSearchQueriesOnly: bool | None = None
|
||||
isRawPrompting: bool | None = None
|
||||
isForceSingleStep: bool | None = None
|
||||
promptTruncation: str | None = None
|
||||
safetyMode: str | None = None
|
||||
citationQuality: str | None = None
|
||||
maxInputTokens: int | None = None
|
||||
isStream: bool | None = None
|
||||
streamOptions: dict[str, Any] | None = None
|
||||
|
||||
|
||||
class CohereUsage(BaseModel):
|
||||
|
|
@ -344,8 +342,8 @@ class CohereUsage(BaseModel):
|
|||
promptTokens: int
|
||||
completionTokens: int
|
||||
totalTokens: int
|
||||
promptTokensDetails: Optional[Dict[str, Any]] = None
|
||||
completionTokensDetails: Optional[Dict[str, Any]] = None
|
||||
promptTokensDetails: dict[str, Any] | None = None
|
||||
completionTokensDetails: dict[str, Any] | None = None
|
||||
|
||||
|
||||
class CohereCitation(BaseModel):
|
||||
|
|
@ -354,7 +352,7 @@ class CohereCitation(BaseModel):
|
|||
start: int
|
||||
end: int
|
||||
text: str
|
||||
document_ids: List[str]
|
||||
document_ids: list[str]
|
||||
|
||||
|
||||
class CohereSearchQuery(BaseModel):
|
||||
|
|
@ -375,18 +373,18 @@ class CohereChatResponse(BaseModel):
|
|||
# via ``handle_cohere_response``'s ``elif oci_finish_reason is not None``
|
||||
# fallback instead of crashing Pydantic validation. Mirrors
|
||||
# ``CohereStreamChunk.finishReason`` which has always been ``Optional[str]``.
|
||||
finishReason: Optional[str] = None
|
||||
finishReason: str | None = None
|
||||
|
||||
# Optional fields
|
||||
chatHistory: Optional[List[CohereMessage]] = None
|
||||
citations: Optional[List[CohereCitation]] = None
|
||||
documents: Optional[List[Dict[str, Any]]] = None
|
||||
errorMessage: Optional[str] = None
|
||||
isSearchRequired: Optional[bool] = None
|
||||
prompt: Optional[str] = None
|
||||
searchQueries: Optional[List[CohereSearchQuery]] = None
|
||||
toolCalls: Optional[List[CohereToolCall]] = None
|
||||
usage: Optional[CohereUsage] = None
|
||||
chatHistory: list[CohereMessage] | None = None
|
||||
citations: list[CohereCitation] | None = None
|
||||
documents: list[dict[str, Any]] | None = None
|
||||
errorMessage: str | None = None
|
||||
isSearchRequired: bool | None = None
|
||||
prompt: str | None = None
|
||||
searchQueries: list[CohereSearchQuery] | None = None
|
||||
toolCalls: list[CohereToolCall] | None = None
|
||||
usage: CohereUsage | None = None
|
||||
|
||||
|
||||
class CohereChatDetails(BaseModel):
|
||||
|
|
@ -415,10 +413,10 @@ class OCIEmbedRequest(BaseModel):
|
|||
|
||||
compartmentId: str
|
||||
servingMode: OCIServingMode
|
||||
inputs: List[str]
|
||||
inputType: Optional[str] = None # SEARCH_DOCUMENT | SEARCH_QUERY | CLASSIFICATION | CLUSTERING | IMAGE
|
||||
truncate: Optional[str] = "END" # NONE | START | END
|
||||
outputDimensions: Optional[int] = None # cohere.embed-v4.0+; valid: 256, 512, 1024, 1536
|
||||
inputs: list[str]
|
||||
inputType: str | None = None # SEARCH_DOCUMENT | SEARCH_QUERY | CLASSIFICATION | CLUSTERING | IMAGE
|
||||
truncate: str | None = "END" # NONE | START | END
|
||||
outputDimensions: int | None = None # cohere.embed-v4.0+; valid: 256, 512, 1024, 1536
|
||||
|
||||
|
||||
class OCIEmbedUsage(BaseModel):
|
||||
|
|
@ -429,11 +427,11 @@ class OCIEmbedUsage(BaseModel):
|
|||
class OCIEmbedResponse(BaseModel):
|
||||
"""Response body from POST /20231130/actions/embedText."""
|
||||
|
||||
id: Optional[str] = None # present in the official SDK response
|
||||
embeddings: List[List[float]]
|
||||
id: str | None = None # present in the official SDK response
|
||||
embeddings: list[list[float]]
|
||||
modelId: str
|
||||
modelVersion: str
|
||||
# OCI returns per-input token counts in inputTextTokenCounts (summed for total usage)
|
||||
inputTextTokenCounts: Optional[List[int]] = None
|
||||
inputTextTokenCounts: list[int] | None = None
|
||||
# Some deployments may return a usage object instead
|
||||
usage: Optional[OCIEmbedUsage] = None
|
||||
usage: OCIEmbedUsage | None = None
|
||||
|
|
|
|||
|
|
@ -1,16 +1,6 @@
|
|||
import json
|
||||
from typing import Any, List, Optional, Union
|
||||
|
||||
from pydantic import BaseModel
|
||||
from typing_extensions import (
|
||||
Protocol,
|
||||
Required,
|
||||
Self,
|
||||
TypedDict,
|
||||
TypeGuard,
|
||||
get_origin,
|
||||
override,
|
||||
runtime_checkable,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -27,14 +17,14 @@ class OllamaToolCall(TypedDict):
|
|||
|
||||
class OllamaVisionModelObject(TypedDict):
|
||||
prompt: str
|
||||
images: List[str]
|
||||
images: list[str]
|
||||
|
||||
|
||||
class OllamaChatCompletionMessage(TypedDict, total=False):
|
||||
role: Required[str]
|
||||
content: str
|
||||
thinking: str
|
||||
images: List[str]
|
||||
tool_calls: List[OllamaToolCall]
|
||||
images: list[str]
|
||||
tool_calls: list[OllamaToolCall]
|
||||
tool_name: str
|
||||
tool_call_id: str
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -2,9 +2,9 @@
|
|||
Type definitions for OpenAI Evals API
|
||||
"""
|
||||
|
||||
from typing import Any, Dict, Final, List, Literal, Optional, Union
|
||||
from typing import Any, Literal
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic import BaseModel
|
||||
from typing_extensions import Required, TypedDict
|
||||
|
||||
|
||||
|
|
@ -15,10 +15,10 @@ class DataSourceConfigCustom(TypedDict, total=False):
|
|||
type: Required[Literal["custom"]]
|
||||
"""Data source type - custom"""
|
||||
|
||||
item_schema: Required[Dict[str, Any]]
|
||||
item_schema: Required[dict[str, Any]]
|
||||
"""JSON schema describing the structure of each row in the dataset"""
|
||||
|
||||
include_sample_schema: Optional[bool]
|
||||
include_sample_schema: bool | None
|
||||
"""Whether eval expects sample schema population"""
|
||||
|
||||
|
||||
|
|
@ -28,7 +28,7 @@ class DataSourceConfigLogs(TypedDict, total=False):
|
|||
type: Required[Literal["logs"]]
|
||||
"""Data source type - logs"""
|
||||
|
||||
metadata: Optional[Dict[str, Any]]
|
||||
metadata: dict[str, Any] | None
|
||||
"""Optional metadata for filtering logs"""
|
||||
|
||||
|
||||
|
|
@ -38,11 +38,11 @@ class DataSourceConfigStoredCompletions(TypedDict, total=False):
|
|||
type: Required[Literal["stored_completions"]]
|
||||
"""Data source type - stored_completions (deprecated)"""
|
||||
|
||||
metadata: Optional[Dict[str, Any]]
|
||||
metadata: dict[str, Any] | None
|
||||
"""Optional metadata for filtering stored completions"""
|
||||
|
||||
|
||||
DataSourceConfig = Union[DataSourceConfigCustom, DataSourceConfigLogs, DataSourceConfigStoredCompletions]
|
||||
DataSourceConfig = DataSourceConfigCustom | DataSourceConfigLogs | DataSourceConfigStoredCompletions
|
||||
|
||||
|
||||
class LLMAsJudgeGraderConfig(TypedDict, total=False):
|
||||
|
|
@ -51,10 +51,10 @@ class LLMAsJudgeGraderConfig(TypedDict, total=False):
|
|||
type: Required[Literal["llm_as_judge"]]
|
||||
"""Grader type - LLM as judge"""
|
||||
|
||||
model: Optional[str]
|
||||
model: str | None
|
||||
"""Model to use as judge (e.g., 'gpt-4')"""
|
||||
|
||||
prompt: Optional[str]
|
||||
prompt: str | None
|
||||
"""Custom prompt for the judge model"""
|
||||
|
||||
|
||||
|
|
@ -64,7 +64,7 @@ class GroundTruthGraderConfig(TypedDict, total=False):
|
|||
type: Required[Literal["ground_truth"]]
|
||||
"""Grader type - ground truth comparison"""
|
||||
|
||||
metric: Optional[Literal["exact_match", "f1_score", "bleu"]]
|
||||
metric: Literal["exact_match", "f1_score", "bleu"] | None
|
||||
"""Metric to use for comparison"""
|
||||
|
||||
|
||||
|
|
@ -78,51 +78,51 @@ class CustomGraderConfig(TypedDict, total=False):
|
|||
"""ID of the custom grading function"""
|
||||
|
||||
|
||||
GraderConfig = Union[LLMAsJudgeGraderConfig, GroundTruthGraderConfig, CustomGraderConfig]
|
||||
GraderConfig = LLMAsJudgeGraderConfig | GroundTruthGraderConfig | CustomGraderConfig
|
||||
|
||||
|
||||
class CreateEvalRequest(TypedDict, total=False):
|
||||
"""Request parameters for creating an evaluation"""
|
||||
|
||||
name: Optional[str]
|
||||
name: str | None
|
||||
"""The name of the evaluation"""
|
||||
|
||||
data_source_config: Required[DataSourceConfig]
|
||||
"""Configuration for the data source"""
|
||||
|
||||
testing_criteria: Required[List[GraderConfig]]
|
||||
testing_criteria: Required[list[GraderConfig]]
|
||||
"""List of graders for all eval runs"""
|
||||
|
||||
metadata: Optional[Dict[str, Any]]
|
||||
metadata: dict[str, Any] | None
|
||||
"""Set of 16 key-value pairs that can be attached to an object (max 64 char keys, 512 char values)"""
|
||||
|
||||
|
||||
class UpdateEvalRequest(TypedDict, total=False):
|
||||
"""Request parameters for updating an evaluation"""
|
||||
|
||||
name: Optional[str]
|
||||
name: str | None
|
||||
"""Updated name"""
|
||||
|
||||
metadata: Optional[Dict[str, Any]]
|
||||
metadata: dict[str, Any] | None
|
||||
"""Updated metadata"""
|
||||
|
||||
|
||||
class ListEvalsParams(TypedDict, total=False):
|
||||
"""Query parameters for listing evaluations"""
|
||||
|
||||
limit: Optional[int]
|
||||
limit: int | None
|
||||
"""Number of results to return per page. Maximum value is 100. Defaults to 20."""
|
||||
|
||||
after: Optional[str]
|
||||
after: str | None
|
||||
"""Cursor for pagination - returns evals after this ID"""
|
||||
|
||||
before: Optional[str]
|
||||
before: str | None
|
||||
"""Cursor for pagination - returns evals before this ID"""
|
||||
|
||||
order: Optional[Literal["asc", "desc"]]
|
||||
order: Literal["asc", "desc"] | None
|
||||
"""Sort order for results. Defaults to 'desc'."""
|
||||
|
||||
order_by: Optional[Literal["created_at", "updated_at"]]
|
||||
order_by: Literal["created_at", "updated_at"] | None
|
||||
"""Field to sort by. Defaults to 'created_at'."""
|
||||
|
||||
|
||||
|
|
@ -139,19 +139,19 @@ class Eval(BaseModel):
|
|||
created_at: int
|
||||
"""Unix timestamp of when the evaluation was created"""
|
||||
|
||||
updated_at: Optional[int] = None
|
||||
updated_at: int | None = None
|
||||
"""Unix timestamp of when the evaluation was last updated"""
|
||||
|
||||
name: Optional[str] = None
|
||||
name: str | None = None
|
||||
"""The name of the evaluation"""
|
||||
|
||||
data_source_config: Dict[str, Any]
|
||||
data_source_config: dict[str, Any]
|
||||
"""Configuration for the data source"""
|
||||
|
||||
testing_criteria: List[Dict[str, Any]]
|
||||
testing_criteria: list[dict[str, Any]]
|
||||
"""List of graders for the evaluation"""
|
||||
|
||||
metadata: Optional[Dict[str, Any]] = None
|
||||
metadata: dict[str, Any] | None = None
|
||||
"""Additional metadata"""
|
||||
|
||||
|
||||
|
|
@ -161,13 +161,13 @@ class ListEvalsResponse(BaseModel):
|
|||
object: str = "list"
|
||||
"""Object type, always 'list'"""
|
||||
|
||||
data: List[Eval]
|
||||
data: list[Eval]
|
||||
"""List of evaluations"""
|
||||
|
||||
first_id: Optional[str] = None
|
||||
first_id: str | None = None
|
||||
"""ID of the first evaluation in the list"""
|
||||
|
||||
last_id: Optional[str] = None
|
||||
last_id: str | None = None
|
||||
"""ID of the last evaluation in the list"""
|
||||
|
||||
has_more: bool = False
|
||||
|
|
@ -227,11 +227,11 @@ class DataSourceInlineConfig(TypedDict, total=False):
|
|||
type: Required[Literal["inline"]]
|
||||
"""Data source type - inline"""
|
||||
|
||||
samples: Required[List[Dict[str, Any]]]
|
||||
samples: Required[list[dict[str, Any]]]
|
||||
"""List of inline samples to use for the run"""
|
||||
|
||||
|
||||
RunDataSourceConfig = Union[DataSourceDatasetConfig, DataSourceSampleSetConfig, DataSourceInlineConfig]
|
||||
RunDataSourceConfig = DataSourceDatasetConfig | DataSourceSampleSetConfig | DataSourceInlineConfig
|
||||
|
||||
|
||||
class CompletionConfig(TypedDict, total=False):
|
||||
|
|
@ -240,48 +240,48 @@ class CompletionConfig(TypedDict, total=False):
|
|||
model: Required[str]
|
||||
"""Model to use for completions"""
|
||||
|
||||
temperature: Optional[float]
|
||||
temperature: float | None
|
||||
"""Sampling temperature (0-2)"""
|
||||
|
||||
max_tokens: Optional[int]
|
||||
max_tokens: int | None
|
||||
"""Maximum tokens to generate"""
|
||||
|
||||
top_p: Optional[float]
|
||||
top_p: float | None
|
||||
"""Nucleus sampling parameter"""
|
||||
|
||||
frequency_penalty: Optional[float]
|
||||
frequency_penalty: float | None
|
||||
"""Frequency penalty (-2.0 to 2.0)"""
|
||||
|
||||
presence_penalty: Optional[float]
|
||||
presence_penalty: float | None
|
||||
"""Presence penalty (-2.0 to 2.0)"""
|
||||
|
||||
|
||||
class CreateRunRequest(TypedDict, total=False):
|
||||
"""Request parameters for creating a run"""
|
||||
|
||||
data_source: Required[Dict[str, Any]]
|
||||
data_source: Required[dict[str, Any]]
|
||||
"""Data source configuration for the run (can be jsonl, completions, or responses type)"""
|
||||
|
||||
name: Optional[str]
|
||||
name: str | None
|
||||
"""Optional name for the run"""
|
||||
|
||||
metadata: Optional[Dict[str, Any]]
|
||||
metadata: dict[str, Any] | None
|
||||
"""Optional metadata for the run"""
|
||||
|
||||
|
||||
class ListRunsParams(TypedDict, total=False):
|
||||
"""Query parameters for listing runs"""
|
||||
|
||||
limit: Optional[int]
|
||||
limit: int | None
|
||||
"""Number of results to return per page. Maximum value is 100. Defaults to 20."""
|
||||
|
||||
after: Optional[str]
|
||||
after: str | None
|
||||
"""Cursor for pagination - returns runs after this ID"""
|
||||
|
||||
before: Optional[str]
|
||||
before: str | None
|
||||
"""Cursor for pagination - returns runs before this ID"""
|
||||
|
||||
order: Optional[Literal["asc", "desc"]]
|
||||
order: Literal["asc", "desc"] | None
|
||||
"""Sort order for results. Defaults to 'desc'."""
|
||||
|
||||
|
||||
|
|
@ -311,7 +311,7 @@ class PerTestingCriteriaResult(BaseModel):
|
|||
result_counts: ResultCounts
|
||||
"""Result counts for this criteria"""
|
||||
|
||||
average_score: Optional[float] = None
|
||||
average_score: float | None = None
|
||||
"""Average score for this criteria"""
|
||||
|
||||
|
||||
|
|
@ -330,43 +330,43 @@ class Run(BaseModel):
|
|||
status: Literal["queued", "running", "completed", "failed", "cancelled"]
|
||||
"""Current status of the run"""
|
||||
|
||||
data_source: Dict[str, Any]
|
||||
data_source: dict[str, Any]
|
||||
"""Data source configuration used for the run"""
|
||||
|
||||
eval_id: str
|
||||
"""ID of the evaluation this run belongs to"""
|
||||
|
||||
name: Optional[str] = None
|
||||
name: str | None = None
|
||||
"""Name of the run"""
|
||||
|
||||
started_at: Optional[int] = None
|
||||
started_at: int | None = None
|
||||
"""Unix timestamp of when the run started"""
|
||||
|
||||
completed_at: Optional[int] = None
|
||||
completed_at: int | None = None
|
||||
"""Unix timestamp of when the run completed"""
|
||||
|
||||
model: Optional[str] = None
|
||||
model: str | None = None
|
||||
"""Model used for the run, if any"""
|
||||
|
||||
per_model_usage: Optional[Any] = None
|
||||
per_model_usage: Any | None = None
|
||||
"""Model usage details per model, if available"""
|
||||
|
||||
per_testing_criteria_results: Optional[List[PerTestingCriteriaResult]] = None
|
||||
per_testing_criteria_results: list[PerTestingCriteriaResult] | None = None
|
||||
"""Per-criteria results"""
|
||||
|
||||
report_url: Optional[str] = None
|
||||
report_url: str | None = None
|
||||
"""URL for the evaluation report"""
|
||||
|
||||
result_counts: Optional[Dict[str, int]] = None
|
||||
result_counts: dict[str, int] | None = None
|
||||
"""Aggregate result counts (e.g., {"passed": 0, "failed": 0, "errored": 0, "total": 0})"""
|
||||
|
||||
shared_with_openai: Optional[bool] = None
|
||||
shared_with_openai: bool | None = None
|
||||
"""Whether run is shared with OpenAI"""
|
||||
|
||||
metadata: Optional[Dict[str, Any]] = None
|
||||
metadata: dict[str, Any] | None = None
|
||||
"""Additional metadata"""
|
||||
|
||||
error: Optional[Dict[str, Any]] = None
|
||||
error: dict[str, Any] | None = None
|
||||
"""Error details if the run failed"""
|
||||
|
||||
|
||||
|
|
@ -376,13 +376,13 @@ class ListRunsResponse(BaseModel):
|
|||
object: str = "list"
|
||||
"""Object type, always 'list'"""
|
||||
|
||||
data: List[Run]
|
||||
data: list[Run]
|
||||
"""List of runs"""
|
||||
|
||||
first_id: Optional[str] = None
|
||||
first_id: str | None = None
|
||||
"""ID of the first run in the list"""
|
||||
|
||||
last_id: Optional[str] = None
|
||||
last_id: str | None = None
|
||||
"""ID of the last run in the list"""
|
||||
|
||||
has_more: bool = False
|
||||
|
|
@ -408,8 +408,8 @@ class RunDeleteResponse(BaseModel):
|
|||
run_id: str
|
||||
"""The ID of the deleted run"""
|
||||
|
||||
object: Optional[str] = "eval.run.deleted"
|
||||
object: str | None = "eval.run.deleted"
|
||||
"""Object type, always 'eval.run.deleted'"""
|
||||
|
||||
deleted: Optional[bool] = True
|
||||
deleted: bool | None = True
|
||||
"""Whether the run was successfully deleted"""
|
||||
|
|
|
|||
|
|
@ -1,11 +1,7 @@
|
|||
import json
|
||||
from enum import Enum
|
||||
from typing import Any, Dict, List, Literal, Optional, Tuple, Union
|
||||
|
||||
from typing_extensions import TypedDict
|
||||
|
||||
|
||||
class OpenRouterErrorMessage(TypedDict):
|
||||
message: str
|
||||
code: int
|
||||
metadata: Dict
|
||||
metadata: dict
|
||||
|
|
|
|||
|
|
@ -1,20 +1,18 @@
|
|||
from typing import Dict, List, Optional
|
||||
|
||||
from typing_extensions import TypedDict
|
||||
|
||||
|
||||
class RecraftImageGenerationRequestParams(TypedDict, total=False):
|
||||
prompt: str
|
||||
text_layout: Optional[List[Dict]]
|
||||
n: Optional[int]
|
||||
style_id: Optional[str]
|
||||
style: Optional[str]
|
||||
substyle: Optional[str]
|
||||
model: Optional[str]
|
||||
response_format: Optional[str]
|
||||
size: Optional[str]
|
||||
negative_prompt: Optional[str]
|
||||
controls: Optional[Dict]
|
||||
text_layout: list[dict] | None
|
||||
n: int | None
|
||||
style_id: str | None
|
||||
style: str | None
|
||||
substyle: str | None
|
||||
model: str | None
|
||||
response_format: str | None
|
||||
size: str | None
|
||||
negative_prompt: str | None
|
||||
controls: dict | None
|
||||
|
||||
|
||||
class RecraftImageEditRequestParams(TypedDict, total=False):
|
||||
|
|
@ -26,11 +24,11 @@ class RecraftImageEditRequestParams(TypedDict, total=False):
|
|||
|
||||
prompt: str # required - A text description of areas to change. Max 1000 bytes
|
||||
strength: float # required - Defines difference with original image, [0, 1]
|
||||
model: Optional[str] # The model to use, default is recraftv3
|
||||
n: Optional[int] # The number of images to generate, must be between 1 and 6
|
||||
style_id: Optional[str] # Use a previously uploaded style as reference
|
||||
style: Optional[str] # The style of generated images, default is realistic_image
|
||||
substyle: Optional[str] # Additional style specification
|
||||
response_format: Optional[str] # Format of returned images: url or b64_json
|
||||
negative_prompt: Optional[str] # Description of undesired elements
|
||||
controls: Optional[Dict] # Custom parameters to tweak generation process
|
||||
model: str | None # The model to use, default is recraftv3
|
||||
n: int | None # The number of images to generate, must be between 1 and 6
|
||||
style_id: str | None # Use a previously uploaded style as reference
|
||||
style: str | None # The style of generated images, default is realistic_image
|
||||
substyle: str | None # Additional style specification
|
||||
response_format: str | None # Format of returned images: url or b64_json
|
||||
negative_prompt: str | None # Description of undesired elements
|
||||
controls: dict | None # Custom parameters to tweak generation process
|
||||
|
|
|
|||
|
|
@ -1,20 +1,9 @@
|
|||
import json
|
||||
from enum import Enum
|
||||
from typing import Any, Dict, List, Literal, Optional, Tuple, Union
|
||||
|
||||
from typing_extensions import (
|
||||
Protocol,
|
||||
Required,
|
||||
Self,
|
||||
TypedDict,
|
||||
TypeGuard,
|
||||
get_origin,
|
||||
override,
|
||||
runtime_checkable,
|
||||
)
|
||||
|
||||
|
||||
class InfinityRerankResult(TypedDict):
|
||||
index: int
|
||||
relevance_score: float
|
||||
document: Optional[str]
|
||||
document: str | None
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ Type definitions for Stability AI API
|
|||
API Reference: https://platform.stability.ai/docs/api-reference
|
||||
"""
|
||||
|
||||
from typing import Final, List, Literal, Optional
|
||||
from typing import Final, Literal
|
||||
|
||||
from typing_extensions import TypedDict
|
||||
|
||||
|
|
@ -20,15 +20,15 @@ class StabilityImageGenerationRequest(TypedDict, total=False):
|
|||
"""
|
||||
|
||||
prompt: str # Required - text prompt for image generation
|
||||
negative_prompt: Optional[str] # What to avoid in the image
|
||||
aspect_ratio: Optional[str] # e.g., "1:1", "16:9", "9:16", "4:3", "3:4", "21:9", "9:21"
|
||||
seed: Optional[int] # Random seed for reproducibility (0 to 4294967294)
|
||||
output_format: Optional[Literal["jpeg", "png", "webp"]] # Output format
|
||||
model: Optional[str] # Model variant (e.g., "sd3.5-large", "sd3.5-medium")
|
||||
mode: Optional[Literal["text-to-image", "image-to-image"]] # Generation mode
|
||||
image: Optional[str] # Base64-encoded image for image-to-image
|
||||
strength: Optional[float] # How much to transform the image (0-1)
|
||||
style_preset: Optional[str] # Style preset name
|
||||
negative_prompt: str | None # What to avoid in the image
|
||||
aspect_ratio: str | None # e.g., "1:1", "16:9", "9:16", "4:3", "3:4", "21:9", "9:21"
|
||||
seed: int | None # Random seed for reproducibility (0 to 4294967294)
|
||||
output_format: Literal["jpeg", "png", "webp"] | None # Output format
|
||||
model: str | None # Model variant (e.g., "sd3.5-large", "sd3.5-medium")
|
||||
mode: Literal["text-to-image", "image-to-image"] | None # Generation mode
|
||||
image: str | None # Base64-encoded image for image-to-image
|
||||
strength: float | None # How much to transform the image (0-1)
|
||||
style_preset: str | None # Style preset name
|
||||
|
||||
|
||||
class StabilityImageEditRequest(StabilityImageGenerationRequest):
|
||||
|
|
@ -38,7 +38,7 @@ class StabilityImageEditRequest(StabilityImageGenerationRequest):
|
|||
Endpoint: /v2beta/stable-image/edit/inpaint
|
||||
"""
|
||||
|
||||
mask: Optional[str] # Base64-encoded mask (white = edit, black = keep)
|
||||
mask: str | None # Base64-encoded mask (white = edit, black = keep)
|
||||
|
||||
|
||||
class StabilityImageGenerationResponse(TypedDict, total=False):
|
||||
|
|
@ -62,11 +62,11 @@ class StabilityUpscaleRequest(TypedDict, total=False):
|
|||
"""
|
||||
|
||||
image: str # Required - Base64-encoded image to upscale
|
||||
prompt: Optional[str] # Text prompt (required for creative upscale)
|
||||
negative_prompt: Optional[str] # What to avoid
|
||||
output_format: Optional[Literal["jpeg", "png", "webp"]] # Output format
|
||||
seed: Optional[int] # Random seed
|
||||
creativity: Optional[float] # Creativity level for creative upscale (0-0.35)
|
||||
prompt: str | None # Text prompt (required for creative upscale)
|
||||
negative_prompt: str | None # What to avoid
|
||||
output_format: Literal["jpeg", "png", "webp"] | None # Output format
|
||||
seed: int | None # Random seed
|
||||
creativity: float | None # Creativity level for creative upscale (0-0.35)
|
||||
|
||||
|
||||
class StabilityInpaintRequest(TypedDict, total=False):
|
||||
|
|
@ -78,11 +78,11 @@ class StabilityInpaintRequest(TypedDict, total=False):
|
|||
|
||||
image: str # Required - Base64-encoded image to edit
|
||||
prompt: str # Required - Description of desired changes
|
||||
mask: Optional[str] # Base64-encoded mask (white = edit, black = keep)
|
||||
negative_prompt: Optional[str] # What to avoid
|
||||
seed: Optional[int] # Random seed
|
||||
output_format: Optional[Literal["jpeg", "png", "webp"]] # Output format
|
||||
grow_mask: Optional[int] # Pixels to grow the mask by (0-100)
|
||||
mask: str | None # Base64-encoded mask (white = edit, black = keep)
|
||||
negative_prompt: str | None # What to avoid
|
||||
seed: int | None # Random seed
|
||||
output_format: Literal["jpeg", "png", "webp"] | None # Output format
|
||||
grow_mask: int | None # Pixels to grow the mask by (0-100)
|
||||
|
||||
|
||||
class StabilityOutpaintRequest(TypedDict, total=False):
|
||||
|
|
@ -93,15 +93,15 @@ class StabilityOutpaintRequest(TypedDict, total=False):
|
|||
"""
|
||||
|
||||
image: str # Required - Base64-encoded image to expand
|
||||
prompt: Optional[str] # Description of content to generate
|
||||
negative_prompt: Optional[str] # What to avoid
|
||||
left: Optional[int] # Pixels to expand left (0-2000)
|
||||
right: Optional[int] # Pixels to expand right (0-2000)
|
||||
up: Optional[int] # Pixels to expand up (0-2000)
|
||||
down: Optional[int] # Pixels to expand down (0-2000)
|
||||
seed: Optional[int] # Random seed
|
||||
output_format: Optional[Literal["jpeg", "png", "webp"]] # Output format
|
||||
creativity: Optional[float] # How creative to be (0-1)
|
||||
prompt: str | None # Description of content to generate
|
||||
negative_prompt: str | None # What to avoid
|
||||
left: int | None # Pixels to expand left (0-2000)
|
||||
right: int | None # Pixels to expand right (0-2000)
|
||||
up: int | None # Pixels to expand up (0-2000)
|
||||
down: int | None # Pixels to expand down (0-2000)
|
||||
seed: int | None # Random seed
|
||||
output_format: Literal["jpeg", "png", "webp"] | None # Output format
|
||||
creativity: float | None # How creative to be (0-1)
|
||||
|
||||
|
||||
class StabilityEraseRequest(TypedDict, total=False):
|
||||
|
|
@ -112,10 +112,10 @@ class StabilityEraseRequest(TypedDict, total=False):
|
|||
"""
|
||||
|
||||
image: str # Required - Base64-encoded image
|
||||
mask: Optional[str] # Base64-encoded mask (white = erase)
|
||||
seed: Optional[int] # Random seed
|
||||
output_format: Optional[Literal["jpeg", "png", "webp"]] # Output format
|
||||
grow_mask: Optional[int] # Pixels to grow the mask by (0-100)
|
||||
mask: str | None # Base64-encoded mask (white = erase)
|
||||
seed: int | None # Random seed
|
||||
output_format: Literal["jpeg", "png", "webp"] | None # Output format
|
||||
grow_mask: int | None # Pixels to grow the mask by (0-100)
|
||||
|
||||
|
||||
class StabilitySearchReplaceRequest(TypedDict, total=False):
|
||||
|
|
@ -128,10 +128,10 @@ class StabilitySearchReplaceRequest(TypedDict, total=False):
|
|||
image: str # Required - Base64-encoded image
|
||||
prompt: str # Required - Description of object to add
|
||||
search_prompt: str # Required - Description of object to find and replace
|
||||
negative_prompt: Optional[str] # What to avoid
|
||||
seed: Optional[int] # Random seed
|
||||
output_format: Optional[Literal["jpeg", "png", "webp"]] # Output format
|
||||
grow_mask: Optional[int] # Pixels to grow detected mask
|
||||
negative_prompt: str | None # What to avoid
|
||||
seed: int | None # Random seed
|
||||
output_format: Literal["jpeg", "png", "webp"] | None # Output format
|
||||
grow_mask: int | None # Pixels to grow detected mask
|
||||
|
||||
|
||||
class StabilityRemoveBackgroundRequest(TypedDict, total=False):
|
||||
|
|
@ -142,7 +142,7 @@ class StabilityRemoveBackgroundRequest(TypedDict, total=False):
|
|||
"""
|
||||
|
||||
image: str # Required - Base64-encoded image
|
||||
output_format: Optional[Literal["png", "webp"]] # Output format (no jpeg - needs transparency)
|
||||
output_format: Literal["png", "webp"] | None # Output format (no jpeg - needs transparency)
|
||||
|
||||
|
||||
class StabilityControlRequest(TypedDict, total=False):
|
||||
|
|
@ -157,10 +157,10 @@ class StabilityControlRequest(TypedDict, total=False):
|
|||
|
||||
image: str # Required - Base64-encoded control image (sketch/structure/style reference)
|
||||
prompt: str # Required - Description of desired output
|
||||
negative_prompt: Optional[str] # What to avoid
|
||||
control_strength: Optional[float] # How strongly to follow the control (0-1)
|
||||
seed: Optional[int] # Random seed
|
||||
output_format: Optional[Literal["jpeg", "png", "webp"]] # Output format
|
||||
negative_prompt: str | None # What to avoid
|
||||
control_strength: float | None # How strongly to follow the control (0-1)
|
||||
seed: int | None # Random seed
|
||||
output_format: Literal["jpeg", "png", "webp"] | None # Output format
|
||||
|
||||
|
||||
class StabilityEditResponse(TypedDict, total=False):
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
from enum import Enum
|
||||
from typing import Any, Dict, Final, List, Literal, Optional, Union
|
||||
from typing import Any, Final, Literal
|
||||
|
||||
from typing_extensions import (
|
||||
Required,
|
||||
|
|
@ -11,7 +11,7 @@ from litellm.types.llms.openai import EmbeddingInput
|
|||
# Gemini supports nested-list inputs (e.g. [["text", "image"]]) as an explicit
|
||||
# opt-in for combined embeddings — a provider-specific extension of the
|
||||
# OpenAI-faithful EmbeddingInput shape.
|
||||
GeminiEmbeddingInput = Union[EmbeddingInput, List[List[str]]]
|
||||
GeminiEmbeddingInput = EmbeddingInput | list[list[str]]
|
||||
|
||||
|
||||
class FunctionResponse(TypedDict, total=False):
|
||||
|
|
@ -19,8 +19,8 @@ class FunctionResponse(TypedDict, total=False):
|
|||
# Supported on Gemini 3+; older Gemini models reject this field.
|
||||
id: str
|
||||
name: Required[str]
|
||||
response: Optional[dict]
|
||||
parts: List["FunctionResponsePartType"]
|
||||
response: dict | None
|
||||
parts: list["FunctionResponsePartType"]
|
||||
|
||||
|
||||
class FunctionCall(TypedDict, total=False):
|
||||
|
|
@ -28,7 +28,7 @@ class FunctionCall(TypedDict, total=False):
|
|||
# Older Gemini models omit/reject this field.
|
||||
id: str
|
||||
name: Required[str]
|
||||
args: Optional[dict]
|
||||
args: dict | None
|
||||
|
||||
|
||||
class FileDataType(TypedDict):
|
||||
|
|
@ -89,7 +89,7 @@ class HttpxServerSideToolCall(TypedDict, total=False):
|
|||
class HttpxServerSideToolResponse(TypedDict, total=False):
|
||||
toolType: str
|
||||
id: str
|
||||
response: Union[str, dict]
|
||||
response: str | dict
|
||||
|
||||
|
||||
class HttpxPartType(TypedDict, total=False):
|
||||
|
|
@ -109,16 +109,16 @@ class HttpxPartType(TypedDict, total=False):
|
|||
|
||||
class HttpxContentType(TypedDict, total=False):
|
||||
role: Literal["user", "model"]
|
||||
parts: List[HttpxPartType]
|
||||
parts: list[HttpxPartType]
|
||||
|
||||
|
||||
class ContentType(TypedDict, total=False):
|
||||
role: Literal["user", "model"]
|
||||
parts: Required[List[PartType]]
|
||||
parts: Required[list[PartType]]
|
||||
|
||||
|
||||
class SystemInstructions(TypedDict):
|
||||
parts: Required[List[PartType]]
|
||||
parts: Required[list[PartType]]
|
||||
|
||||
|
||||
class Schema(TypedDict, total=False):
|
||||
|
|
@ -131,10 +131,10 @@ class Schema(TypedDict, total=False):
|
|||
items: "Schema"
|
||||
minItems: str
|
||||
maxItems: str
|
||||
enum: List[str]
|
||||
properties: Dict[str, "Schema"]
|
||||
propertyOrdering: List[str]
|
||||
required: List[str]
|
||||
enum: list[str]
|
||||
properties: dict[str, "Schema"]
|
||||
propertyOrdering: list[str]
|
||||
required: list[str]
|
||||
minProperties: str
|
||||
maxProperties: str
|
||||
minimum: float
|
||||
|
|
@ -143,13 +143,13 @@ class Schema(TypedDict, total=False):
|
|||
maxLength: str
|
||||
pattern: str
|
||||
example: Any
|
||||
anyOf: List["Schema"]
|
||||
anyOf: list["Schema"]
|
||||
|
||||
|
||||
class FunctionDeclaration(TypedDict, total=False):
|
||||
name: Required[str]
|
||||
description: str
|
||||
parameters: Union[Schema, dict]
|
||||
parameters: Schema | dict
|
||||
response: Schema
|
||||
|
||||
|
||||
|
|
@ -163,7 +163,7 @@ class Retrieval(TypedDict):
|
|||
|
||||
class FunctionCallingConfig(TypedDict, total=False):
|
||||
mode: Literal["ANY", "AUTO", "NONE"]
|
||||
allowed_function_names: List[str]
|
||||
allowed_function_names: list[str]
|
||||
|
||||
|
||||
HarmCategory = Literal[
|
||||
|
|
@ -237,7 +237,7 @@ class GenerationConfig(TypedDict, total=False):
|
|||
top_k: float
|
||||
candidate_count: int
|
||||
max_output_tokens: int
|
||||
stop_sequences: List[str]
|
||||
stop_sequences: list[str]
|
||||
presence_penalty: float
|
||||
frequency_penalty: float
|
||||
response_mime_type: Literal["text/plain", "application/json"]
|
||||
|
|
@ -247,7 +247,7 @@ class GenerationConfig(TypedDict, total=False):
|
|||
seed: int
|
||||
responseLogprobs: bool
|
||||
logprobs: int
|
||||
responseModalities: List[GeminiResponseModalities]
|
||||
responseModalities: list[GeminiResponseModalities]
|
||||
imageConfig: GeminiImageConfig
|
||||
thinkingConfig: GeminiThinkingConfig
|
||||
mediaResolution: str
|
||||
|
|
@ -267,7 +267,7 @@ class VertexToolName(str, Enum):
|
|||
|
||||
|
||||
class Tools(TypedDict, total=False):
|
||||
function_declarations: List[FunctionDeclaration]
|
||||
function_declarations: list[FunctionDeclaration]
|
||||
googleSearch: dict
|
||||
googleSearchRetrieval: dict
|
||||
enterpriseWebSearch: dict
|
||||
|
|
@ -300,12 +300,12 @@ class UsageMetadata(TypedDict, total=False):
|
|||
responseTokenCount: int
|
||||
cachedContentTokenCount: int
|
||||
toolUsePromptTokenCount: int
|
||||
toolUsePromptTokensDetails: List[PromptTokensDetails]
|
||||
promptTokensDetails: List[PromptTokensDetails]
|
||||
cacheTokensDetails: List[PromptTokensDetails]
|
||||
toolUsePromptTokensDetails: list[PromptTokensDetails]
|
||||
promptTokensDetails: list[PromptTokensDetails]
|
||||
cacheTokensDetails: list[PromptTokensDetails]
|
||||
thoughtsTokenCount: int
|
||||
responseTokensDetails: List[PromptTokensDetails]
|
||||
candidatesTokensDetails: List[PromptTokensDetails] # Alternative key name used in some responses
|
||||
responseTokensDetails: list[PromptTokensDetails]
|
||||
candidatesTokensDetails: list[PromptTokensDetails] # Alternative key name used in some responses
|
||||
|
||||
|
||||
class TokenCountDetailsResponse(TypedDict):
|
||||
|
|
@ -317,14 +317,14 @@ class TokenCountDetailsResponse(TypedDict):
|
|||
"""
|
||||
|
||||
totalTokens: int
|
||||
promptTokensDetails: List[PromptTokensDetails]
|
||||
promptTokensDetails: list[PromptTokensDetails]
|
||||
|
||||
|
||||
class CachedContent(TypedDict, total=False):
|
||||
ttl: TTL
|
||||
expire_time: str
|
||||
contents: List[ContentType]
|
||||
tools: List[Tools]
|
||||
contents: list[ContentType]
|
||||
tools: list[Tools]
|
||||
createTime: str # "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z"
|
||||
updateTime: str # "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z"
|
||||
usageMetadata: UsageMetadata
|
||||
|
|
@ -337,19 +337,19 @@ class CachedContent(TypedDict, total=False):
|
|||
|
||||
|
||||
class RequestBody(TypedDict, total=False):
|
||||
contents: Required[List[ContentType]]
|
||||
contents: Required[list[ContentType]]
|
||||
system_instruction: SystemInstructions
|
||||
tools: Tools
|
||||
toolConfig: ToolConfig
|
||||
safetySettings: List[SafetSettingsConfig]
|
||||
safetySettings: list[SafetSettingsConfig]
|
||||
generationConfig: GenerationConfig
|
||||
cachedContent: str
|
||||
labels: Dict[str, str]
|
||||
labels: dict[str, str]
|
||||
serviceTier: str
|
||||
|
||||
|
||||
class CachedContentRequestBody(TypedDict, total=False):
|
||||
contents: Required[List[ContentType]]
|
||||
contents: Required[list[ContentType]]
|
||||
system_instruction: SystemInstructions
|
||||
tools: Tools
|
||||
toolConfig: ToolConfig
|
||||
|
|
@ -359,7 +359,7 @@ class CachedContentRequestBody(TypedDict, total=False):
|
|||
|
||||
|
||||
class CachedContentListAllResponseBody(TypedDict, total=False):
|
||||
cachedContents: List[CachedContent]
|
||||
cachedContents: list[CachedContent]
|
||||
nextPageToken: str
|
||||
|
||||
|
||||
|
|
@ -387,7 +387,7 @@ class Citation(TypedDict):
|
|||
|
||||
|
||||
class CitationMetadata(TypedDict):
|
||||
citations: List[Citation]
|
||||
citations: list[Citation]
|
||||
|
||||
|
||||
class SearchEntryPoint(TypedDict, total=False):
|
||||
|
|
@ -396,9 +396,9 @@ class SearchEntryPoint(TypedDict, total=False):
|
|||
|
||||
|
||||
class GroundingMetadata(TypedDict, total=False):
|
||||
webSearchQueries: List[str]
|
||||
webSearchQueries: list[str]
|
||||
searchEntryPoint: SearchEntryPoint
|
||||
groundingAttributions: List[dict]
|
||||
groundingAttributions: list[dict]
|
||||
|
||||
|
||||
class LogprobsCandidate(TypedDict):
|
||||
|
|
@ -408,12 +408,12 @@ class LogprobsCandidate(TypedDict):
|
|||
|
||||
|
||||
class LogprobsTopCandidate(TypedDict):
|
||||
candidates: List[LogprobsCandidate]
|
||||
candidates: list[LogprobsCandidate]
|
||||
|
||||
|
||||
class LogprobsResult(TypedDict, total=False):
|
||||
topCandidates: List[LogprobsTopCandidate]
|
||||
chosenCandidates: List[LogprobsCandidate]
|
||||
topCandidates: list[LogprobsTopCandidate]
|
||||
chosenCandidates: list[LogprobsCandidate]
|
||||
|
||||
|
||||
class UrlMetadata(TypedDict, total=False):
|
||||
|
|
@ -422,7 +422,7 @@ class UrlMetadata(TypedDict, total=False):
|
|||
|
||||
|
||||
class UrlContextMetadata(TypedDict, total=False):
|
||||
urlMetadata: List[UrlMetadata]
|
||||
urlMetadata: list[UrlMetadata]
|
||||
|
||||
|
||||
class Candidates(TypedDict, total=False):
|
||||
|
|
@ -441,7 +441,7 @@ class Candidates(TypedDict, total=False):
|
|||
"MALFORMED_FUNCTION_CALL",
|
||||
"IMAGE_SAFETY",
|
||||
]
|
||||
safetyRatings: List[SafetyRatings]
|
||||
safetyRatings: list[SafetyRatings]
|
||||
citationMetadata: CitationMetadata
|
||||
groundingMetadata: GroundingMetadata
|
||||
finishMessage: str
|
||||
|
|
@ -451,21 +451,21 @@ class Candidates(TypedDict, total=False):
|
|||
|
||||
class PromptFeedback(TypedDict):
|
||||
blockReason: str
|
||||
safetyRatings: List[SafetyRatings]
|
||||
safetyRatings: list[SafetyRatings]
|
||||
blockReasonMessage: str
|
||||
|
||||
|
||||
class GenerateContentResponseBody(TypedDict, total=False):
|
||||
candidates: List[Candidates]
|
||||
candidates: list[Candidates]
|
||||
promptFeedback: PromptFeedback
|
||||
usageMetadata: Required[UsageMetadata]
|
||||
responseId: str
|
||||
|
||||
|
||||
class FineTuneHyperparameters(TypedDict, total=False):
|
||||
epoch_count: Optional[int]
|
||||
learning_rate_multiplier: Optional[float]
|
||||
adapter_size: Optional[
|
||||
epoch_count: int | None
|
||||
learning_rate_multiplier: float | None
|
||||
adapter_size: (
|
||||
Literal[
|
||||
"ADAPTER_SIZE_UNSPECIFIED",
|
||||
"ADAPTER_SIZE_ONE",
|
||||
|
|
@ -473,43 +473,41 @@ class FineTuneHyperparameters(TypedDict, total=False):
|
|||
"ADAPTER_SIZE_EIGHT",
|
||||
"ADAPTER_SIZE_SIXTEEN",
|
||||
]
|
||||
]
|
||||
| None
|
||||
)
|
||||
|
||||
|
||||
class FineTunesupervisedTuningSpec(TypedDict, total=False):
|
||||
training_dataset_uri: str
|
||||
validation_dataset: Optional[str]
|
||||
tuned_model_display_name: Optional[str]
|
||||
hyperParameters: Optional[FineTuneHyperparameters]
|
||||
validation_dataset: str | None
|
||||
tuned_model_display_name: str | None
|
||||
hyperParameters: FineTuneHyperparameters | None
|
||||
|
||||
|
||||
class FineTuneJobCreate(TypedDict, total=False):
|
||||
baseModel: str
|
||||
supervisedTuningSpec: FineTunesupervisedTuningSpec
|
||||
tunedModelDisplayName: Optional[str]
|
||||
tunedModelDisplayName: str | None
|
||||
|
||||
|
||||
class ResponseSupervisedTuningSpec(TypedDict, total=False):
|
||||
trainingDatasetUri: Optional[str]
|
||||
hyperParameters: Optional[FineTuneHyperparameters]
|
||||
trainingDatasetUri: str | None
|
||||
hyperParameters: FineTuneHyperparameters | None
|
||||
|
||||
|
||||
class ResponseTuningJob(TypedDict):
|
||||
name: Optional[str]
|
||||
tunedModelDisplayName: Optional[str]
|
||||
baseModel: Optional[str]
|
||||
supervisedTuningSpec: Optional[ResponseSupervisedTuningSpec]
|
||||
state: Optional[
|
||||
name: str | None
|
||||
tunedModelDisplayName: str | None
|
||||
baseModel: str | None
|
||||
supervisedTuningSpec: ResponseSupervisedTuningSpec | None
|
||||
state: (
|
||||
Literal[
|
||||
"JOB_STATE_PENDING",
|
||||
"JOB_STATE_RUNNING",
|
||||
"JOB_STATE_SUCCEEDED",
|
||||
"JOB_STATE_FAILED",
|
||||
"JOB_STATE_CANCELLED",
|
||||
"JOB_STATE_PENDING", "JOB_STATE_RUNNING", "JOB_STATE_SUCCEEDED", "JOB_STATE_FAILED", "JOB_STATE_CANCELLED"
|
||||
]
|
||||
]
|
||||
createTime: Optional[str]
|
||||
updateTime: Optional[str]
|
||||
| None
|
||||
)
|
||||
createTime: str | None
|
||||
updateTime: str | None
|
||||
|
||||
|
||||
class VideoSegmentConfig(TypedDict, total=False):
|
||||
|
|
@ -524,9 +522,9 @@ class InstanceVideo(TypedDict, total=False):
|
|||
|
||||
|
||||
class InstanceImage(TypedDict, total=False):
|
||||
gcsUri: Optional[str]
|
||||
bytesBase64Encoded: Optional[str]
|
||||
mimeType: Optional[str]
|
||||
gcsUri: str | None
|
||||
bytesBase64Encoded: str | None
|
||||
mimeType: str | None
|
||||
|
||||
|
||||
class Instance(TypedDict, total=False):
|
||||
|
|
@ -536,24 +534,24 @@ class Instance(TypedDict, total=False):
|
|||
|
||||
|
||||
class VertexMultimodalEmbeddingRequest(TypedDict, total=False):
|
||||
instances: Required[List[Instance]]
|
||||
instances: Required[list[Instance]]
|
||||
parameters: dict
|
||||
|
||||
|
||||
class VideoEmbedding(TypedDict):
|
||||
startOffsetSec: int
|
||||
endOffsetSec: int
|
||||
embedding: List[float]
|
||||
embedding: list[float]
|
||||
|
||||
|
||||
class MultimodalPrediction(TypedDict, total=False):
|
||||
textEmbedding: List[float]
|
||||
imageEmbedding: List[float]
|
||||
videoEmbeddings: List[VideoEmbedding]
|
||||
textEmbedding: list[float]
|
||||
imageEmbedding: list[float]
|
||||
videoEmbeddings: list[VideoEmbedding]
|
||||
|
||||
|
||||
class MultimodalPredictions(TypedDict):
|
||||
predictions: List[MultimodalPrediction]
|
||||
predictions: list[MultimodalPrediction]
|
||||
|
||||
|
||||
class VertexAICachedContentResponseObject(TypedDict):
|
||||
|
|
@ -580,7 +578,7 @@ class VertexAITextEmbeddingsRequestBody(TypedDict, total=False):
|
|||
|
||||
|
||||
class ContentEmbeddings(TypedDict):
|
||||
values: List[int]
|
||||
values: list[int]
|
||||
|
||||
|
||||
class VertexAITextEmbeddingsResponseObject(TypedDict):
|
||||
|
|
@ -592,11 +590,11 @@ class EmbedContentRequest(VertexAITextEmbeddingsRequestBody):
|
|||
|
||||
|
||||
class VertexAIBatchEmbeddingsRequestBody(TypedDict, total=False):
|
||||
requests: List[EmbedContentRequest]
|
||||
requests: list[EmbedContentRequest]
|
||||
|
||||
|
||||
class VertexAIBatchEmbeddingsResponseObject(TypedDict):
|
||||
embeddings: List[ContentEmbeddings]
|
||||
embeddings: list[ContentEmbeddings]
|
||||
|
||||
|
||||
class GeminiEmbedContentRequestBody(TypedDict, total=False):
|
||||
|
|
@ -614,7 +612,7 @@ class GeminiEmbedContentResponseObject(TypedDict):
|
|||
|
||||
|
||||
class GcsSource(TypedDict):
|
||||
uris: List[str]
|
||||
uris: list[str]
|
||||
|
||||
|
||||
class InputConfig(TypedDict):
|
||||
|
|
@ -724,7 +722,7 @@ class VertexVideoGenerationParameters(TypedDict, total=False):
|
|||
class VertexVideoGenerationRequest(TypedDict):
|
||||
"""Complete request body for Vertex AI video generation"""
|
||||
|
||||
instances: Required[List[VertexVideoGenerationInstance]]
|
||||
instances: Required[list[VertexVideoGenerationInstance]]
|
||||
parameters: VertexVideoGenerationParameters
|
||||
|
||||
|
||||
|
|
@ -741,12 +739,12 @@ class VertexVideoGenerationResponse(TypedDict, total=False):
|
|||
|
||||
name: str
|
||||
done: bool
|
||||
response: Dict[str, Any]
|
||||
metadata: Dict[str, Any]
|
||||
error: Dict[str, Any]
|
||||
response: dict[str, Any]
|
||||
metadata: dict[str, Any]
|
||||
error: dict[str, Any]
|
||||
|
||||
|
||||
VERTEX_CREDENTIALS_TYPES = Union[str, Dict[str, str]]
|
||||
VERTEX_CREDENTIALS_TYPES = str | dict[str, str]
|
||||
|
||||
|
||||
class VertexPartnerProvider(str, Enum):
|
||||
|
|
|
|||
|
|
@ -4,8 +4,6 @@ Type definitions for Vertex AI Text-to-Speech API
|
|||
Reference: https://cloud.google.com/text-to-speech/docs/reference/rest/v1/text/synthesize
|
||||
"""
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from typing_extensions import TypedDict
|
||||
|
||||
|
||||
|
|
@ -16,8 +14,8 @@ class VertexTextToSpeechInput(TypedDict, total=False):
|
|||
Exactly one of text or ssml must be provided.
|
||||
"""
|
||||
|
||||
text: Optional[str]
|
||||
ssml: Optional[str]
|
||||
text: str | None
|
||||
ssml: str | None
|
||||
|
||||
|
||||
class VertexTextToSpeechVoice(TypedDict, total=False):
|
||||
|
|
@ -55,4 +53,4 @@ class VertexTextToSpeechRequest(TypedDict, total=False):
|
|||
|
||||
input: VertexTextToSpeechInput
|
||||
voice: VertexTextToSpeechVoice
|
||||
audioConfig: Optional[VertexTextToSpeechAudioConfig]
|
||||
audioConfig: VertexTextToSpeechAudioConfig | None
|
||||
|
|
|
|||
|
|
@ -1,19 +1,18 @@
|
|||
from enum import Enum
|
||||
from typing import List, Optional
|
||||
|
||||
from typing_extensions import NotRequired, TypedDict
|
||||
|
||||
|
||||
class WatsonXAPIParams(TypedDict):
|
||||
project_id: Optional[str]
|
||||
space_id: Optional[str]
|
||||
region_name: Optional[str]
|
||||
project_id: str | None
|
||||
space_id: str | None
|
||||
region_name: str | None
|
||||
|
||||
|
||||
class WatsonXCredentials(TypedDict):
|
||||
api_key: str
|
||||
api_base: str
|
||||
token: Optional[str]
|
||||
token: str | None
|
||||
|
||||
|
||||
class WatsonXAudioTranscriptionRequestBody(TypedDict):
|
||||
|
|
@ -45,7 +44,7 @@ class WatsonXAudioTranscriptionRequestBody(TypedDict):
|
|||
temperature: NotRequired[float]
|
||||
"""Sampling temperature (0-1)"""
|
||||
|
||||
timestamp_granularities: NotRequired[List[str]]
|
||||
timestamp_granularities: NotRequired[list[str]]
|
||||
"""Timestamp granularities: ['word', 'segment']"""
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,28 +1,28 @@
|
|||
from typing import List, Literal, Optional, TypedDict
|
||||
from typing import Literal, TypedDict
|
||||
|
||||
|
||||
class XAIWebSearchFilters(TypedDict, total=False):
|
||||
"""Filters for XAI web search tool"""
|
||||
|
||||
allowed_domains: Optional[List[str]] # Max 5 domains
|
||||
excluded_domains: Optional[List[str]] # Max 5 domains
|
||||
allowed_domains: list[str] | None # Max 5 domains
|
||||
excluded_domains: list[str] | None # Max 5 domains
|
||||
|
||||
|
||||
class XAIWebSearchTool(TypedDict, total=False):
|
||||
"""XAI web search tool configuration"""
|
||||
|
||||
type: Literal["web_search"]
|
||||
filters: Optional[XAIWebSearchFilters]
|
||||
enable_image_understanding: Optional[bool]
|
||||
filters: XAIWebSearchFilters | None
|
||||
enable_image_understanding: bool | None
|
||||
|
||||
|
||||
class XAIXSearchTool(TypedDict, total=False):
|
||||
"""XAI X (Twitter) search tool configuration"""
|
||||
|
||||
type: Literal["x_search"]
|
||||
allowed_x_handles: Optional[List[str]] # Max 10 handles
|
||||
excluded_x_handles: Optional[List[str]] # Max 10 handles
|
||||
from_date: Optional[str] # ISO8601 format: YYYY-MM-DD
|
||||
to_date: Optional[str] # ISO8601 format: YYYY-MM-DD
|
||||
enable_image_understanding: Optional[bool]
|
||||
enable_video_understanding: Optional[bool]
|
||||
allowed_x_handles: list[str] | None # Max 10 handles
|
||||
excluded_x_handles: list[str] | None # Max 10 handles
|
||||
from_date: str | None # ISO8601 format: YYYY-MM-DD
|
||||
to_date: str | None # ISO8601 format: YYYY-MM-DD
|
||||
enable_image_understanding: bool | None
|
||||
enable_video_understanding: bool | None
|
||||
|
|
|
|||
|
|
@ -20,14 +20,14 @@ from .router_settings_endpoints import (
|
|||
)
|
||||
|
||||
__all__ = [
|
||||
"CACHE_SETTINGS_FIELDS",
|
||||
"COORDINATION_REDIS_SETTINGS_FIELDS",
|
||||
"REDIS_TYPE_DESCRIPTIONS",
|
||||
"ROUTER_SETTINGS_FIELDS",
|
||||
"ROUTING_STRATEGY_DESCRIPTIONS",
|
||||
"RouterSettingsField",
|
||||
"CACHE_SETTINGS_FIELDS",
|
||||
"REDIS_TYPE_DESCRIPTIONS",
|
||||
"CacheSettingsField",
|
||||
"COORDINATION_REDIS_SETTINGS_FIELDS",
|
||||
"CoordinationRedisSection",
|
||||
"CoordinationRedisSettingsField",
|
||||
"CoordinationRedisSource",
|
||||
"RouterSettingsField",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Types and field definitions for cache settings management endpoints
|
||||
"""
|
||||
|
||||
from typing import Any, Dict, Final, List, Optional
|
||||
from typing import Any, Final
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
|
@ -13,14 +13,14 @@ class CacheSettingsField(BaseModel):
|
|||
field_value: Any
|
||||
field_description: str
|
||||
field_default: Any = None
|
||||
options: Optional[List[str]] = None # For fields with predefined options/enum values
|
||||
options: list[str] | None = None # For fields with predefined options/enum values
|
||||
ui_field_name: str # User-friendly display name
|
||||
link: Optional[str] = None # Documentation link for the field
|
||||
redis_type: Optional[str] = None # Which Redis type this field applies to (node, cluster, sentinel)
|
||||
link: str | None = None # Documentation link for the field
|
||||
redis_type: str | None = None # Which Redis type this field applies to (node, cluster, sentinel)
|
||||
|
||||
|
||||
# Redis type descriptions
|
||||
REDIS_TYPE_DESCRIPTIONS: Final[Dict[str, str]] = {
|
||||
REDIS_TYPE_DESCRIPTIONS: Final[dict[str, str]] = {
|
||||
"node": "Standard Redis node/single instance",
|
||||
"cluster": "Redis Cluster mode for high availability and horizontal scaling",
|
||||
"sentinel": "Redis Sentinel mode for high availability with automatic failover",
|
||||
|
|
@ -28,7 +28,7 @@ REDIS_TYPE_DESCRIPTIONS: Final[Dict[str, str]] = {
|
|||
|
||||
|
||||
# Define all available cache settings fields
|
||||
CACHE_SETTINGS_FIELDS: Final[List[CacheSettingsField]] = [
|
||||
CACHE_SETTINGS_FIELDS: Final[list[CacheSettingsField]] = [
|
||||
CacheSettingsField(
|
||||
field_name="redis_type",
|
||||
field_type="String",
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Types and field definitions for coordination Redis settings management endpoints
|
||||
"""
|
||||
|
||||
from typing import Final, Literal, Optional
|
||||
from typing import Final, Literal
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
|
@ -14,9 +14,9 @@ CoordinationRedisSource = Literal["coordination_redis", "cache_backend", "enviro
|
|||
class CoordinationRedisSettingsField(BaseModel):
|
||||
field_name: str
|
||||
field_type: str
|
||||
field_value: Optional[object] = None
|
||||
field_value: object | None = None
|
||||
field_description: str
|
||||
field_default: Optional[object] = None
|
||||
field_default: object | None = None
|
||||
ui_field_name: str
|
||||
section: CoordinationRedisSection
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Types and field definitions for router settings management endpoints
|
||||
"""
|
||||
|
||||
from typing import Any, Dict, Final, List, Literal, Optional
|
||||
from typing import Any, Final, Literal
|
||||
|
||||
from pydantic import BaseModel, Field, field_validator
|
||||
|
||||
|
|
@ -13,7 +13,7 @@ class FallbackCreateRequest(BaseModel):
|
|||
"""Request model for creating/updating fallbacks"""
|
||||
|
||||
model: str = Field(description="The model name to configure fallbacks for (e.g., 'gpt-3.5-turbo')")
|
||||
fallback_models: List[str] = Field(
|
||||
fallback_models: list[str] = Field(
|
||||
description="List of fallback model names in order of priority",
|
||||
min_length=1,
|
||||
)
|
||||
|
|
@ -24,7 +24,7 @@ class FallbackCreateRequest(BaseModel):
|
|||
|
||||
@field_validator("fallback_models")
|
||||
@classmethod
|
||||
def validate_fallback_models(cls, v: List[str]) -> List[str]:
|
||||
def validate_fallback_models(cls, v: list[str]) -> list[str]:
|
||||
if not v:
|
||||
raise ValueError("fallback_models must contain at least one model")
|
||||
if len(v) != len(set(v)):
|
||||
|
|
@ -43,7 +43,7 @@ class FallbackResponse(BaseModel):
|
|||
"""Response model for fallback operations"""
|
||||
|
||||
model: str = Field(description="The model name")
|
||||
fallback_models: List[str] = Field(description="List of fallback model names")
|
||||
fallback_models: list[str] = Field(description="List of fallback model names")
|
||||
fallback_type: str = Field(description="Type of fallback")
|
||||
message: str = Field(description="Success message")
|
||||
|
||||
|
|
@ -52,7 +52,7 @@ class FallbackGetResponse(BaseModel):
|
|||
"""Response model for getting fallbacks"""
|
||||
|
||||
model: str = Field(description="The model name")
|
||||
fallback_models: List[str] = Field(description="List of fallback model names")
|
||||
fallback_models: list[str] = Field(description="List of fallback model names")
|
||||
fallback_type: str = Field(description="Type of fallback")
|
||||
|
||||
|
||||
|
|
@ -73,13 +73,13 @@ class RouterSettingsField(BaseModel):
|
|||
field_value: Any
|
||||
field_description: str
|
||||
field_default: Any = None
|
||||
options: Optional[List[str]] = None # For fields with predefined options/enum values
|
||||
options: list[str] | None = None # For fields with predefined options/enum values
|
||||
ui_field_name: str # User-friendly display name
|
||||
link: Optional[str] = None # Documentation link for the field
|
||||
link: str | None = None # Documentation link for the field
|
||||
|
||||
|
||||
# Routing strategy descriptions
|
||||
ROUTING_STRATEGY_DESCRIPTIONS: Final[Dict[str, str]] = {
|
||||
ROUTING_STRATEGY_DESCRIPTIONS: Final[dict[str, str]] = {
|
||||
"simple-shuffle": "Randomly picks a deployment from the list. Simple and fast.",
|
||||
"least-busy": "Routes to the deployment with the lowest number of ongoing requests.",
|
||||
"latency-based-routing": "Routes to the deployment with the lowest latency over a sliding window.",
|
||||
|
|
@ -90,7 +90,7 @@ ROUTING_STRATEGY_DESCRIPTIONS: Final[Dict[str, str]] = {
|
|||
|
||||
|
||||
# Define all available router settings fields
|
||||
ROUTER_SETTINGS_FIELDS: Final[List[RouterSettingsField]] = [
|
||||
ROUTER_SETTINGS_FIELDS: Final[list[RouterSettingsField]] = [
|
||||
RouterSettingsField(
|
||||
field_name="routing_strategy",
|
||||
field_type="String",
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import enum
|
||||
from typing import Any, Dict, Final, List, Literal, Optional, TYPE_CHECKING, Union
|
||||
from typing import TYPE_CHECKING, Any, Final, Literal
|
||||
|
||||
from pydantic import BaseModel
|
||||
from typing_extensions import TypedDict
|
||||
|
|
@ -52,7 +52,7 @@ DEFAULT_SUBJECT_TOKEN_TYPE: Final = "urn:ietf:params:oauth:token-type:access_tok
|
|||
# MCP Literals
|
||||
MCPTransportType = Literal[MCPTransport.sse, MCPTransport.http, MCPTransport.stdio]
|
||||
MCPSpecVersionType = Literal[MCPSpecVersion.nov_2024, MCPSpecVersion.mar_2025, MCPSpecVersion.jun_2025]
|
||||
MCPAuthType = Optional[
|
||||
MCPAuthType = (
|
||||
Literal[
|
||||
MCPAuth.none,
|
||||
MCPAuth.api_key,
|
||||
|
|
@ -67,7 +67,8 @@ MCPAuthType = Optional[
|
|||
MCPAuth.true_passthrough,
|
||||
MCPAuth.oauth_delegate,
|
||||
]
|
||||
]
|
||||
| None
|
||||
)
|
||||
|
||||
|
||||
class MCPPublicServer(BaseModel):
|
||||
|
|
@ -77,12 +78,12 @@ class MCPPublicServer(BaseModel):
|
|||
|
||||
server_id: str
|
||||
name: str
|
||||
alias: Optional[str] = None
|
||||
server_name: Optional[str] = None
|
||||
alias: str | None = None
|
||||
server_name: str | None = None
|
||||
transport: MCPTransportType
|
||||
spec_path: Optional[str] = None
|
||||
auth_type: Optional[MCPAuthType] = None
|
||||
mcp_info: Optional[Dict[str, Any]] = None
|
||||
spec_path: str | None = None
|
||||
auth_type: MCPAuthType | None = None
|
||||
mcp_info: dict[str, Any] | None = None
|
||||
|
||||
|
||||
# OAuth 2.0 token-endpoint client authentication method (RFC 6749 section 2.3.1).
|
||||
|
|
@ -90,49 +91,49 @@ MCPTokenEndpointAuthMethod = Literal["client_secret_basic", "client_secret_post"
|
|||
|
||||
|
||||
class MCPCredentials(TypedDict, total=False):
|
||||
auth_value: Optional[str]
|
||||
auth_value: str | None
|
||||
"""
|
||||
Authentication value
|
||||
"""
|
||||
|
||||
client_id: Optional[str]
|
||||
client_id: str | None
|
||||
"""
|
||||
OAuth 2.0 client identifier used when auth_type is oauth2
|
||||
"""
|
||||
|
||||
client_secret: Optional[str]
|
||||
client_secret: str | None
|
||||
"""
|
||||
OAuth 2.0 client secret used when auth_type is oauth2
|
||||
"""
|
||||
|
||||
scopes: Optional[List[str]]
|
||||
scopes: list[str] | None
|
||||
"""
|
||||
OAuth 2.0 scopes to request when exchanging the client credentials
|
||||
"""
|
||||
|
||||
# AWS SigV4 fields
|
||||
aws_access_key_id: Optional[str]
|
||||
aws_access_key_id: str | None
|
||||
"""AWS access key ID for SigV4 signing. Optional — falls back to boto3 credential chain."""
|
||||
|
||||
aws_secret_access_key: Optional[str]
|
||||
aws_secret_access_key: str | None
|
||||
"""AWS secret access key for SigV4 signing. Optional — falls back to boto3 credential chain."""
|
||||
|
||||
aws_session_token: Optional[str]
|
||||
aws_session_token: str | None
|
||||
"""AWS session token for temporary STS credentials. Optional."""
|
||||
|
||||
aws_region_name: Optional[str]
|
||||
aws_region_name: str | None
|
||||
"""AWS region for SigV4 signing (e.g., 'us-east-1'). Not a secret — stored unencrypted."""
|
||||
|
||||
aws_service_name: Optional[str]
|
||||
aws_service_name: str | None
|
||||
"""AWS service name for SigV4 signing (e.g., 'bedrock-agentcore'). Not a secret — stored unencrypted."""
|
||||
|
||||
aws_role_name: Optional[str]
|
||||
aws_role_name: str | None
|
||||
"""IAM role ARN for STS AssumeRole (e.g., 'arn:aws:iam::123456789012:role/MyRole'). Not a secret — stored unencrypted."""
|
||||
|
||||
aws_session_name: Optional[str]
|
||||
aws_session_name: str | None
|
||||
"""Session name for STS AssumeRole (used in CloudTrail). Not a secret — stored unencrypted."""
|
||||
|
||||
audience: Optional[str]
|
||||
audience: str | None
|
||||
"""
|
||||
Target audience for OAuth 2.0 Token Exchange (RFC 8693).
|
||||
|
||||
|
|
@ -142,7 +143,7 @@ class MCPCredentials(TypedDict, total=False):
|
|||
stripped from the stored blob. Prefer the top-level request field.
|
||||
"""
|
||||
|
||||
token_exchange_endpoint: Optional[str]
|
||||
token_exchange_endpoint: str | None
|
||||
"""
|
||||
IDP token endpoint for OAuth 2.0 Token Exchange (RFC 8693).
|
||||
|
||||
|
|
@ -151,7 +152,7 @@ class MCPCredentials(TypedDict, total=False):
|
|||
authoritative. Prefer the top-level request field.
|
||||
"""
|
||||
|
||||
subject_token_type: Optional[str]
|
||||
subject_token_type: str | None
|
||||
"""
|
||||
Subject token type for OAuth 2.0 Token Exchange (RFC 8693).
|
||||
Default: DEFAULT_SUBJECT_TOKEN_TYPE (urn:ietf:params:oauth:token-type:access_token).
|
||||
|
|
@ -161,12 +162,12 @@ class MCPCredentials(TypedDict, total=False):
|
|||
the top-level request field.
|
||||
"""
|
||||
|
||||
id_jag_resource_token_endpoint: Optional[str]
|
||||
id_jag_resource_token_endpoint: str | None
|
||||
"""
|
||||
Resource authorization server JWT-bearer (RFC 7523) endpoint for ID-JAG leg 2
|
||||
"""
|
||||
|
||||
id_jag_resource: Optional[str]
|
||||
id_jag_resource: str | None
|
||||
"""
|
||||
Optional RFC 8707 resource indicator sent on ID-JAG leg 1
|
||||
"""
|
||||
|
|
@ -180,28 +181,28 @@ class MCPCredentials(TypedDict, total=False):
|
|||
``audience``, which is the RFC 8693 token-exchange parameter.
|
||||
"""
|
||||
|
||||
client_private_key: Optional[str]
|
||||
client_private_key: str | None
|
||||
"""
|
||||
PEM private key used to sign the private-key-JWT client_assertion (RFC 7523)
|
||||
"""
|
||||
|
||||
client_private_key_id: Optional[str]
|
||||
client_private_key_id: str | None
|
||||
"""
|
||||
Key id (kid) advertised in the client_assertion JWT header
|
||||
"""
|
||||
|
||||
client_assertion_signing_alg: Optional[str]
|
||||
client_assertion_signing_alg: str | None
|
||||
"""
|
||||
Signing algorithm for the client_assertion JWT. Default: RS256
|
||||
"""
|
||||
|
||||
token_endpoint_auth_method: Optional[MCPTokenEndpointAuthMethod]
|
||||
token_endpoint_auth_method: MCPTokenEndpointAuthMethod | None
|
||||
"""
|
||||
How the gateway authenticates to the upstream token endpoint. "client_secret_basic"
|
||||
sends HTTP Basic; defaults to "client_secret_post" when unset.
|
||||
"""
|
||||
|
||||
redirect_uris: Optional[List[str]]
|
||||
redirect_uris: list[str] | None
|
||||
"""
|
||||
The redirect URIs a dynamically registered (RFC 7591) OAuth client was bound to at
|
||||
registration time. Lets a later registration detect that the proxy's public origin no
|
||||
|
|
@ -210,7 +211,7 @@ class MCPCredentials(TypedDict, total=False):
|
|||
this field existed. Not a secret; stored unencrypted.
|
||||
"""
|
||||
|
||||
token_exchange_profile: Optional[str]
|
||||
token_exchange_profile: str | None
|
||||
"""
|
||||
Token exchange wire dialect: "rfc8693" (default, the standard token-exchange grant) or
|
||||
"entra_obo" (Microsoft Entra On-Behalf-Of, the RFC 7523 jwt-bearer grant + requested_token_use
|
||||
|
|
@ -228,12 +229,12 @@ MCP_ADMIN_CONFIG_CREDENTIAL_KEYS: Final[tuple[str, ...]] = ("upstream_resource",
|
|||
|
||||
|
||||
class MCPServerCostInfo(TypedDict, total=False):
|
||||
default_cost_per_query: Optional[float]
|
||||
default_cost_per_query: float | None
|
||||
"""
|
||||
Default cost per query for the MCP server tool call
|
||||
"""
|
||||
|
||||
tool_name_to_cost_per_query: Optional[Dict[str, float]]
|
||||
tool_name_to_cost_per_query: dict[str, float] | None
|
||||
"""
|
||||
Granular, set a custom cost for each tool in the MCP server
|
||||
"""
|
||||
|
|
@ -245,12 +246,12 @@ class MCPStdioConfig(TypedDict, total=False):
|
|||
Command to run the MCP server (e.g., 'npx', 'python', 'node')
|
||||
"""
|
||||
|
||||
args: List[str]
|
||||
args: list[str]
|
||||
"""
|
||||
Arguments to pass to the command
|
||||
"""
|
||||
|
||||
env: Optional[Dict[str, str]]
|
||||
env: dict[str, str] | None
|
||||
"""
|
||||
Environment variables to set when running the command
|
||||
"""
|
||||
|
|
@ -262,9 +263,9 @@ class MCPPreCallRequestObject(BaseModel):
|
|||
"""
|
||||
|
||||
tool_name: str
|
||||
arguments: Dict[str, Any]
|
||||
server_name: Optional[str] = None
|
||||
user_api_key_auth: Optional[Dict[str, Any]] = None
|
||||
arguments: dict[str, Any]
|
||||
server_name: str | None = None
|
||||
user_api_key_auth: dict[str, Any] | None = None
|
||||
hidden_params: HiddenParams = HiddenParams()
|
||||
|
||||
|
||||
|
|
@ -274,8 +275,8 @@ class MCPPreCallResponseObject(BaseModel):
|
|||
"""
|
||||
|
||||
should_proceed: bool = True
|
||||
modified_arguments: Optional[Dict[str, Any]] = None
|
||||
error_message: Optional[str] = None
|
||||
modified_arguments: dict[str, Any] | None = None
|
||||
error_message: str | None = None
|
||||
hidden_params: HiddenParams = HiddenParams()
|
||||
|
||||
|
||||
|
|
@ -285,9 +286,9 @@ class MCPDuringCallRequestObject(BaseModel):
|
|||
"""
|
||||
|
||||
tool_name: str
|
||||
arguments: Dict[str, Any]
|
||||
server_name: Optional[str] = None
|
||||
start_time: Optional[float] = None
|
||||
arguments: dict[str, Any]
|
||||
server_name: str | None = None
|
||||
start_time: float | None = None
|
||||
hidden_params: HiddenParams = HiddenParams()
|
||||
|
||||
|
||||
|
|
@ -297,7 +298,7 @@ class MCPDuringCallResponseObject(BaseModel):
|
|||
"""
|
||||
|
||||
should_continue: bool = True
|
||||
error_message: Optional[str] = None
|
||||
error_message: str | None = None
|
||||
hidden_params: HiddenParams = HiddenParams()
|
||||
|
||||
|
||||
|
|
@ -306,5 +307,5 @@ class MCPPostCallResponseObject(BaseModel):
|
|||
Pydantic object used for MCP post_call_hook response
|
||||
"""
|
||||
|
||||
mcp_tool_call_response: List[Union[MCPTextContent, MCPImageContent, MCPEmbeddedResource]]
|
||||
mcp_tool_call_response: list[MCPTextContent | MCPImageContent | MCPEmbeddedResource]
|
||||
hidden_params: HiddenParams
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
from datetime import datetime
|
||||
from typing import Any, Dict, Final, List, Literal, Optional
|
||||
from typing import Any, Final, Literal
|
||||
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
|
||||
|
|
@ -12,21 +12,21 @@ from litellm.types.mcp import (
|
|||
)
|
||||
|
||||
# MCPInfo now allows arbitrary additional fields for custom metadata
|
||||
MCPInfo = Dict[str, Any]
|
||||
MCPInfo = dict[str, Any]
|
||||
|
||||
|
||||
class MCPOAuthMetadata(BaseModel):
|
||||
scopes: Optional[List[str]] = None
|
||||
scopes: list[str] | None = None
|
||||
"""Resource-driven scopes for the authorization request: the RFC 9728 protected-resource
|
||||
``scopes_supported``, or the ``scope`` from the WWW-Authenticate 401 challenge when the resource
|
||||
supplied one, else the authorization server's ``scopes_supported``. This is the scope value a
|
||||
client requests per the MCP authorization spec Scope Selection Strategy; scope minimization and
|
||||
inflation control are the authorization server's and user's job at consent (RFC 6749 §3.3), not
|
||||
the client's."""
|
||||
authorization_url: Optional[str] = None
|
||||
token_url: Optional[str] = None
|
||||
registration_url: Optional[str] = None
|
||||
discovered_issuer: Optional[str] = None
|
||||
authorization_url: str | None = None
|
||||
token_url: str | None = None
|
||||
registration_url: str | None = None
|
||||
discovered_issuer: str | None = None
|
||||
"""The ``issuer`` the authorization-server metadata document self-attests (RFC 8414). Persisted
|
||||
trust-on-first-use as the server's ``issuer`` when none is configured, so that later rebuilds
|
||||
anchor discovery on it (RFC 8414 §3.3) and a subsequently compromised resource cannot re-point
|
||||
|
|
@ -40,75 +40,75 @@ class MCPOAuthMetadata(BaseModel):
|
|||
class MCPServer(BaseModel):
|
||||
server_id: str
|
||||
name: str
|
||||
alias: Optional[str] = None
|
||||
server_name: Optional[str] = None
|
||||
url: Optional[str] = None
|
||||
alias: str | None = None
|
||||
server_name: str | None = None
|
||||
url: str | None = None
|
||||
transport: MCPTransportType
|
||||
spec_path: Optional[str] = None
|
||||
auth_type: Optional[MCPAuthType] = None
|
||||
authentication_token: Optional[str] = None
|
||||
instructions: Optional[str] = None
|
||||
mcp_info: Optional[MCPInfo] = None
|
||||
extra_headers: Optional[List[str]] = (
|
||||
spec_path: str | None = None
|
||||
auth_type: MCPAuthType | None = None
|
||||
authentication_token: str | None = None
|
||||
instructions: str | None = None
|
||||
mcp_info: MCPInfo | None = None
|
||||
extra_headers: list[str] | None = (
|
||||
None # allow admin to specify which headers to forward from client to the MCP server
|
||||
)
|
||||
allowed_tools: Optional[List[str]] = None
|
||||
disallowed_tools: Optional[List[str]] = None
|
||||
tool_name_to_display_name: Optional[Dict[str, str]] = None
|
||||
tool_name_to_description: Optional[Dict[str, str]] = None
|
||||
allowed_params: Optional[Dict[str, List[str]]] = None # map of tool names to allowed parameter lists
|
||||
static_headers: Optional[Dict[str, str]] = None # static headers to forward to the MCP server
|
||||
allowed_tools: list[str] | None = None
|
||||
disallowed_tools: list[str] | None = None
|
||||
tool_name_to_display_name: dict[str, str] | None = None
|
||||
tool_name_to_description: dict[str, str] | None = None
|
||||
allowed_params: dict[str, list[str]] | None = None # map of tool names to allowed parameter lists
|
||||
static_headers: dict[str, str] | None = None # static headers to forward to the MCP server
|
||||
# Admin-configured env vars. Each entry is {name, value, scope, description}.
|
||||
# scope=="global" values are interpolated into static_headers using ${NAME}.
|
||||
# scope=="user" values must be supplied per-user.
|
||||
env_vars: Optional[List[Dict[str, Any]]] = None
|
||||
env_vars: list[dict[str, Any]] | None = None
|
||||
# OAuth-specific fields
|
||||
client_id: Optional[str] = None
|
||||
client_secret: Optional[str] = None
|
||||
issuer: Optional[str] = None
|
||||
client_id: str | None = None
|
||||
client_secret: str | None = None
|
||||
issuer: str | None = None
|
||||
issuer_is_anchored: bool = False
|
||||
scopes: Optional[List[str]] = None
|
||||
authorization_url: Optional[str] = None
|
||||
token_url: Optional[str] = None
|
||||
registration_url: Optional[str] = None
|
||||
scopes: list[str] | None = None
|
||||
authorization_url: str | None = None
|
||||
token_url: str | None = None
|
||||
registration_url: str | None = None
|
||||
# How the gateway authenticates to the upstream token endpoint. When
|
||||
# "client_secret_basic" the credentials go in an HTTP Basic Authorization
|
||||
# header (omitted from the body); None defaults to "client_secret_post".
|
||||
token_endpoint_auth_method: Optional[MCPTokenEndpointAuthMethod] = None
|
||||
token_endpoint_auth_method: MCPTokenEndpointAuthMethod | None = None
|
||||
# RFC 8707 resource indicator sent on this server's upstream oauth2 legs (authorize, both
|
||||
# token grants, and the client_credentials fetch). None omits it, which is the default and
|
||||
# today's behavior; "auto" derives the canonical URI from ``url``; any other value is sent
|
||||
# verbatim. Resolved by ``oauth_utils.resolve_upstream_resource``.
|
||||
upstream_resource: str | None = None
|
||||
# AWS SigV4 fields
|
||||
aws_access_key_id: Optional[str] = None
|
||||
aws_secret_access_key: Optional[str] = None
|
||||
aws_session_token: Optional[str] = None
|
||||
aws_region_name: Optional[str] = None
|
||||
aws_service_name: Optional[str] = None # defaults to "bedrock-agentcore"
|
||||
aws_role_name: Optional[str] = None # IAM role ARN for STS AssumeRole
|
||||
aws_session_name: Optional[str] = None # session name for CloudTrail auditing
|
||||
aws_access_key_id: str | None = None
|
||||
aws_secret_access_key: str | None = None
|
||||
aws_session_token: str | None = None
|
||||
aws_region_name: str | None = None
|
||||
aws_service_name: str | None = None # defaults to "bedrock-agentcore"
|
||||
aws_role_name: str | None = None # IAM role ARN for STS AssumeRole
|
||||
aws_session_name: str | None = None # session name for CloudTrail auditing
|
||||
# Token Exchange (OBO) fields
|
||||
token_exchange_endpoint: Optional[str] = None
|
||||
audience: Optional[str] = None
|
||||
token_exchange_endpoint: str | None = None
|
||||
audience: str | None = None
|
||||
subject_token_type: str = DEFAULT_SUBJECT_TOKEN_TYPE
|
||||
# ID-JAG fields (draft-ietf-oauth-identity-assertion-authz-grant).
|
||||
# Leg 1 reuses token_exchange_endpoint (IdP org-AS), audience (resource-AS
|
||||
# identifier), scopes, subject_token_type, client_id/client_secret. Leg 2
|
||||
# posts the ID-JAG assertion to id_jag_resource_token_endpoint.
|
||||
id_jag_resource_token_endpoint: Optional[str] = None
|
||||
id_jag_resource: Optional[str] = None
|
||||
client_private_key: Optional[str] = None
|
||||
client_private_key_id: Optional[str] = None
|
||||
id_jag_resource_token_endpoint: str | None = None
|
||||
id_jag_resource: str | None = None
|
||||
client_private_key: str | None = None
|
||||
client_private_key_id: str | None = None
|
||||
client_assertion_signing_alg: str = "RS256"
|
||||
# Wire dialect: "rfc8693" (standard token-exchange grant) or "entra_obo" (Microsoft Entra
|
||||
# On-Behalf-Of, the RFC 7523 jwt-bearer grant + requested_token_use extension)
|
||||
token_exchange_profile: str = "rfc8693"
|
||||
# Stdio-specific fields
|
||||
command: Optional[str] = None
|
||||
args: Optional[List[str]] = None
|
||||
env: Optional[Dict[str, str]] = None
|
||||
access_groups: Optional[List[str]] = None
|
||||
command: str | None = None
|
||||
args: list[str] | None = None
|
||||
env: dict[str, str] | None = None
|
||||
access_groups: list[str] | None = None
|
||||
allow_all_keys: bool = False
|
||||
available_on_public_internet: bool = True
|
||||
# Explicit opt-in to upstream-delegated authentication for ``oauth2``
|
||||
|
|
@ -134,36 +134,36 @@ class MCPServer(BaseModel):
|
|||
# ``Authorization`` for non-OAuth reasons (e.g. static bearer tokens). Must
|
||||
# be set explicitly to avoid regressing servers that did not opt in.
|
||||
oauth_passthrough: bool = False
|
||||
dcr_bridge: Optional[bool] = None
|
||||
dcr_bridge: bool | None = None
|
||||
is_byok: bool = False
|
||||
byok_description: List[str] = []
|
||||
byok_api_key_help_url: Optional[str] = None
|
||||
source_url: Optional[str] = None
|
||||
created_at: Optional[datetime] = None
|
||||
updated_at: Optional[datetime] = None
|
||||
byok_description: list[str] = []
|
||||
byok_api_key_help_url: str | None = None
|
||||
source_url: str | None = None
|
||||
created_at: datetime | None = None
|
||||
updated_at: datetime | None = None
|
||||
# OAuth2 flow type. Defaults to None (interactive / authorization_code).
|
||||
# Set to "client_credentials" to enable M2M token fetching.
|
||||
oauth2_flow: Optional[Literal["client_credentials", "authorization_code"]] = None
|
||||
oauth2_flow: Literal["client_credentials", "authorization_code"] | None = None
|
||||
# Per-user OAuth server-side storage config.
|
||||
# token_validation: key-value pairs that must match fields in the OAuth token
|
||||
# response (supports dot-notation for nested fields, e.g. "team.enterprise_id").
|
||||
# Tokens that fail validation are rejected before storage.
|
||||
token_validation: Optional[Dict[str, Any]] = None
|
||||
token_validation: dict[str, Any] | None = None
|
||||
# Optional TTL override (seconds) for the Redis per-user token cache, capped
|
||||
# at the token's expires_in minus the expiry buffer so a cached entry never
|
||||
# outlives the token. Defaults to the token's expires_in minus the expiry
|
||||
# buffer, or MCP_PER_USER_TOKEN_DEFAULT_TTL when expires_in is absent.
|
||||
token_storage_ttl_seconds: Optional[int] = None
|
||||
timeout: Optional[float] = None
|
||||
token_storage_ttl_seconds: int | None = None
|
||||
timeout: float | None = None
|
||||
# Max concurrent outbound tool calls to this server; excess calls queue.
|
||||
# None or a value <= 0 means unlimited.
|
||||
max_concurrent_requests: Optional[int] = None
|
||||
max_concurrent_requests: int | None = None
|
||||
# Resolved short-ID tool prefix when LITELLM_USE_SHORT_MCP_TOOL_PREFIX is
|
||||
# enabled. Set by ``MCPServerManager._assign_unique_short_prefix`` at
|
||||
# registration time so that natural-hash collisions between two
|
||||
# different ``server_id`` values are bumped deterministically. Left
|
||||
# ``None`` in default-prefix mode.
|
||||
short_prefix: Optional[str] = None
|
||||
short_prefix: str | None = None
|
||||
allow_sampling: bool = False
|
||||
allow_elicitation: bool = False
|
||||
model_config = ConfigDict(arbitrary_types_allowed=True)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
from datetime import datetime
|
||||
from typing import List, Optional
|
||||
|
||||
from pydantic import BaseModel
|
||||
from typing_extensions import TypedDict
|
||||
|
|
@ -13,22 +12,22 @@ class MCPToolsetTool(TypedDict):
|
|||
class MCPToolset(BaseModel):
|
||||
toolset_id: str
|
||||
toolset_name: str
|
||||
description: Optional[str] = None
|
||||
tools: List[MCPToolsetTool] = []
|
||||
created_at: Optional[datetime] = None
|
||||
created_by: Optional[str] = None
|
||||
updated_at: Optional[datetime] = None
|
||||
updated_by: Optional[str] = None
|
||||
description: str | None = None
|
||||
tools: list[MCPToolsetTool] = []
|
||||
created_at: datetime | None = None
|
||||
created_by: str | None = None
|
||||
updated_at: datetime | None = None
|
||||
updated_by: str | None = None
|
||||
|
||||
|
||||
class NewMCPToolsetRequest(BaseModel):
|
||||
toolset_name: str
|
||||
description: Optional[str] = None
|
||||
tools: List[MCPToolsetTool] = []
|
||||
description: str | None = None
|
||||
tools: list[MCPToolsetTool] = []
|
||||
|
||||
|
||||
class UpdateMCPToolsetRequest(BaseModel):
|
||||
toolset_id: str
|
||||
toolset_name: Optional[str] = None
|
||||
description: Optional[str] = None
|
||||
tools: Optional[List[MCPToolsetTool]] = None
|
||||
toolset_name: str | None = None
|
||||
description: str | None = None
|
||||
tools: list[MCPToolsetTool] | None = None
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
from typing import Any, Callable, ClassVar, Dict, List, Optional
|
||||
from collections.abc import Callable
|
||||
from typing import Any, ClassVar
|
||||
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
|
||||
|
|
@ -7,27 +8,27 @@ class MCPTool(BaseModel):
|
|||
model_config: ClassVar[ConfigDict] = ConfigDict(arbitrary_types_allowed=True)
|
||||
name: str
|
||||
description: str
|
||||
input_schema: Dict[str, Any]
|
||||
input_schema: dict[str, Any]
|
||||
handler: Callable
|
||||
|
||||
|
||||
class ToolSchema(BaseModel):
|
||||
name: str
|
||||
description: str
|
||||
inputSchema: Dict[str, Any]
|
||||
inputSchema: dict[str, Any]
|
||||
|
||||
|
||||
class ListToolsResponse(BaseModel):
|
||||
tools: List[ToolSchema]
|
||||
nextCursor: Optional[str] = None
|
||||
_meta: Optional[Dict[str, Any]] = None
|
||||
tools: list[ToolSchema]
|
||||
nextCursor: str | None = None
|
||||
_meta: dict[str, Any] | None = None
|
||||
|
||||
|
||||
class CallToolRequest(BaseModel):
|
||||
method: str = "tools/call"
|
||||
params: Dict[str, Any]
|
||||
params: dict[str, Any]
|
||||
|
||||
|
||||
class ContentItem(BaseModel):
|
||||
type: str
|
||||
text: Optional[str] = None
|
||||
text: str | None = None
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ Pydantic models for Memory management endpoints.
|
|||
"""
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Any, List, Optional
|
||||
from typing import Any
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
|
@ -12,44 +12,44 @@ class LiteLLM_MemoryRow(BaseModel):
|
|||
memory_id: str
|
||||
key: str
|
||||
value: str
|
||||
metadata: Optional[Any] = None
|
||||
user_id: Optional[str] = None
|
||||
team_id: Optional[str] = None
|
||||
created_at: Optional[datetime] = None
|
||||
created_by: Optional[str] = None
|
||||
updated_at: Optional[datetime] = None
|
||||
updated_by: Optional[str] = None
|
||||
metadata: Any | None = None
|
||||
user_id: str | None = None
|
||||
team_id: str | None = None
|
||||
created_at: datetime | None = None
|
||||
created_by: str | None = None
|
||||
updated_at: datetime | None = None
|
||||
updated_by: str | None = None
|
||||
|
||||
|
||||
class MemoryCreateRequest(BaseModel):
|
||||
key: str = Field(..., description="Memory key (acts as the namespace in the URL).")
|
||||
value: str = Field(..., description="Memory content. Typically markdown/text for LLM context.")
|
||||
metadata: Optional[Any] = Field(
|
||||
metadata: Any | None = Field(
|
||||
default=None,
|
||||
description="Optional JSON metadata (tags, structured fields).",
|
||||
)
|
||||
user_id: Optional[str] = Field(
|
||||
user_id: str | None = Field(
|
||||
default=None,
|
||||
description="Scope to this user. Defaults to the caller's user_id.",
|
||||
)
|
||||
team_id: Optional[str] = Field(
|
||||
team_id: str | None = Field(
|
||||
default=None,
|
||||
description="Scope to this team. Defaults to the caller's team_id.",
|
||||
)
|
||||
|
||||
|
||||
class MemoryUpdateRequest(BaseModel):
|
||||
value: Optional[str] = None
|
||||
metadata: Optional[Any] = None
|
||||
value: str | None = None
|
||||
metadata: Any | None = None
|
||||
# Only honored on create (when the row doesn't yet exist) and only for
|
||||
# PROXY_ADMIN callers — mirrors MemoryCreateRequest so admins can bootstrap
|
||||
# rows scoped to another user/team via PUT, not just POST.
|
||||
user_id: Optional[str] = None
|
||||
team_id: Optional[str] = None
|
||||
user_id: str | None = None
|
||||
team_id: str | None = None
|
||||
|
||||
|
||||
class MemoryListResponse(BaseModel):
|
||||
memories: List[LiteLLM_MemoryRow]
|
||||
memories: list[LiteLLM_MemoryRow]
|
||||
total: int
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -8,20 +8,18 @@ can adopt the type without violating the SDK-must-not-import-from-proxy
|
|||
layering rule.
|
||||
"""
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from typing_extensions import TypedDict
|
||||
|
||||
|
||||
class ObjectPermissionDict(TypedDict, total=False):
|
||||
mcp_servers: Optional[list[str]]
|
||||
mcp_access_groups: Optional[list[str]]
|
||||
mcp_tool_permissions: Optional[dict[str, list[str]]]
|
||||
mcp_toolsets: Optional[list[str]]
|
||||
blocked_tools: Optional[list[str]]
|
||||
vector_stores: Optional[list[str]]
|
||||
agents: Optional[list[str]]
|
||||
agent_access_groups: Optional[list[str]]
|
||||
models: Optional[list[str]]
|
||||
search_tools: Optional[list[str]]
|
||||
mcp_tool_search_enabled: Optional[bool]
|
||||
mcp_servers: list[str] | None
|
||||
mcp_access_groups: list[str] | None
|
||||
mcp_tool_permissions: dict[str, list[str]] | None
|
||||
mcp_toolsets: list[str] | None
|
||||
blocked_tools: list[str] | None
|
||||
vector_stores: list[str] | None
|
||||
agents: list[str] | None
|
||||
agent_access_groups: list[str] | None
|
||||
models: list[str] | None
|
||||
search_tools: list[str] | None
|
||||
mcp_tool_search_enabled: bool | None
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
from enum import Enum
|
||||
from typing import Final, Optional
|
||||
from typing import Final
|
||||
|
||||
from typing_extensions import TypedDict
|
||||
|
||||
|
|
@ -37,22 +37,22 @@ class PassthroughStandardLoggingPayload(TypedDict, total=False):
|
|||
The full url of the request
|
||||
"""
|
||||
|
||||
request_method: Optional[str]
|
||||
request_method: str | None
|
||||
"""
|
||||
The method of the request
|
||||
"GET", "POST", "PUT", "DELETE", etc.
|
||||
"""
|
||||
|
||||
request_body: Optional[dict]
|
||||
request_body: dict | None
|
||||
"""
|
||||
The body of the request
|
||||
"""
|
||||
response_body: Optional[dict] # only tracked for non-streaming responses
|
||||
response_body: dict | None # only tracked for non-streaming responses
|
||||
"""
|
||||
The body of the response
|
||||
"""
|
||||
|
||||
cost_per_request: Optional[float]
|
||||
cost_per_request: float | None
|
||||
"""
|
||||
The cost per request to the target endpoint
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,6 @@
|
|||
Used for /vertex_ai/ pass through endpoints
|
||||
"""
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from ..llms.vertex_ai import VERTEX_CREDENTIALS_TYPES
|
||||
|
|
@ -11,10 +9,10 @@ from ..llms.vertex_ai import VERTEX_CREDENTIALS_TYPES
|
|||
|
||||
class VertexPassThroughCredentials(BaseModel):
|
||||
# Example: vertex_project = "my-project-123"
|
||||
vertex_project: Optional[str] = None
|
||||
vertex_project: str | None = None
|
||||
|
||||
# Example: vertex_location = "us-central1"
|
||||
vertex_location: Optional[str] = None
|
||||
vertex_location: str | None = None
|
||||
|
||||
# Example: vertex_credentials = "/path/to/credentials.json" or "os.environ/GOOGLE_CREDS"
|
||||
vertex_credentials: Optional[VERTEX_CREDENTIALS_TYPES] = None
|
||||
vertex_credentials: VERTEX_CREDENTIALS_TYPES | None = None
|
||||
|
|
|
|||
|
|
@ -24,13 +24,13 @@ __all__ = [
|
|||
"Policy",
|
||||
"PolicyConfig",
|
||||
"PolicyGuardrails",
|
||||
# Resolver types
|
||||
"PolicyMatchContext",
|
||||
"PolicyScope",
|
||||
# Validation types
|
||||
"PolicyValidateRequest",
|
||||
"PolicyValidationError",
|
||||
"PolicyValidationErrorType",
|
||||
"PolicyValidationResponse",
|
||||
# Resolver types
|
||||
"PolicyMatchContext",
|
||||
"ResolvedPolicy",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
from datetime import datetime
|
||||
from enum import Enum
|
||||
from typing import Any, Dict, List, Literal, Optional
|
||||
from typing import Any, Literal
|
||||
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
|
||||
|
|
@ -17,24 +17,24 @@ class SupportedPromptIntegrations(str, Enum):
|
|||
|
||||
class PromptInfo(BaseModel):
|
||||
prompt_type: Literal["config", "db"]
|
||||
environment: Optional[str] = "development"
|
||||
environment: str | None = "development"
|
||||
|
||||
model_config = ConfigDict(extra="allow", protected_namespaces=())
|
||||
|
||||
|
||||
class PromptLiteLLMParams(BaseModel):
|
||||
prompt_id: Optional[str] = None
|
||||
prompt_id: str | None = None
|
||||
prompt_integration: str
|
||||
|
||||
api_base: Optional[str] = None
|
||||
api_key: Optional[str] = None
|
||||
api_base: str | None = None
|
||||
api_key: str | None = None
|
||||
|
||||
provider_specific_query_params: Optional[Dict[str, Any]] = None
|
||||
provider_specific_query_params: dict[str, Any] | None = None
|
||||
|
||||
ignore_prompt_manager_model: Optional[bool] = False
|
||||
ignore_prompt_manager_optional_params: Optional[bool] = False
|
||||
ignore_prompt_manager_model: bool | None = False
|
||||
ignore_prompt_manager_optional_params: bool | None = False
|
||||
|
||||
dotprompt_content: Optional[str] = None
|
||||
dotprompt_content: str | None = None
|
||||
"""
|
||||
allows saving the dotprompt file content
|
||||
"""
|
||||
|
|
@ -46,13 +46,13 @@ class PromptSpec(BaseModel):
|
|||
prompt_id: str
|
||||
litellm_params: PromptLiteLLMParams
|
||||
prompt_info: PromptInfo
|
||||
created_at: Optional[datetime] = None
|
||||
updated_at: Optional[datetime] = None
|
||||
version: Optional[int] = None # Version number for version history
|
||||
environment: Optional[str] = "development"
|
||||
created_by: Optional[str] = None
|
||||
created_at: datetime | None = None
|
||||
updated_at: datetime | None = None
|
||||
version: int | None = None # Version number for version history
|
||||
environment: str | None = "development"
|
||||
created_by: str | None = None
|
||||
|
||||
def __init__(self, **data):
|
||||
def __init__(self, **data) -> None:
|
||||
if "prompt_info" not in data:
|
||||
data["prompt_info"] = PromptInfo(prompt_type="config")
|
||||
elif "prompt_info" in data:
|
||||
|
|
@ -64,14 +64,14 @@ class PromptSpec(BaseModel):
|
|||
class PromptTemplateBase(BaseModel):
|
||||
litellm_prompt_id: str
|
||||
content: str
|
||||
metadata: Optional[Dict[str, Any]] = None
|
||||
metadata: dict[str, Any] | None = None
|
||||
|
||||
|
||||
class PromptInfoResponse(BaseModel):
|
||||
prompt_spec: PromptSpec
|
||||
raw_prompt_template: Optional[PromptTemplateBase] = None
|
||||
environments: Optional[List[str]] = None # All environments this prompt is deployed to
|
||||
raw_prompt_template: PromptTemplateBase | None = None
|
||||
environments: list[str] | None = None # All environments this prompt is deployed to
|
||||
|
||||
|
||||
class ListPromptsResponse(BaseModel):
|
||||
prompts: List[PromptSpec]
|
||||
prompts: list[PromptSpec]
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ External producers (e.g. the litellm-rust gateway) POST finished logging
|
|||
payloads here; the proxy replays them through the standard callback fan-out.
|
||||
"""
|
||||
|
||||
from typing import Any, Literal, Optional
|
||||
from typing import Any, Literal
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
|
@ -17,7 +17,7 @@ class CallbackLogRecord(BaseModel):
|
|||
|
||||
status: Literal["success", "failure"]
|
||||
standard_logging_payload: dict[str, Any]
|
||||
error: Optional[str] = None
|
||||
error: str | None = None
|
||||
|
||||
|
||||
class CallbackLogsRequest(BaseModel):
|
||||
|
|
|
|||
|
|
@ -2,8 +2,6 @@
|
|||
Claude Code Marketplace endpoint types for LiteLLM Proxy
|
||||
"""
|
||||
|
||||
from typing import Dict, List, Optional
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
|
|
@ -11,20 +9,20 @@ class PluginAuthor(BaseModel):
|
|||
"""Plugin author information."""
|
||||
|
||||
name: str = Field(..., description="Author name")
|
||||
email: Optional[str] = Field(None, description="Author email")
|
||||
email: str | None = Field(None, description="Author email")
|
||||
|
||||
|
||||
class PluginOwner(BaseModel):
|
||||
"""Marketplace owner information."""
|
||||
|
||||
name: str = Field(..., description="Owner name")
|
||||
email: Optional[str] = Field(None, description="Owner email")
|
||||
email: str | None = Field(None, description="Owner email")
|
||||
|
||||
|
||||
class PluginSpec(BaseModel):
|
||||
"""Mutable fields shared by plugin create and update requests."""
|
||||
|
||||
source: Dict[str, str] = Field(
|
||||
source: dict[str, str] = Field(
|
||||
...,
|
||||
description=(
|
||||
"Git source reference. Supported formats:\n"
|
||||
|
|
@ -33,14 +31,14 @@ class PluginSpec(BaseModel):
|
|||
"- Git Subdir: {'source': 'git-subdir', 'url': 'https://github.com/org/repo.git', 'path': 'plugins/plugin-name'}"
|
||||
),
|
||||
)
|
||||
version: Optional[str] = Field("1.0.0", description="Semantic version")
|
||||
description: Optional[str] = Field(None, description="Plugin description")
|
||||
author: Optional[PluginAuthor] = Field(None, description="Plugin author")
|
||||
homepage: Optional[str] = Field(None, description="Plugin homepage URL")
|
||||
keywords: Optional[List[str]] = Field(None, description="Search keywords")
|
||||
category: Optional[str] = Field(None, description="Plugin category")
|
||||
domain: Optional[str] = Field(None, description="Skill domain (e.g., 'Productivity')")
|
||||
namespace: Optional[str] = Field(None, description="Skill namespace within domain (e.g., 'workflows')")
|
||||
version: str | None = Field("1.0.0", description="Semantic version")
|
||||
description: str | None = Field(None, description="Plugin description")
|
||||
author: PluginAuthor | None = Field(None, description="Plugin author")
|
||||
homepage: str | None = Field(None, description="Plugin homepage URL")
|
||||
keywords: list[str] | None = Field(None, description="Search keywords")
|
||||
category: str | None = Field(None, description="Plugin category")
|
||||
domain: str | None = Field(None, description="Skill domain (e.g., 'Productivity')")
|
||||
namespace: str | None = Field(None, description="Skill namespace within domain (e.g., 'workflows')")
|
||||
|
||||
|
||||
class RegisterPluginRequest(PluginSpec):
|
||||
|
|
@ -76,9 +74,9 @@ class PluginResponse(BaseModel):
|
|||
|
||||
id: str = Field(..., description="Plugin unique ID")
|
||||
name: str = Field(..., description="Plugin name")
|
||||
version: Optional[str] = Field(None, description="Plugin version")
|
||||
description: Optional[str] = Field(None, description="Plugin description")
|
||||
source: Dict[str, str] = Field(..., description="Git source reference")
|
||||
version: str | None = Field(None, description="Plugin version")
|
||||
description: str | None = Field(None, description="Plugin description")
|
||||
source: dict[str, str] = Field(..., description="Git source reference")
|
||||
enabled: bool = Field(..., description="Whether plugin is enabled")
|
||||
|
||||
|
||||
|
|
@ -95,24 +93,24 @@ class PluginListItem(BaseModel):
|
|||
|
||||
id: str
|
||||
name: str
|
||||
version: Optional[str]
|
||||
description: Optional[str]
|
||||
source: Dict[str, str]
|
||||
author: Optional[PluginAuthor] = None
|
||||
homepage: Optional[str] = None
|
||||
keywords: Optional[List[str]] = None
|
||||
category: Optional[str] = None
|
||||
domain: Optional[str] = None
|
||||
namespace: Optional[str] = None
|
||||
version: str | None
|
||||
description: str | None
|
||||
source: dict[str, str]
|
||||
author: PluginAuthor | None = None
|
||||
homepage: str | None = None
|
||||
keywords: list[str] | None = None
|
||||
category: str | None = None
|
||||
domain: str | None = None
|
||||
namespace: str | None = None
|
||||
enabled: bool
|
||||
created_at: Optional[str]
|
||||
updated_at: Optional[str]
|
||||
created_at: str | None
|
||||
updated_at: str | None
|
||||
|
||||
|
||||
class ListPluginsResponse(BaseModel):
|
||||
"""Response from listing plugins."""
|
||||
|
||||
plugins: List[PluginListItem]
|
||||
plugins: list[PluginListItem]
|
||||
count: int
|
||||
|
||||
|
||||
|
|
@ -120,13 +118,13 @@ class MarketplacePluginEntry(BaseModel):
|
|||
"""Plugin entry in marketplace.json."""
|
||||
|
||||
name: str
|
||||
source: Dict[str, str]
|
||||
version: Optional[str] = None
|
||||
description: Optional[str] = None
|
||||
author: Optional[PluginAuthor] = None
|
||||
homepage: Optional[str] = None
|
||||
keywords: Optional[List[str]] = None
|
||||
category: Optional[str] = None
|
||||
source: dict[str, str]
|
||||
version: str | None = None
|
||||
description: str | None = None
|
||||
author: PluginAuthor | None = None
|
||||
homepage: str | None = None
|
||||
keywords: list[str] | None = None
|
||||
category: str | None = None
|
||||
|
||||
|
||||
class MarketplaceResponse(BaseModel):
|
||||
|
|
@ -139,4 +137,4 @@ class MarketplaceResponse(BaseModel):
|
|||
|
||||
name: str = Field(..., description="Marketplace identifier")
|
||||
owner: PluginOwner = Field(..., description="Marketplace owner")
|
||||
plugins: List[MarketplacePluginEntry] = Field(default_factory=list, description="Available plugins")
|
||||
plugins: list[MarketplacePluginEntry] = Field(default_factory=list, description="Available plugins")
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ CloudZero endpoint types for LiteLLM Proxy
|
|||
"""
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Any, Dict, List, Optional
|
||||
from typing import Any
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
|
@ -26,13 +26,13 @@ class CloudZeroInitResponse(BaseModel):
|
|||
class CloudZeroExportRequest(BaseModel):
|
||||
"""Request model for CloudZero export operations"""
|
||||
|
||||
limit: Optional[int] = Field(None, description="Optional limit on number of records to export")
|
||||
limit: int | None = Field(None, description="Optional limit on number of records to export")
|
||||
operation: str = Field(
|
||||
default="replace_hourly",
|
||||
description="CloudZero operation type (replace_hourly or sum)",
|
||||
)
|
||||
start_time_utc: Optional[datetime] = Field(None, description="Start time for data export in UTC")
|
||||
end_time_utc: Optional[datetime] = Field(None, description="End time for data export in UTC")
|
||||
start_time_utc: datetime | None = Field(None, description="Start time for data export in UTC")
|
||||
end_time_utc: datetime | None = Field(None, description="End time for data export in UTC")
|
||||
|
||||
|
||||
class CloudZeroExportResponse(BaseModel):
|
||||
|
|
@ -40,25 +40,25 @@ class CloudZeroExportResponse(BaseModel):
|
|||
|
||||
message: str
|
||||
status: str
|
||||
records_exported: Optional[int] = None
|
||||
dry_run_data: Optional[Dict[str, Any]] = Field(
|
||||
records_exported: int | None = None
|
||||
dry_run_data: dict[str, Any] | None = Field(
|
||||
None, description="Dry run data including usage data and CBF transformed data"
|
||||
)
|
||||
summary: Optional[Dict[str, Any]] = Field(None, description="Summary statistics for dry run")
|
||||
summary: dict[str, Any] | None = Field(None, description="Summary statistics for dry run")
|
||||
|
||||
|
||||
class CloudZeroSettingsView(BaseModel):
|
||||
"""Response model for viewing CloudZero settings with masked API key"""
|
||||
|
||||
api_key_masked: Optional[str] = Field(None, description="Masked API key showing only first 4 and last 4 characters")
|
||||
connection_id: Optional[str] = Field(None, description="CloudZero connection ID for data submission")
|
||||
timezone: Optional[str] = Field(None, description="Timezone for date handling")
|
||||
status: Optional[str] = Field(None, description="Configuration status")
|
||||
api_key_masked: str | None = Field(None, description="Masked API key showing only first 4 and last 4 characters")
|
||||
connection_id: str | None = Field(None, description="CloudZero connection ID for data submission")
|
||||
timezone: str | None = Field(None, description="Timezone for date handling")
|
||||
status: str | None = Field(None, description="Configuration status")
|
||||
|
||||
|
||||
class CloudZeroSettingsUpdate(BaseModel):
|
||||
"""Request model for updating CloudZero settings"""
|
||||
|
||||
api_key: Optional[str] = Field(None, description="New CloudZero API key for authentication")
|
||||
connection_id: Optional[str] = Field(None, description="New CloudZero connection ID for data submission")
|
||||
timezone: Optional[str] = Field(None, description="New timezone for date handling")
|
||||
api_key: str | None = Field(None, description="New CloudZero API key for authentication")
|
||||
connection_id: str | None = Field(None, description="New CloudZero connection ID for data submission")
|
||||
timezone: str | None = Field(None, description="New timezone for date handling")
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from typing import List, Optional
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
|
|
@ -17,7 +15,7 @@ class ComplianceResponse(BaseModel):
|
|||
|
||||
compliant: bool
|
||||
regulation: str
|
||||
checks: List[ComplianceCheckResult]
|
||||
checks: list[ComplianceCheckResult]
|
||||
|
||||
|
||||
class ComplianceCheckRequest(BaseModel):
|
||||
|
|
@ -27,7 +25,7 @@ class ComplianceCheckRequest(BaseModel):
|
|||
"""
|
||||
|
||||
request_id: str
|
||||
user_id: Optional[str] = None
|
||||
model: Optional[str] = None
|
||||
timestamp: Optional[str] = None
|
||||
guardrail_information: Optional[List[dict]] = None
|
||||
user_id: str | None = None
|
||||
model: str | None = None
|
||||
timestamp: str | None = None
|
||||
guardrail_information: list[dict] | None = None
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from typing import List, Optional
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from litellm.types.proxy.control_plane_endpoints import WorkerRegistryEntry
|
||||
|
|
@ -7,10 +5,10 @@ from litellm.types.proxy.control_plane_endpoints import WorkerRegistryEntry
|
|||
|
||||
class UiDiscoveryEndpoints(BaseModel):
|
||||
server_root_path: str
|
||||
proxy_base_url: Optional[str]
|
||||
proxy_base_url: str | None
|
||||
auto_redirect_to_sso: bool
|
||||
admin_ui_disabled: bool
|
||||
sso_configured: bool
|
||||
hide_default_credentials_hint: bool = False
|
||||
is_control_plane: bool = False
|
||||
workers: List[WorkerRegistryEntry] = []
|
||||
workers: list[WorkerRegistryEntry] = []
|
||||
|
|
|
|||
|
|
@ -1,16 +1,14 @@
|
|||
from typing import Optional
|
||||
|
||||
from pydantic import Field
|
||||
|
||||
from .base import GuardrailConfigModel
|
||||
|
||||
|
||||
class AimGuardrailConfigModel(GuardrailConfigModel):
|
||||
api_key: Optional[str] = Field(
|
||||
api_key: str | None = Field(
|
||||
default=None,
|
||||
description="The API key for the Aim guardrail. If not provided, the `AIM_API_KEY` environment variable is checked.",
|
||||
)
|
||||
api_base: Optional[str] = Field(
|
||||
api_base: str | None = Field(
|
||||
default=None,
|
||||
description="The API base for the Aim guardrail. Default is https://api.aim.security. Also checks if the `AIM_API_BASE` environment variable is set.",
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
from typing import Optional, Literal
|
||||
from typing import Literal
|
||||
|
||||
from pydantic import Field
|
||||
|
||||
|
|
@ -14,7 +14,7 @@ class AktoConfigModel(GuardrailConfigModel):
|
|||
akto-ingest (mode: post_call) -> ingest request+response data
|
||||
"""
|
||||
|
||||
akto_base_url: Optional[str] = Field(
|
||||
akto_base_url: str | None = Field(
|
||||
default=None,
|
||||
description="Akto Guardrail API Base URL. Env: AKTO_GUARDRAIL_API_BASE.",
|
||||
json_schema_extra={
|
||||
|
|
@ -25,17 +25,17 @@ class AktoConfigModel(GuardrailConfigModel):
|
|||
},
|
||||
)
|
||||
|
||||
akto_api_key: Optional[str] = Field(
|
||||
akto_api_key: str | None = Field(
|
||||
default=None,
|
||||
description="API key for Akto. Env: AKTO_API_KEY.",
|
||||
)
|
||||
|
||||
akto_account_id: Optional[str] = Field(
|
||||
akto_account_id: str | None = Field(
|
||||
default=None,
|
||||
description="Akto account ID for multi-tenant deployments. Env: AKTO_ACCOUNT_ID. Default: '1000000'.",
|
||||
)
|
||||
|
||||
akto_vxlan_id: Optional[str] = Field(
|
||||
akto_vxlan_id: str | None = Field(
|
||||
default=None,
|
||||
description="Akto VXLAN ID. Env: AKTO_VXLAN_ID. Default: '0'.",
|
||||
)
|
||||
|
|
@ -45,7 +45,7 @@ class AktoConfigModel(GuardrailConfigModel):
|
|||
description="What to do when Akto is unreachable. 'fail_open' = allow, 'fail_closed' = block.",
|
||||
)
|
||||
|
||||
guardrail_timeout: Optional[int] = Field(
|
||||
guardrail_timeout: int | None = Field(
|
||||
default=None,
|
||||
description="HTTP timeout in seconds. Default: 5.",
|
||||
)
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue