ReflectionSolver.predict:v0
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
import weave
from utils import Problem
import logging
from pydantic.main import BaseModel
from pydantic.fields import Field
class Solution(BaseModel):
core_question: str = Field(..., description="Core question of the problem")
problem_solving_info: str = Field(..., description="Problem-solving information related to the core question")
plan: str = Field(..., description="Step by step plan to solve the problem")
pseudocode: str = Field(..., description="Pseudocode to solve the problem")
source_code: str = Field(..., description="Valid Python3 sourcecode to solve the problem.")
reflect_prompt_template = "\nYou just failed to solve the problem.\n\nHere is problem:\n<problem>\n{problem_description}\n</problem>\n\nHere is the sample input to the problem:\n<input>\n{sample_input}\n</input>\n\nand here is the expected output:\n<output>\n{sample_output}\n</output>\n\nHere is the answer you provided:\n<answer>\n{answer}\n</answer>\n\nPlease try again to solve the problem.\n"
@weave.op
async def reflection_solver(
problem: Problem,
llm_model: str,
system_prompt: str,
prompt_template: str,
# temperature: float = 0.7,
timeout: int = 10
) -> str:
logging.info(f"Solving problem: {problem.problem_name}")
# call model one first time to get the code
logging.info("Calling model to solve the problem")
if "o1" in llm_model: