From 44701d8968478a4938a531ae0246fdaca51b5f57 Mon Sep 17 00:00:00 2001 From: VK Date: Wed, 11 Sep 2024 00:11:07 -0700 Subject: [PATCH] updated --- nomadic/experiment/base.py | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/nomadic/experiment/base.py b/nomadic/experiment/base.py index e8ce940..e6f9c64 100644 --- a/nomadic/experiment/base.py +++ b/nomadic/experiment/base.py @@ -386,17 +386,34 @@ def _default_param_function(param_values: Dict[str, Any]) -> RunResult: return self.experiment_result - def _construct_prompt(self, prompt_variant: str, example: Dict[str, str]) -> str: + def _construct_prompt( + self, + prompt_variant: str, + example: Dict[str, str] = None, + context: str = "", + instruction: str = "", + query: str = "", + question: str = "", + response: str = "", + answer: str = "" + ) -> str: + # Determine values for query/question (interchangeable) and response/answer (irreplaceable) + query_value = example.get("query", query) or query or question + response_value = example.get("response", response) or response or answer + + # Prepare replacements dictionary replacements = { - "[CONTEXT]": example["context"], - "[QUERY]": example["query"], - "[INSTRUCTION]": example.get("instruction", ""), - "[RESPONSE]": example.get("response", ""), + "[CONTEXT]": example.get("context", context) or context, + "[QUERY]": query_value, + "[INSTRUCTION]": example.get("instruction", instruction) or instruction, + "[RESPONSE]": response_value, } + # Replace placeholders in the prompt variant for placeholder, value in replacements.items(): prompt_variant = prompt_variant.replace(placeholder, value) + # Find and remove unused placeholders unused_placeholders = [ key for key in replacements.keys() if key in prompt_variant ]