Enhanced mock OpenAI client for MARS testing
| 25 | |
| 26 | |
| 27 | class MockOpenAIClient: |
| 28 | """Enhanced mock OpenAI client for MARS testing""" |
| 29 | |
| 30 | def __init__(self, response_delay=0.1, reasoning_tokens=1000): |
| 31 | self.response_delay = response_delay |
| 32 | self.reasoning_tokens = reasoning_tokens |
| 33 | self.call_count = 0 |
| 34 | self.call_times = [] |
| 35 | |
| 36 | def chat_completions_create(self, **kwargs): |
| 37 | """Mock completions.create with configurable delay""" |
| 38 | start_time = time.time() |
| 39 | time.sleep(self.response_delay) # Simulate API call delay |
| 40 | self.call_count += 1 |
| 41 | self.call_times.append(time.time()) |
| 42 | |
| 43 | call_count = self.call_count # Capture for closure |
| 44 | |
| 45 | # Check the problem content to provide appropriate mock response |
| 46 | messages = kwargs.get('messages', []) |
| 47 | problem_text = ' '.join(m.get('content', '') for m in messages if isinstance(m, dict)).lower() |
| 48 | |
| 49 | # Generate response with expected features based on problem type |
| 50 | if 'polynomial' in problem_text or 'algebra' in problem_text: |
| 51 | content = f'Using systematic analysis and case-by-case examination, solution {call_count}. The answer is 42.' |
| 52 | elif 'distribute' in problem_text or 'combinatorics' in problem_text: |
| 53 | content = f'Using stars and bars method with constraint analysis, solution {call_count}. The answer is 42.' |
| 54 | elif 'triangle' in problem_text or 'geometry' in problem_text: |
| 55 | content = f'Applying geometric inequality and area analysis, solution {call_count}. The answer is 42.' |
| 56 | else: |
| 57 | content = f'Mock mathematical solution {call_count}. The answer is 42.' |
| 58 | |
| 59 | class MockUsage: |
| 60 | def __init__(self, reasoning_tokens): |
| 61 | self.completion_tokens_details = type('obj', (), { |
| 62 | 'reasoning_tokens': reasoning_tokens |
| 63 | })() |
| 64 | self.total_tokens = reasoning_tokens + 100 |
| 65 | |
| 66 | class MockChoice: |
| 67 | def __init__(self, response_content): |
| 68 | self.message = type('obj', (), { |
| 69 | 'content': response_content |
| 70 | })() |
| 71 | |
| 72 | class MockResponse: |
| 73 | def __init__(self, reasoning_tokens, response_content): |
| 74 | self.choices = [MockChoice(response_content)] |
| 75 | self.usage = MockUsage(reasoning_tokens) |
| 76 | |
| 77 | return MockResponse(self.reasoning_tokens, content) |
| 78 | |
| 79 | @property |
| 80 | def chat(self): |
| 81 | return type('obj', (), { |
| 82 | 'completions': type('obj', (), { |
| 83 | 'create': self.chat_completions_create |
| 84 | })() |
no outgoing calls