Coverage for src\funcall\types.py: 89%
25 statements
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-28 01:17 +0900
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-28 01:17 +0900
1from typing import Generic, Literal, Required, TypedDict, TypeVar, Union, get_args
3T = TypeVar("T")
6class Context(Generic[T]):
7 """Generic context container for dependency injection in function calls."""
9 def __init__(self, value: T | None = None) -> None:
10 self.value = value
13class LiteLLMFunctionSpec(TypedDict):
14 """Type definition for LiteLLM function specification."""
16 name: Required[str]
17 parameters: Required[dict[str, object] | None]
18 strict: Required[bool | None]
19 type: Required[Literal["function"]]
20 description: str | None
23class LiteLLMFunctionToolParam(TypedDict):
24 """Type definition for LiteLLM function tool parameter."""
26 type: Literal["function"]
27 function: Required[LiteLLMFunctionSpec]
30class ToolMeta(TypedDict):
31 require_confirm: bool
32 return_direct: bool
35def is_context_type(hint: type) -> bool:
36 return getattr(hint, "__origin__", None) is Context or hint is Context
39def is_optional_type(hint: type) -> bool:
40 origin = getattr(hint, "__origin__", None)
41 if origin is Union: 41 ↛ 42line 41 didn't jump to line 42 because the condition on line 41 was never true
42 args = get_args(hint)
43 return any(a is type(None) for a in args)
44 return False