From 7c0c471e5513ec915c50d8d430d53871f2bff511 Mon Sep 17 00:00:00 2001 From: cybermaggedon Date: Sun, 27 Oct 2024 15:04:53 +0000 Subject: [PATCH] Feature/prompt terms (#128) * Add prompt terms * Remove dupe template code --- templates/components/prompt-template.jsonnet | 76 +++++++++----------- 1 file changed, 34 insertions(+), 42 deletions(-) diff --git a/templates/components/prompt-template.jsonnet b/templates/components/prompt-template.jsonnet index 25982eb3..ac820df6 100644 --- a/templates/components/prompt-template.jsonnet +++ b/templates/components/prompt-template.jsonnet @@ -8,6 +8,36 @@ local default_prompts = import "prompts/default-prompts.jsonnet"; prompts:: default_prompts, + local prompt_template_args = [ "--prompt" ] + [ + p.key + "=" + p.value.prompt, + for p in std.objectKeysValuesAll($.prompts.templates) + ], + + local prompt_response_type_args = [ "--prompt-response-type" ] + [ + p.key + "=" + p.value["response-type"], + for p in std.objectKeysValuesAll($.prompts.templates) + if std.objectHas(p.value, "response-type") + ], + + local prompt_schema_args = [ "--prompt-schema" ] + [ + ( + p.key + "=" + + std.manifestJsonMinified(p.value["schema"]) + ) + for p in std.objectKeysValuesAll($.prompts.templates) + if std.objectHas(p.value, "schema") + ], + + local prompt_term_args = [ "--prompt-term" ] + [ + p.key + "=" + t.key + ":" + t.value + for p in std.objectKeysValuesAll($.prompts.templates) + if std.objectHas(p.value, "terms") + for t in std.objectKeysValuesAll(p.value.terms) + ], + + local prompt_args = prompt_template_args + prompt_response_type_args + + prompt_schema_args + prompt_term_args, + "prompt" +: { create:: function(engine) @@ -28,27 +58,8 @@ local default_prompts = import "prompts/default-prompts.jsonnet"; "--system-prompt", $["prompts"]["system-template"], - "--prompt", - - ] + [ - p.key + "=" + p.value.prompt, - for p in std.objectKeysValuesAll($.prompts.templates) - ] + [ - "--prompt-response-type" - ] + [ - p.key + "=" + p.value["response-type"], - for p in std.objectKeysValuesAll($.prompts.templates) - if std.objectHas(p.value, "response-type") - ] + [ - "--prompt-schema" - ] + [ - ( - p.key + "=" + - std.manifestJsonMinified(p.value["schema"]) - ) - for p in std.objectKeysValuesAll($.prompts.templates) - if std.objectHas(p.value, "schema") - ]) + ] + prompt_args + ) .with_limits("0.5", "128M") .with_reservations("0.1", "128M"); @@ -90,27 +101,8 @@ local default_prompts = import "prompts/default-prompts.jsonnet"; "--system-prompt", $["prompts"]["system-template"], - "--prompt", - - ] + [ - p.key + "=" + p.value.prompt, - for p in std.objectKeysValuesAll($.prompts.templates) - ] + [ - "--prompt-response-type" - ] + [ - p.key + "=" + p.value["response-type"], - for p in std.objectKeysValuesAll($.prompts.templates) - if std.objectHas(p.value, "response-type") - ] + [ - "--prompt-schema" - ] + [ - ( - p.key + "=" + - std.manifestJsonMinified(p.value["schema"]) - ) - for p in std.objectKeysValuesAll($.prompts.templates) - if std.objectHas(p.value, "schema") - ]) + ] + prompt_args + ) .with_limits("0.5", "128M") .with_reservations("0.1", "128M");