Skip to content

Commit 380d924

Browse files
authored
Merge pull request #244 from codelion/fix-prompt-optimizer-example
Fix prompt optimizer example
2 parents 7b413bf + 2613c8d commit 380d924

File tree

2 files changed

+11
-22
lines changed

2 files changed

+11
-22
lines changed

examples/llm_prompt_optimization/evaluate_prompts.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ def evaluate_ifeval(client, prompt_template, num_samples, model):
8282

8383
try:
8484
formatted_prompt = prompt_template.format(instruction=instruction)
85-
except KeyError:
86-
# Handle prompts with different placeholder names
87-
formatted_prompt = prompt_template.replace("{instruction}", instruction)
85+
except KeyError as e:
86+
print(f"Error: Prompt template missing placeholder: {e}")
87+
return 0.0, 0, total, total
8888

8989
# Call LLM with retries
9090
output_text = None
@@ -163,8 +163,9 @@ def evaluate_hover(client, prompt_template, num_samples, model):
163163

164164
try:
165165
formatted_prompt = prompt_template.format(claim=claim)
166-
except KeyError:
167-
formatted_prompt = prompt_template.replace("{claim}", claim)
166+
except KeyError as e:
167+
print(f"Error: Prompt template missing placeholder: {e}")
168+
return 0.0, 0, total, total
168169

169170
# Call LLM with retries
170171
output_text = None
@@ -258,10 +259,9 @@ def evaluate_hotpotqa(client, prompt_template, num_samples, model):
258259
formatted_prompt = prompt_template.format(
259260
context=context_str.strip(), question=question
260261
)
261-
except KeyError:
262-
# Try alternative formatting
263-
formatted_prompt = prompt_template.replace("{context}", context_str.strip())
264-
formatted_prompt = formatted_prompt.replace("{question}", question)
262+
except KeyError as e:
263+
print(f"Error: Prompt template missing placeholders: {e}")
264+
return 0.0, 0, total, total
265265

266266
# Call LLM with retries
267267
output_text = None
Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,2 @@
1-
You are an expert prompt engineer specializing in creating effective prompts for language models.
2-
3-
Your task is to evolve and improve prompts to maximize their performance on specific tasks. When rewriting prompts:
4-
5-
1. **Maintain the exact placeholder format**: Always use the same placeholder name as in the original prompt (e.g., {instruction}, {claim}, {context}, {question})
6-
2. **Keep it simple**: Avoid overly complex or verbose instructions unless necessary
7-
3. **Be specific**: Provide clear, actionable guidance to the model
8-
4. **Test-oriented**: Focus on what will improve accuracy on the given evaluation metrics
9-
5. **Format-aware**: Ensure the prompt works well with the expected input/output format
10-
11-
**CRITICAL**: Your rewritten prompt must use EXACTLY the same placeholder names as the original. Do not change {instruction} to {input_text} or any other variation.
12-
13-
Generate only the improved prompt text, nothing else.
1+
You are an expert prompt evaluator.
2+
Your job is to analyze the provided prompts and evaluate them systematically.

0 commit comments

Comments
 (0)