-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemporary_eval.py
More file actions
83 lines (62 loc) · 3.01 KB
/
Copy pathtemporary_eval.py
File metadata and controls
83 lines (62 loc) · 3.01 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# IN TEST PROMPT PASTE THE PROBLEM/DOUBT/QUESTION YOU WANT TO TEST THE MODELS WITH
#DEPRECATED
from model_use import get_responses_from_models , model_list
import os
from llm_evaluator import LLMEvaluator
import uuid
api_key = os.getenv("OPENROUTER_API_KEY")
#test_prompt = "Explain the theory of relativity in just one line ."
test_prompt ="""
A bar of mass 𝑀 = 1.00 kg and length 𝐿 = 0.20 m is lying on a horizontal frictionless surface. One
end of the bar is pivoted at a point about which it is free to rotate. A small mass 𝑚 = 0.10 kg is
moving on the same horizontal surface with 5.00 m/s
speed on a path perpendicular to the bar. It
hits the bar at a distance 𝐿/2 from the pivoted end and returns back on the same path with speed v.
After this elastic collision, the bar rotates with an angular velocity 𝜔. Which of the following
statement is correct?
(A) 𝜔 = 6.98 rad/ s and v = 4.30 m /s
(B) 𝜔 = 3.75 rad /s and v = 4.30 m /s
(C) 𝜔 = 3.75 rad/ s and v = 10.0 m/ s
(D) 𝜔 = 6.80 rad/ s and v = 4.10 m /s
Limit your response to 300 words.
"""
#If not specified then limit your response to 200 words
# 1. Instantiate evaluator
evaluator = LLMEvaluator()
# 2. Generate a unique prompt_id for this workflow
prompt_id = str(uuid.uuid4())
# 3. Get model responses
models_response = get_responses_from_models(model_list, test_prompt, api_key)
# 4. Aggregate all responses into a single string for judge
responses_text = ""
for i, (model_name, response) in enumerate(models_response.items(), 1):
content = getattr(response, "content", str(response))
responses_text += f"\n**Response {chr(64+i)} ({model_name}):**\n{content}\n"
print("===============================================================================================================" )
print("Model Responses:")
for model_name, response in models_response.items():
content = getattr(response, "content", str(response))
print(f"{model_name}: {content}")
print(":===============================================================================================================")
# 5. Judge all responses together
comparative_prompt = f"""
{evaluator.system_prompt}
## Comparative Evaluation Task
**Teaching Scenario/Student Question/Problem Asked :**
{test_prompt}
**AI Model Responses:**
{responses_text}
Please evaluate these responses using the comparative evaluation framework. Provide head-to-head scores and determine the winner.
"""
judge_response = evaluator.judge_model_invoke(comparative_prompt)
# 6. Store everything in one row in prompt_workflow
evaluator.store_full_workflow(
prompt_id=prompt_id,
test_prompt=test_prompt,
all_models_response=responses_text,
judge_response=judge_response
)
print("Judge Model Comparative Response:")
print("Judge Model Response:===============================================================================================================" )
print(judge_response)
print ("==============================================================================================================================")