kaikaidai commited on
Commit
94cc8e3
·
verified ·
1 Parent(s): 0e485d1

Synced repo using 'sync_with_huggingface' Github Action

Browse files
Files changed (1) hide show
  1. criteria_handler.py +34 -30
criteria_handler.py CHANGED
@@ -4,6 +4,39 @@ import gradio as gr
4
  import re
5
  from eval_criteria_library import EXAMPLE_METRICS
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  def select_evaluation_criteria(data_upload_group, df_state, prompt_state):
8
  with gr.Group(visible=True) as criteria_group:
9
  select_eval_criteria_button = gr.Button("Select Evaluation Criteria", visible=False)
@@ -95,36 +128,7 @@ def select_evaluation_criteria(data_upload_group, df_state, prompt_state):
95
 
96
  def save_prompt(evaluation_criteria, input_col, output_col, context_col, expected_output_col):
97
  # Use the actual Jinja template with proper Jinja syntax and raw JSON
98
- template = '''You are tasked with evaluating a response based on a given instruction (which may contain an Input) and a scoring rubric. Provide a comprehensive feedback on the response quality strictly adhering to the scoring rubric, without any general evaluation. Follow this with a score, referring to the scoring rubric. Avoid generating any additional opening, closing, or explanations.
99
-
100
- Here are some rules of the evaluation:
101
- (1) You should prioritize evaluating whether the response satisfies the provided rubric. The basis of your score should depend exactly on the rubric. However, the response does not need to explicitly address points raised in the rubric. Rather, evaluate the response based on the criteria outlined in the rubric.
102
-
103
- Your reply should strictly follow this format:
104
- Your output format should strictly adhere to JSON as follows: {% raw %}{"feedback": "<write feedback>", "result": <numerical score>}{% endraw %}. Ensure the output is valid JSON, without additional formatting or explanations.
105
-
106
- Here is the data.
107
-
108
- {% if model_context is defined and model_context %}Context:
109
- ```
110
- {{ model_context }}
111
- ```
112
-
113
- {% endif %}Instruction:
114
- ```
115
- {{ model_input }}
116
- ```
117
-
118
- Response:
119
- ```
120
- {{ model_output }}
121
- ```
122
-
123
- Score Rubrics:
124
- {{ evaluation_criteria }}
125
-
126
- {% if expected_model_output is defined and expected_model_output %}Reference answer:
127
- {{ expected_model_output }}{% endif %}'''
128
 
129
  # Create mapping dictionary
130
  mapping_dict = {
 
4
  import re
5
  from eval_criteria_library import EXAMPLE_METRICS
6
 
7
+ SYSTEM_PROMPT = """Please act as an impartial judge and evaluate based on the user's instruction. Your output format should strictly adhere to JSON as follows: {"feedback": "<write feedback>", "result": <numerical score>}. Ensure the output is valid JSON, without additional formatting or explanations."""
8
+
9
+ EVALUATION_TEMPLATE = '''You are tasked with evaluating a response based on a given instruction (which may contain an Input) and a scoring rubric. Provide a comprehensive feedback on the response quality strictly adhering to the scoring rubric, without any general evaluation. Follow this with a score, referring to the scoring rubric. Avoid generating any additional opening, closing, or explanations.
10
+
11
+ Here are some rules of the evaluation:
12
+ (1) You should prioritize evaluating whether the response satisfies the provided rubric. The basis of your score should depend exactly on the rubric. However, the response does not need to explicitly address points raised in the rubric. Rather, evaluate the response based on the criteria outlined in the rubric.
13
+
14
+ Your reply should strictly follow this format:
15
+ Your output format should strictly adhere to JSON as follows: {% raw %}{"feedback": "<write feedback>", "result": <numerical score>}{% endraw %}. Ensure the output is valid JSON, without additional formatting or explanations.
16
+
17
+ Here is the data.
18
+
19
+ {% if model_context is defined and model_context %}Context:
20
+ ```
21
+ {{ model_context }}
22
+ ```
23
+
24
+ {% endif %}Instruction:
25
+ ```
26
+ {{ model_input }}
27
+ ```
28
+
29
+ Response:
30
+ ```
31
+ {{ model_output }}
32
+ ```
33
+
34
+ Score Rubrics:
35
+ {{ evaluation_criteria }}
36
+
37
+ {% if expected_model_output is defined and expected_model_output %}Reference answer:
38
+ {{ expected_model_output }}{% endif %}'''
39
+
40
  def select_evaluation_criteria(data_upload_group, df_state, prompt_state):
41
  with gr.Group(visible=True) as criteria_group:
42
  select_eval_criteria_button = gr.Button("Select Evaluation Criteria", visible=False)
 
128
 
129
  def save_prompt(evaluation_criteria, input_col, output_col, context_col, expected_output_col):
130
  # Use the actual Jinja template with proper Jinja syntax and raw JSON
131
+ template = EVALUATION_TEMPLATE
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
 
133
  # Create mapping dictionary
134
  mapping_dict = {