Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7c2299a
add mypy-based validation, drop syntactic check on return type
kiranandcode Feb 4, 2026
88b5eb9
resurrects tests for test_handlers_llm_encoding.py
kiranandcode Feb 4, 2026
511b8dc
switched to type error instead of value error
kiranandcode Feb 4, 2026
031f740
neatened up type checking tests
kiranandcode Feb 4, 2026
84c3dca
added mypy to llm dependencies
kiranandcode Feb 5, 2026
fd71991
switched to use typing_extensions TypeAliasType
kiranandcode Feb 5, 2026
de6d2ff
moved type checking to an operation
kiranandcode Feb 5, 2026
9e3b7cc
refined exception guard and switched to any instead of skipping bindi…
kiranandcode Feb 5, 2026
fbd8a2d
refactored code to construct asts, added more systematic tests, and c…
kiranandcode Feb 5, 2026
9767665
updated deps of llm submodule
kiranandcode Feb 5, 2026
d15a3c9
llm tests all pass
kiranandcode Feb 5, 2026
bb5a13e
minor bug
kiranandcode Feb 5, 2026
8f56e4b
ruff formatting
kiranandcode Feb 5, 2026
a8c0e92
updated imports to include sys.modules
kiranandcode Feb 6, 2026
a13f453
restricted sys.modules in imports and suppressed warnings on importin…
kiranandcode Feb 6, 2026
2e86880
added ignore to ast.FunctionDef
kiranandcode Feb 6, 2026
2b04109
updated to use ruff to clean up generated code and avoid redundant my…
kiranandcode Feb 6, 2026
2a847f2
updated codeadapt fixture
kiranandcode Feb 6, 2026
3d99205
added --unsafe-fixes to ruff invocation
kiranandcode Feb 6, 2026
6999c36
updated prompt
kiranandcode Feb 6, 2026
4f14c3f
format notebook
kiranandcode Feb 6, 2026
3d1d814
format notebook
kiranandcode Feb 6, 2026
918e899
switched from ruff to autoflake
kiranandcode Feb 6, 2026
7db4e03
fix for __init__
kiranandcode Feb 6, 2026
b2dcaf1
fixed test with __init__ returning None
kiranandcode Feb 6, 2026
02eba96
final fixes
kiranandcode Feb 6, 2026
1b1501b
added type_checking
kiranandcode Feb 6, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,706 changes: 853 additions & 853 deletions docs/source/llm.ipynb

Large diffs are not rendered by default.

17 changes: 7 additions & 10 deletions effectful/handlers/llm/encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def _format_callable_type(callable_type: type[Callable]) -> str:

if param_types is ...:
params_str = "..."
elif isinstance(param_types, (list, tuple)):
elif isinstance(param_types, list | tuple):
params_str = ", ".join(getattr(t, "__name__", str(t)) for t in param_types)
else:
params_str = str(param_types)
Expand Down Expand Up @@ -366,14 +366,6 @@ def _validate_signature_callable(
"decode() requires synthesized function to have a return type annotation"
)

expected_name = getattr(expected_return, "__name__", str(expected_return))
actual_name = getattr(actual_return, "__name__", str(actual_return))
if expected_name != actual_name:
raise ValueError(
f"decode() expected function with return type {expected_name}, "
f"got {actual_name}"
)


@dataclass
class CallableEncodable(Encodable[Callable, SynthesizedFunction]):
Expand Down Expand Up @@ -455,6 +447,11 @@ def decode(self, encoded_value: SynthesizedFunction) -> Callable:
# Validate signature from AST before execution
_validate_signature_ast(last_stmt, self.expected_params)

# Type-check with mypy; pass original module_code so mypy sees exact source
evaluation.type_check(
module, self.ctx, self.expected_params, self.expected_return
)

# Compile and execute
# https://docs.python.org/3/library/functions.html#exec
g: MutableMapping[str, Any] = {}
Expand Down Expand Up @@ -620,7 +617,7 @@ def _encodable_callable(

# Ellipsis means any params, skip param validation
expected_params: list[type] | None = None
if param_types is not ... and isinstance(param_types, (list, tuple)):
if param_types is not ... and isinstance(param_types, list | tuple):
expected_params = list(param_types)

return CallableEncodable(ty, typed_enc, ctx, expected_params, expected_return)
Loading
Loading