MCPcopy Index your code
hub / github.com/algorithmicsuperintelligence/optillm / evaluate_response

Function evaluate_response

scripts/eval_frames_benchmark.py:51–96  ·  view source on GitHub ↗
(question: str, llm_response: str, ground_truth: str, model: str)

Source from the content-addressed store, hash-verified

49 return response.choices[0].message.content.strip()
50
51def evaluate_response(question: str, llm_response: str, ground_truth: str, model: str) -> Dict[str, str]:
52 evaluation_prompt = f"""===Task===
53I need your help in evaluating an answer provided by an LLM against a ground
54truth answer. Your task is to determine if the ground truth answer is present in the LLM's
55response. Please analyze the provided data and make a decision.
56===Instructions===
571. Carefully compare the "Predicted Answer" with the "Ground Truth Answer".
582. Consider the substance of the answers - look for equivalent information or correct answers.
59Do not focus on exact wording unless the exact wording is crucial to the meaning.
603. Your final decision should be based on whether the meaning and the vital facts of the
61"Ground Truth Answer" are present in the "Predicted Answer:"
62===Input Data===
63- Question: {question}
64- Predicted Answer: {llm_response}
65- Ground Truth Answer: {ground_truth}
66===Output Format===
67Provide your final evaluation in the following format:
68"Explanation:" (How you made the decision?)
69"Decision:" ("TRUE" or "FALSE" )
70Please proceed with the evaluation."""
71
72 evaluation_response = client.chat.completions.create(
73 model=model,
74 messages=[
75 {"role": "system", "content": "You are a helpful assistant."},
76 {"role": "user", "content": evaluation_prompt}
77 ],
78 max_tokens=300,
79 n=1,
80 stop=None,
81 temperature=0.3,
82 )
83
84 evaluation_text = evaluation_response.choices[0].message.content.strip()
85
86 # Extract the decision and explanation
87 lines = evaluation_text.split('\n')
88 decision = "FALSE"
89 explanation = ""
90 for line in lines:
91 if line.startswith("Decision:"):
92 decision = line.split(":")[1].strip().upper()
93 elif line.startswith("Explanation:"):
94 explanation = line.split(":", 1)[1].strip()
95
96 return {"decision": decision, "explanation": explanation}
97
98def main(model: str):
99 # Load the dataset

Callers 1

mainFunction · 0.70

Calls 1

createMethod · 0.45

Tested by

no test coverage detected