Repository navigation
Conversation
Dotprompt.render(String, Map) and PromptFunction.render(Map) put template variables, context and history in one map: every key became a template variable, "context" set @ data and "messages" set history. Callers passing user-controlled input as that map let users inject a system turn, media URLs or @ data. JS, Go and Python keep these in separate DataArgument fields. Add render overloads taking a DataArgument (with a builder) on Dotprompt, PromptFunction and PromptRefFunction. Template variables come only from input, @ data only from context and history only from messages, so input keys named "context" or "messages" are plain variables. The Map overloads are deprecated and convert to a DataArgument with their old semantics, so there is a single render path. The spec suite, smoke tests and docs now use the new overloads.
The Java library hasn't been published yet, so instead of deprecating the Map-based render overloads (which read "messages" and "context" from the input map as reserved keys), remove them along with their conversion helpers. DataArgument is now the only way to pass render data: template variables come from input, @ data from context and history from messages. Tests and docs use the DataArgument overloads only.
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What's new
rendernow takes aDataArgument, keeping template input,@context and conversation history in separate fields (as JS, Go and Python already do):data.input(),@data only fromdata.context(), history only fromdata.messages(). Input keys namedmessages/contextare plain template variables.DataArgument.builder()added (the docs already described it).SpecTestrenders through the new path; smoke tests (Java + Kotlin) and the Java docs use it.Why
render(String, Map<String, Object>)reads template variables,contextandmessagesfrom the same map. If an app passes user-controlled data as that map, the user can add amessageskey and inject asystemturn or an arbitrary media URL into the output (no markers involved, so the marker nonce in #644 doesn't cover it), or acontextkey to set@data. Raised in review of #644.API changes (unpublished library)
The
Map-based overloads are removed:Dotprompt.render(String, Map[, Map])andPromptFunction/PromptRefFunction.render(Map[, Map]). The Java library hasn't been published yet (the 0.1.0 publish job failed; nothing on Maven Central), so they're removed rather than deprecated. Migrate by wrapping template variables inDataArgument.builder().input(map)and passing history / context through their own fields.Not in this PR
Dotprompt's privatetoMessageswithParser(follow-up after this and fix(dotprompt-java): add per-render nonce to template markers #644 land).toMessages' signature; trivial to resolve (toMessages(rendered, nonce, history)) whichever lands second.