Spaces:
Sleeping
Sleeping
File size: 2,721 Bytes
89da890 f3c444a 2d643fe 89da890 2d643fe 89da890 2d643fe 89da890 2d643fe 89da890 2d643fe 89da890 2d643fe 89da890 2d643fe |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# algoforge_prime/core/evolution_engine.py
from core.llm_clients import call_huggingface_api, call_gemini_api, LLMResponse # Absolute
from prompts.system_prompts import get_system_prompt # Absolute
# from ..prompts.prompt_templates import format_evolution_user_prompt # If you create one
def evolve_solution(
original_solution_text: str,
comprehensive_critique_text: str, # This includes LLM critique + test summary
original_combined_score: int,
problem_description: str,
problem_type: str,
llm_client_config: dict # {"type": ..., "model_id": ..., "temp": ..., "max_tokens": ...}
) -> str: # Returns evolved solution text or an error string
"""
Attempts to evolve a solution based on its critique and score.
"""
system_p_evolve = get_system_prompt("evolution_general") # problem_type can be used for specialization
user_p_evolve = (
f"Original Problem Context: \"{problem_description}\"\n\n"
f"The solution to be evolved achieved a score of {original_combined_score}/10.\n"
f"Here is the solution text:\n```python\n{original_solution_text}\n```\n\n"
f"Here is the comprehensive evaluation and critique it received (including any automated test feedback):\n'''\n{comprehensive_critique_text}\n'''\n\n"
f"Your Task: Based on the above, evolve the provided solution to make it demonstrably superior. "
f"Address any flaws, incompleteness, or inefficiencies mentioned in the critique or highlighted by test failures. "
f"If the solution was good, make it even better (e.g., more robust, more efficient, clearer). "
f"Clearly explain the key improvements you've made as an integral part of your evolved response (e.g., in comments or a concluding summary)."
)
llm_response_obj = None # type: LLMResponse
if llm_client_config["type"] == "hf":
llm_response_obj = call_huggingface_api(
user_p_evolve, llm_client_config["model_id"],
temperature=llm_client_config["temp"], max_new_tokens=llm_client_config["max_tokens"],
system_prompt_text=system_p_evolve
)
elif llm_client_config["type"] == "google_gemini":
llm_response_obj = call_gemini_api(
user_p_evolve, llm_client_config["model_id"],
temperature=llm_client_config["temp"], max_new_tokens=llm_client_config["max_tokens"],
system_prompt_text=system_p_evolve
)
else:
return f"ERROR (Evolution): Unknown LLM client type '{llm_client_config['type']}'"
if llm_response_obj.success:
return llm_response_obj.text
else:
return f"ERROR (Evolution with {llm_response_obj.model_id_used}): {llm_response_obj.error}" |