mgbam commited on
Commit
d686fd7
·
verified ·
1 Parent(s): 96ef077

Update core/generation_engine.py

Browse files
Files changed (1) hide show
  1. core/generation_engine.py +42 -0
core/generation_engine.py CHANGED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # algoforge_prime/core/generation_engine.py
2
+ from .llm_clients import call_huggingface_api, call_gemini_api, LLMResponse
3
+ from ..prompts.system_prompts import get_system_prompt
4
+ from ..prompts.prompt_templates import format_genesis_user_prompt
5
+
6
+ def generate_initial_solutions(
7
+ problem_description,
8
+ initial_hints,
9
+ problem_type,
10
+ num_solutions_to_generate,
11
+ llm_client_config # Dict: {"type": ..., "model_id": ..., "temp": ..., "max_tokens": ...}
12
+ ):
13
+ solutions = []
14
+ system_p_genesis = get_system_prompt("genesis", problem_type)
15
+
16
+ for i in range(num_solutions_to_generate):
17
+ user_p_genesis = format_genesis_user_prompt(
18
+ problem_description, initial_hints, i + 1, num_solutions_to_generate
19
+ )
20
+
21
+ llm_response_obj = None
22
+ if llm_client_config["type"] == "hf":
23
+ llm_response_obj = call_huggingface_api(
24
+ user_p_genesis, llm_client_config["model_id"],
25
+ temperature=llm_client_config["temp"], max_new_tokens=llm_client_config["max_tokens"],
26
+ system_prompt_text=system_p_genesis
27
+ )
28
+ elif llm_client_config["type"] == "google_gemini":
29
+ llm_response_obj = call_gemini_api(
30
+ user_p_genesis, llm_client_config["model_id"],
31
+ temperature=llm_client_config["temp"], max_new_tokens=llm_client_config["max_tokens"],
32
+ system_prompt_text=system_p_genesis
33
+ )
34
+
35
+ if llm_response_obj and llm_response_obj.success:
36
+ solutions.append(llm_response_obj.text)
37
+ elif llm_response_obj: # Error occurred
38
+ solutions.append(f"ERROR (Genesis Attempt {i+1}): {llm_response_obj.error}")
39
+ else: # Should not happen if LLMResponse always returned
40
+ solutions.append(f"ERROR (Genesis Attempt {i+1}): Unknown error during LLM call.")
41
+
42
+ return solutions