Skip to content

Commit 59c7ac7

Browse files
committed
chore: break up long lines, add spaces where necessary
1 parent aee6aa7 commit 59c7ac7

1 file changed

Lines changed: 72 additions & 34 deletions

File tree

  • packages/optimization/src/ldai_optimization

packages/optimization/src/ldai_optimization/client.py

Lines changed: 72 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -625,16 +625,19 @@ async def _evaluate_acceptance_judge(
625625

626626
# Build instructions for the judge
627627
instructions = (
628-
f"You are a judge that evaluates the response to the user's question.\n\n"
629-
f"Here is the statement that you should evaluate the response against: '{optimization_judge.acceptance_statement}'\n"
628+
"You are a judge that evaluates the response to the user's question.\n\n"
629+
"Here is the statement that you should evaluate the response against: "
630+
f"'{optimization_judge.acceptance_statement}'\n"
630631
f"Here is the history of all messages between the user and the assistant: {message_history_text}\n"
631-
f"You should score the response based on how well it meets the acceptance statement using a score between 0.0 and 1.0.\n"
632-
f"A score of 0.0 means it does not match at all, while a score of 1.0 means it matches perfectly.\n"
633-
f"A score of 0.3-0.7 means it matches partially, while a score of 0.7-1.0 means it matches well.\n"
634-
f"A score of 0.0-0.3 means that it does not match well at all. You can return any value between 0.0 and 1.0.\n"
635-
f"You should also provide a rationale for your score.\n"
636-
f"You should call the structured output tool to format your response.\n\n"
637-
f'Example: {{"score": 0.8, "rationale": "The response matches the acceptance statement well."}}'
632+
"You should score the response based on how well it meets the acceptance statement "
633+
"using a score between 0.0 and 1.0.\n"
634+
"A score of 0.0 means it does not match at all, while a score of 1.0 means it matches perfectly.\n"
635+
"A score of 0.3-0.7 means it matches partially, while a score of 0.7-1.0 means it matches well.\n"
636+
"A score of 0.0-0.3 means that it does not match well at all. "
637+
"You can return any value between 0.0 and 1.0.\n"
638+
"You should also provide a rationale for your score.\n"
639+
"You should call the structured output tool to format your response.\n\n"
640+
'Example: {"score": 0.8, "rationale": "The response matches the acceptance statement well."}'
638641
)
639642

640643
if resolved_variables:
@@ -643,9 +646,13 @@ async def _evaluate_acceptance_judge(
643646
if resolved_agent_tools:
644647
tool_names = [t.name for t in resolved_agent_tools]
645648
instructions += (
646-
f"\n\nThe following tools were available to the agent and may be called by you to verify the response: {json.dumps(tool_names)}."
647-
"\nIf verifying the response requires looking up external information, call the appropriate tool before scoring."
648-
"You should only call the tools for the most recent response, and should only call the tools if necessary. Assume that previous feedback will have addressed bad tool call results from prior iterations."
649+
"\n\nThe following tools were available to the agent and "
650+
f"may be called by you to verify the response: {json.dumps(tool_names)}."
651+
"\nIf verifying the response requires looking up external information, "
652+
"call the appropriate tool before scoring. "
653+
"You should only call the tools for the most recent response, "
654+
"and should only call the tools if necessary. "
655+
"Assume that previous feedback will have addressed bad tool call results from prior iterations."
649656
)
650657

651658
# Prepend agent tools so the judge can invoke them for verification if needed
@@ -790,10 +797,16 @@ def _new_variation_prompt_preamble(self) -> str:
790797
"You are an assistant that helps improve agent configurations through iterative optimization.",
791798
"",
792799
"Your task is to generate improved agent instructions and parameters based on the feedback provided.",
793-
"The feedback you provide should guide the LLM To improve the agent instructions for all possible use cases, not one concrete case.",
794-
"For example, if the feedback is that the agent is not returning the correct records, you should improve the agent instructions to return the correct records for all possible use cases. Not just the one concrete case that was provided in the feedback.",
795-
"When changing the instructions, keep the original intent in mind when it comes to things like the use of variables and placeholders.",
796-
"If the original instructions were to use a placeholder like {{id}}, you should keep the placeholder in the new instructions, not replace it with the actual value. This is the case for all parameterized values (all parameters should appear in each new variation).",
800+
"The feedback you provide should guide the LLM to improve the agent instructions "
801+
"for all possible use cases, not one concrete case.",
802+
"For example, if the feedback is that the agent is not returning the correct records, "
803+
"you should improve the agent instructions to return the correct records for all possible use cases. "
804+
"Not just the one concrete case that was provided in the feedback.",
805+
"When changing the instructions, keep the original intent in mind "
806+
"when it comes to things like the use of variables and placeholders.",
807+
"If the original instructions were to use a placeholder like {{id}}, "
808+
"you should keep the placeholder in the new instructions, not replace it with the actual value. "
809+
"This is the case for all parameterized values (all parameters should appear in each new variation).",
797810
"Pay particular attention to the instructions regarding tools and the rules for variables.",
798811
]
799812
)
@@ -899,7 +912,10 @@ def _new_variation_prompt_feedback(self, history: List[OptimizationContext]) ->
899912
if optimization_judge.threshold is not None:
900913
passed = score >= optimization_judge.threshold
901914
status = "PASSED" if passed else "FAILED"
902-
feedback_line = f"- {judge_key}: Score {score:.3f} (threshold: {optimization_judge.threshold}) - {status}"
915+
feedback_line = (
916+
f"- {judge_key}: Score {score:.3f}"
917+
f" (threshold: {optimization_judge.threshold}) - {status}"
918+
)
903919
else:
904920
passed = score >= 1.0
905921
status = "PASSED" if passed else "FAILED"
@@ -921,9 +937,12 @@ def _new_variation_prompt_improvement_instructions(
921937
"""
922938
model_instructions = "\n".join(
923939
[
924-
"You may also choose to change the model if you believe that the current model is not performing well or a different model would be better suited for the task. "
925-
f"Here are the models you may choose from: {self._options.model_choices}. You must always return a model property, even if it's the same as the current model.",
926-
"When suggesting a new model, you should provide a rationale for why you believe the new model would be better suited for the task.",
940+
"You may also choose to change the model if you believe that the current model is "
941+
"not performing well or a different model would be better suited for the task. "
942+
f"Here are the models you may choose from: {self._options.model_choices}. "
943+
"You must always return a model property, even if it's the same as the current model.",
944+
"When suggesting a new model, you should provide a rationale for why you believe "
945+
"the new model would be better suited for the task.",
927946
]
928947
)
929948

@@ -938,23 +957,35 @@ def _new_variation_prompt_improvement_instructions(
938957
"## Prompt Variables:",
939958
"These variables are substituted into the instructions at call time using {{variable_name}} syntax.",
940959
"Rules:",
941-
"- If the {{variable_name}} placeholder is not present in the current instructions, you should include it where logically appropriate.",
942-
"Here are the original instructions so that you can see how the placeholders are used and which are available:",
960+
"- If the {{variable_name}} placeholder is not present in the current instructions, "
961+
"you should include it where logically appropriate.",
962+
"Here are the original instructions so that you can see how the "
963+
"placeholders are used and which are available:",
943964
"\nSTART:" "\n" + self._initial_instructions + "\n",
944965
"\nEND OF ORIGINAL INSTRUCTIONS\n",
945-
f"The following prompt variables are available and are the only variables that should be used: {placeholder_list}"
946-
"Here is an example of a good response if an {{id}} placeholder is available: 'Select records matching id {{id}}'",
947-
"Here is an example of a bad response if an {{id}} placeholder is available: 'Select records matching id 1232'",
948-
"Here is an example of a good response if a {{resource_id}} and {{resource_type}} placeholder are available: 'Select records matching id {{resource_id}} and type {{resource_type}}'",
949-
"Here is an example of a bad response if a {{resource_id}} and {{resource_type}} placeholder are available: 'Select records matching id 1232 and type {{resource_type}}'",
950-
"Here is another example of a bad response if a {{resource_id}} and {{resource_type}} placeholder are available: 'Select records matching id {{resource_id}} and type resource-123'",
966+
f"The following prompt variables are available and are the only "
967+
f"variables that should be used: {placeholder_list}",
968+
"Here is an example of a good response if an {{id}} placeholder is available: "
969+
"'Select records matching id {{id}}'",
970+
"Here is an example of a bad response if an {{id}} placeholder is available: "
971+
"'Select records matching id 1232'",
972+
"Here is an example of a good response if a {{resource_id}} and {{resource_type}} "
973+
"placeholder are available: "
974+
"'Select records matching id {{resource_id}} and type {{resource_type}}'",
975+
"Here is an example of a bad response if a {{resource_id}} and {{resource_type}} "
976+
"placeholder are available: "
977+
"'Select records matching id 1232 and type {{resource_type}}'",
978+
"Here is another example of a bad response if a {{resource_id}} and {{resource_type}} "
979+
"placeholder are available: "
980+
"'Select records matching id {{resource_id}} and type resource-123'",
951981
]
952982
)
953983

954984
tool_instructions = "\n".join(
955985
[
956986
"## Tool Format:",
957-
'If the current configuration includes tools, you MUST return them unchanged in current_parameters["tools"].',
987+
'If the current configuration includes tools, you MUST return them '
988+
'unchanged in current_parameters["tools"].',
958989
"Do NOT include internal framework tools such as the evaluation tool or structured output tool.",
959990
"Each tool must follow this exact format:",
960991
"{",
@@ -995,7 +1026,8 @@ def _new_variation_prompt_improvement_instructions(
9951026

9961027
parameters_instructions = "\n".join(
9971028
[
998-
"Return these values in a JSON object with the following keys: current_instructions, current_parameters, and model.",
1029+
"Return these values in a JSON object with the following keys: "
1030+
"current_instructions, current_parameters, and model.",
9991031
"Example:",
10001032
"{",
10011033
' "current_instructions": "...',
@@ -1004,8 +1036,11 @@ def _new_variation_prompt_improvement_instructions(
10041036
" },",
10051037
' "model": "gpt-4o"',
10061038
"}",
1007-
"Parameters should only be things that are directly parseable by an LLM call, for example, temperature, max_tokens, etc."
1008-
"Do not include any other parameters that are not directly parseable by an LLM call. If you want to provide instruction for tone or other attributes, provide them directly in the instructions.",
1039+
"Parameters should only be things that are directly parseable by an LLM call, "
1040+
"for example, temperature, max_tokens, etc.",
1041+
"Do not include any other parameters that are not directly parseable by an LLM call. "
1042+
"If you want to provide instruction for tone or other attributes, "
1043+
"provide them directly in the instructions.",
10091044
]
10101045
)
10111046

@@ -1025,8 +1060,11 @@ def _new_variation_prompt_improvement_instructions(
10251060
"Return the improved configuration in a structured format that can be parsed to update:",
10261061
"1. The agent instructions (current_instructions)",
10271062
"2. The agent parameters (current_parameters)",
1028-
"3. The model (model) - you must always return a model, even if it's the same as the current model.",
1029-
"4. You should return the tools the user has defined, as-is, on the new parameters. Do not modify them, but make sure you do not include internal tools like the evaluation tool or structured output tool.",
1063+
"3. The model (model) - you must always return a model, "
1064+
"even if it's the same as the current model.",
1065+
"4. You should return the tools the user has defined, as-is, on the new parameters. "
1066+
"Do not modify them, but make sure you do not include internal tools like "
1067+
"the evaluation tool or structured output tool.",
10301068
parameters_instructions,
10311069
]
10321070
)

0 commit comments

Comments
 (0)