Skip to content

feat: [Orchestration] Enable local prompt templates #423

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 23 commits into from
Apr 30, 2025

Conversation

Jonas-Isr
Copy link
Member

@Jonas-Isr Jonas-Isr commented Apr 24, 2025

Context

AI/ai-sdk-java-backlog#215

This PR enables users to validate and use prompt templates from their local environment, without the use of prompt registry. For this, the user can provide a String containing a YAML representation of the prompt template and we will deserialise this into our (high level) OrchestrationTemplate class, which then can be used to configure an Orchestration call. If the provided prompt template does not match the prompt-registry spec, an exception is thrown.

Note 1: We have to assume that the prompt-registry spec keeps exactly equal to the orchestration spec for the relevant fields. If the two diverge, we can no longer deserialise the prompt template (which follows prompt-registry spec) into our Java classes (which follow mostly the orchestration prompt). Since we deserialise into high-level classes, we might have some wiggle room, but that would probably become quite messy.

Note 2: The whole process on our side (i.e. validation and deserialisation) ignores the additionalFields of the prompt templates. This is aligned with PO and JS SDK. (The reason is that we cannot know what is inside these fields, and it usually is information we cannot handle in our template classes.)

Feature scope:

  • Local yaml files can be used to create templates without using prompt registry
  • the yaml gets validated

Definition of Done

Comment on lines +137 to +149
final Object obj;
try {
final ObjectMapper yamlReader = new ObjectMapper(new YAMLFactory());
obj = yamlReader.readValue(inputYaml, Object.class);
} catch (JsonProcessingException ex) {
throw new IOException("Failed to parse the YAML input: " + ex.getMessage(), ex);
}
try {
final ObjectMapper jsonWriter = new ObjectMapper();
return fromJson(jsonWriter.writeValueAsString(obj));
} catch (JsonProcessingException ex) {
throw new IOException("Failed to deserialize the input: " + ex.getMessage(), ex);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if these are the correct/best Exception types. I am open to suggestions :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using two objectmappers, I was about to pitch something like...

  private static class TemplateYaml {
    @JsonProperty("spec")
    private OrchestrationTemplate spec;
  }

But that would've required additional customization to propagate the modules/rules along for Yaml Factory.

@Jonas-Isr Jonas-Isr changed the title feat: [Orchesrtation] Enable local prompt templates feat: [Orchestration] Enable local prompt templates Apr 24, 2025
Comment on lines +120 to +125
private OrchestrationTemplate fromJson(@Nonnull final String inputString) throws IOException {
final ObjectMapper objectMapper =
OrchestrationJacksonConfiguration.getOrchestrationObjectMapper();
final JsonNode rootNode = objectMapper.readTree(inputString);
return objectMapper.treeToValue(rootNode.get("spec"), OrchestrationTemplate.class);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method could principally be made public as an additional feature. I left it private because it is not part of the ticket, not tested on its own, and not aligned with JS SDK (which only has the yaml feature afaik).

@Jonas-Isr Jonas-Isr self-assigned this Apr 24, 2025
@Jonas-Isr Jonas-Isr added the please-review Request to review a pull-request label Apr 24, 2025
* @since 1.7.0
*/
@Nullable
public OrchestrationTemplate fromYaml(@Nonnull final String inputYaml) throws IOException {
Copy link
Member Author

@Jonas-Isr Jonas-Isr Apr 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Question to reviewer)
Should we maybe annotate this with @Beta?

Pro: We might not be able to continue to keep this method/feature alive without additional work if the specs of prompt-registry and orchestration were to diverge at some point (see "Note 1" in the PR description).

Con: Additional beta annotation for convenience code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as discussed, since this API has no alternative to users, I would keep it non-Beta

@Jonas-Isr Jonas-Isr merged commit d5ecdc9 into main Apr 30, 2025
7 checks passed
@Jonas-Isr Jonas-Isr deleted the orch-local-prompt-templates branch April 30, 2025 11:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
please-review Request to review a pull-request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants