from ..interface.base_evaluator import EvaluationResult, BaseEvaluator
import requests

class Evaluator(BaseEvaluator):
    
    def __init__(self, model_name: str = "llama3.2:3b", base_url: str = "http://localhost:11434"):
        self.base_url = base_url
        self.model_name = model_name
        
        
    SYSTEM_PROMPT = """
You are a system that evaluates the correctness of a response to a question.
The question will be provided in <question>...</question> tags.
The response will be provided in <response>...</response> tags.
The expected answer will be provided in <expected_answer>...</expected_answer> tags.

The response doesn't have to exactly match all the words/context the expected answer. It just needs to be right about
the answer to the actual question itself.

Evaluate whether the response is correct or not, and return your reasoning in <reasoning>...</reasoning> tags.
Then return the result in <result>...</result> tags — either as 'true' or 'false'.
"""

    def evaluate(self, query: str, response: str, expected_answer: str) -> EvaluationResult:
        user_prompt = f"""
        <questions> \n{query} </question>
        <response> \n{response} </response>
        <expected_answer> \n{expected_answer} </expected_answer>
        """
        
        response_content = requests.post(
            f"{self.base_url}/api/generate",
            json={
                "model": self.model_name,
                "prompt": user_prompt,
                "stream": False,
                "options": {
                    "temperature": 0.7,
                    "top_p": 0.9,
                }
            }
        
        return super().evaluate(query, response, expected_answer)
    
    