Add JSON program generation, validation, and evaluation in core module #20
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.
This PR adds support for generation, validation, and evaluation of simple programs targeting a specified API. Programs consist of a sequence of calls to functions of the specified API with arguments that are a combination of JSON values and results from preceding program steps. Programs are are represented as JSON using the following schema:
For example, given a music service API with functions
getRecentlyPlayed
,filterTracks
, andcreatePlaylist
, the user request "get my favorite 50 tracks from last year and make the non-classical ones into a playlist" might be represented as the followingProgram
instance:The
createProgramTranslator
function introduced in this PR creates an object that can translate natural language requests into such programs. Thetranslate
method of the object combines theProgram
schema, a specified API schema, and a user request into a prompt that directs the LLM to generate a JSON program. The resulting program can be safely evaluated using theevaluateJsonProgram
function, which implements a simple interpreter. Calls to API functions in the program are passed to anonCall
callback function for validation and dispatch. Thus, unlike JavaScript'seval
, access to external functionality and resources is entirely controlled by the host application.