Get response from the LLM for an IMO problem with extended timeout for complex reasoning
(problem: str, model: str, extra_body: dict = None, timeout: int = 600)
| 477 | return analysis |
| 478 | |
| 479 | def get_llm_response(problem: str, model: str, extra_body: dict = None, timeout: int = 600) -> Dict[str, any]: |
| 480 | """ |
| 481 | Get response from the LLM for an IMO problem with extended timeout for complex reasoning |
| 482 | """ |
| 483 | try: |
| 484 | kwargs = {} |
| 485 | if extra_body: |
| 486 | kwargs["extra_body"] = extra_body |
| 487 | |
| 488 | response = client.with_options(timeout=timeout).chat.completions.create( |
| 489 | model=model, |
| 490 | messages=[ |
| 491 | {"role": "system", "content": SYSTEM_PROMPT}, |
| 492 | {"role": "user", "content": problem} |
| 493 | ], |
| 494 | max_tokens=64000, # Extended token limit for complex IMO proofs (increased from 30000) |
| 495 | **kwargs |
| 496 | ) |
| 497 | |
| 498 | solution_text = response.choices[0].message.content.strip() |
| 499 | reasoning_tokens = getattr(response.usage, 'reasoning_tokens', 0) |
| 500 | total_tokens = response.usage.total_tokens if hasattr(response.usage, 'total_tokens') else 0 |
| 501 | |
| 502 | return { |
| 503 | "solution": solution_text, |
| 504 | "reasoning_tokens": reasoning_tokens, |
| 505 | "total_tokens": total_tokens, |
| 506 | "success": True |
| 507 | } |
| 508 | |
| 509 | except Exception as e: |
| 510 | logger.error(f"Error getting LLM response: {e}") |
| 511 | return { |
| 512 | "solution": f"Error generating solution: {str(e)}", |
| 513 | "reasoning_tokens": 0, |
| 514 | "total_tokens": 0, |
| 515 | "success": False |
| 516 | } |
| 517 | |
| 518 | def evaluate_solution(problem_data: Dict, solution: str, model: str = "google/gemini-2.5-flash-lite") -> Dict[str, any]: |
| 519 | """ |