Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
vnkn authored Sep 11, 2024
1 parent 07d25b1 commit 44701d8
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions nomadic/experiment/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
Expand Down

0 comments on commit 44701d8

Please sign in to comment.