File size: 1,900 Bytes
d686fd7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# algoforge_prime/core/generation_engine.py
from .llm_clients import call_huggingface_api, call_gemini_api, LLMResponse
from ..prompts.system_prompts import get_system_prompt
from ..prompts.prompt_templates import format_genesis_user_prompt

def generate_initial_solutions(
    problem_description,
    initial_hints,
    problem_type,
    num_solutions_to_generate,
    llm_client_config # Dict: {"type": ..., "model_id": ..., "temp": ..., "max_tokens": ...}
):
    solutions = []
    system_p_genesis = get_system_prompt("genesis", problem_type)

    for i in range(num_solutions_to_generate):
        user_p_genesis = format_genesis_user_prompt(
            problem_description, initial_hints, i + 1, num_solutions_to_generate
        )
        
        llm_response_obj = None
        if llm_client_config["type"] == "hf":
            llm_response_obj = call_huggingface_api(
                user_p_genesis, llm_client_config["model_id"],
                temperature=llm_client_config["temp"], max_new_tokens=llm_client_config["max_tokens"],
                system_prompt_text=system_p_genesis
            )
        elif llm_client_config["type"] == "google_gemini":
            llm_response_obj = call_gemini_api(
                user_p_genesis, llm_client_config["model_id"],
                temperature=llm_client_config["temp"], max_new_tokens=llm_client_config["max_tokens"],
                system_prompt_text=system_p_genesis
            )
        
        if llm_response_obj and llm_response_obj.success:
            solutions.append(llm_response_obj.text)
        elif llm_response_obj: # Error occurred
            solutions.append(f"ERROR (Genesis Attempt {i+1}): {llm_response_obj.error}")
        else: # Should not happen if LLMResponse always returned
            solutions.append(f"ERROR (Genesis Attempt {i+1}): Unknown error during LLM call.")
            
    return solutions