-
Notifications
You must be signed in to change notification settings - Fork 3
Implement internal synthesis API #519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
c192c78
Fresh diff
kiranandcode ea3d25c
remove instructionhandler
eb8680 f83d312
updated internal interface to make all tests pass
kiranandcode d8d52e7
fixed caching tests
kiranandcode a322a35
updated llm.ipynb
kiranandcode 41beb78
removed unnecessarily defensive validation
kiranandcode 1400d19
updated tool call decoding to use concrete type of tool result instea…
kiranandcode a06296d
updated completions to fix basic type errors
kiranandcode c47abd6
updated call assistant to handle decoding tool calls
kiranandcode 43e5b78
dropped stale comments
kiranandcode 6bb2b13
moved model and param model back to internals of `completions`
kiranandcode 88da657
added default encodable instance for Callable
kiranandcode 88c65ee
fixed type errors
kiranandcode 18da11b
update to use more structured type for synthesis
kiranandcode 52df3f6
updated callable encoding tests
kiranandcode 4b10ac3
s/TypeError/NotImplementedError
kiranandcode 2a8af94
Merge branch 'master' into kg-encodable-default
kiranandcode 2b4449a
simplified smart constructor
kiranandcode 553450f
bare callables not allowed
kiranandcode aac0eb9
droped synthesis and removed encoding_instructions
kiranandcode 5b3a559
fixed imports
kiranandcode 711b27d
fixed imports and tests
kiranandcode File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| import ast | ||
| import builtins | ||
| import linecache | ||
| import typing | ||
| from types import CodeType | ||
| from typing import Any | ||
|
|
||
| from effectful.ops.syntax import ObjectInterpretation, defop, implements | ||
|
|
||
|
|
||
| @defop | ||
| def parse(source: str, filename: str) -> ast.Module: | ||
| """ | ||
| Parse source text into an AST. | ||
|
|
||
| source: The Python source code to parse. | ||
| filename: The filename recorded in the resulting AST for tracebacks and tooling. | ||
|
|
||
| Returns the parsed AST. | ||
| """ | ||
| raise NotImplementedError( | ||
| "An eval provider must be installed in order to parse code." | ||
| ) | ||
|
|
||
|
|
||
| @defop | ||
| def compile(module: ast.Module, filename: str) -> CodeType: | ||
eb8680 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| """ | ||
| Compile an AST into a Python code object. | ||
eb8680 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| module: The AST to compile (typically produced by parse()). | ||
| filename: The filename recorded in the resulting code object (CodeType.co_filename), used in tracebacks and by inspect.getsource(). | ||
|
|
||
| Returns the compiled code object. | ||
| """ | ||
| raise NotImplementedError( | ||
| "An eval provider must be installed in order to compile code." | ||
| ) | ||
|
|
||
|
|
||
| @defop | ||
| def exec( | ||
kiranandcode marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| bytecode: CodeType, | ||
eb8680 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| env: dict[str, Any], | ||
eb8680 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) -> None: | ||
| """ | ||
| Execute a compiled code object. | ||
|
|
||
| bytecode: A code object to execute (typically produced by compile()). | ||
| env: The namespace mapping used during execution. | ||
| """ | ||
| raise NotImplementedError( | ||
| "An eval provider must be installed in order to execute code." | ||
| ) | ||
|
|
||
|
|
||
| class UnsafeEvalProvider(ObjectInterpretation): | ||
| """UNSAFE provider that handles parse, comple and exec operations | ||
| by shelling out to python *without* any further checks. Only use for testing.""" | ||
|
|
||
| @implements(parse) | ||
| def parse(self, source: str, filename: str) -> ast.Module: | ||
| # Cache source under `filename` so inspect.getsource() can retrieve it later. | ||
| # inspect uses f.__code__.co_filename -> linecache.getlines(filename) | ||
| linecache.cache[filename] = ( | ||
| len(source), | ||
| None, | ||
| source.splitlines(True), | ||
| filename, | ||
| ) | ||
|
|
||
| return ast.parse(source, filename=filename, mode="exec") | ||
|
|
||
| @implements(compile) | ||
| def compile(self, module: ast.AST, filename: str) -> CodeType: | ||
| return builtins.compile(typing.cast(typing.Any, module), filename, "exec") | ||
|
|
||
| @implements(exec) | ||
| def exec( | ||
| self, | ||
| bytecode: CodeType, | ||
| env: dict[str, Any], | ||
| ) -> None: | ||
| # Ensure builtins exist in the execution environment. | ||
| env.setdefault("__builtins__", __builtins__) | ||
|
|
||
| # Execute module-style so top-level defs land in `env`. | ||
| builtins.exec(bytecode, env, env) | ||
kiranandcode marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.