Spaces:
Paused
Paused
Synced repo using 'sync_with_huggingface' Github Action
Browse files
app.py
CHANGED
|
@@ -19,67 +19,67 @@ MAX_ITERATIONS = 3 # Maximum number of refinement iterations
|
|
| 19 |
|
| 20 |
# Split the evaluation prompt into separate dimensions
|
| 21 |
ACCURACY_PROMPT = """
|
| 22 |
-
Evaluate the response on Accuracy: Is the response factually correct
|
| 23 |
-
|
| 24 |
Scoring Rubric:
|
| 25 |
-
Score 1: The response contains
|
| 26 |
-
Score 2: The response
|
| 27 |
-
Score 3: The response
|
| 28 |
-
Score 4: The response is
|
| 29 |
-
Score 5: The response is
|
| 30 |
-
|
| 31 |
Provide:
|
| 32 |
-
- A numeric score (1-5, where 5 is
|
| 33 |
-
- A
|
| 34 |
-
- Specific suggestions for improvement
|
| 35 |
"""
|
| 36 |
|
| 37 |
RELEVANCE_PROMPT = """
|
| 38 |
-
Evaluate the response on Relevance: Does the response
|
| 39 |
-
|
| 40 |
Scoring Rubric:
|
| 41 |
-
Score 1: The response
|
| 42 |
-
Score 2: The response addresses the
|
| 43 |
-
Score 3: The response
|
| 44 |
-
Score 4: The response
|
| 45 |
-
Score 5: The response
|
| 46 |
-
|
| 47 |
Provide:
|
| 48 |
-
- A numeric score (1-5, where 5 is
|
| 49 |
-
- A
|
| 50 |
-
- Specific suggestions for improvement
|
| 51 |
"""
|
| 52 |
|
| 53 |
CLARITY_PROMPT = """
|
| 54 |
-
Evaluate the response on Clarity: Is the response
|
| 55 |
-
|
| 56 |
Scoring Rubric:
|
| 57 |
-
Score 1: The response
|
| 58 |
-
Score 2: The response is
|
| 59 |
-
Score 3: The response is
|
| 60 |
-
Score 4: The response
|
| 61 |
-
Score 5: The response
|
| 62 |
-
|
| 63 |
Provide:
|
| 64 |
-
- A numeric score (1-5, where 5 is
|
| 65 |
-
- A
|
| 66 |
-
- Specific suggestions for improvement
|
| 67 |
"""
|
| 68 |
|
| 69 |
DEPTH_PROMPT = """
|
| 70 |
-
Evaluate the response on Depth: Does the response provide
|
| 71 |
-
|
| 72 |
Scoring Rubric:
|
| 73 |
-
Score 1: The response
|
| 74 |
-
Score 2: The response
|
| 75 |
-
Score 3: The response
|
| 76 |
-
Score 4: The response
|
| 77 |
-
Score 5: The response
|
| 78 |
-
|
| 79 |
Provide:
|
| 80 |
-
- A numeric score (1-5, where 5 is
|
| 81 |
-
- A
|
| 82 |
-
- Specific suggestions for improvement
|
| 83 |
"""
|
| 84 |
|
| 85 |
# Initialize API keys from environment variables or Streamlit secrets
|
|
@@ -160,11 +160,16 @@ async def evaluate_with_atla_async(inputs: dict[str, str]) -> Tuple[float, Dict[
|
|
| 160 |
clarity_task = evaluate_dimension(inputs["question"], inputs["response"], CLARITY_PROMPT)
|
| 161 |
depth_task = evaluate_dimension(inputs["question"], inputs["response"], DEPTH_PROMPT)
|
| 162 |
|
| 163 |
-
# Run all evaluations concurrently
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
|
| 169 |
# Calculate average score
|
| 170 |
avg_score = (accuracy_score + relevance_score + clarity_score + depth_score) / 4
|
|
|
|
| 19 |
|
| 20 |
# Split the evaluation prompt into separate dimensions
|
| 21 |
ACCURACY_PROMPT = """
|
| 22 |
+
Evaluate the response on Accuracy: Is the response factually correct, free from even minor inaccuracies, and demonstrating a deep, nuanced understanding of the subject matter?
|
| 23 |
+
|
| 24 |
Scoring Rubric:
|
| 25 |
+
Score 1: The response contains any factual errors, no matter how minor, or shows any signs of hallucination.
|
| 26 |
+
Score 2: The response is mostly accurate but lacks precision in technical details or contains slight oversimplifications.
|
| 27 |
+
Score 3: The response is accurate and precise, but fails to address potential edge cases or exceptions.
|
| 28 |
+
Score 4: The response is highly accurate, addresses edge cases, but doesn't demonstrate extraordinary depth of knowledge.
|
| 29 |
+
Score 5: The response is impeccably accurate, demonstrates expert-level understanding, and provides insights beyond common knowledge.
|
| 30 |
+
|
| 31 |
Provide:
|
| 32 |
+
- A numeric score (1-5, where 5 is near impossible to achieve)
|
| 33 |
+
- A detailed critique justifying the score, highlighting even minor inaccuracies
|
| 34 |
+
- Specific suggestions for improvement, including additional facts or nuances that could have been included
|
| 35 |
"""
|
| 36 |
|
| 37 |
RELEVANCE_PROMPT = """
|
| 38 |
+
Evaluate the response on Relevance: Does the response answer the user's question with laser-focused precision, anticipating and addressing all possible interpretations and implications?
|
| 39 |
+
|
| 40 |
Scoring Rubric:
|
| 41 |
+
Score 1: The response fails to directly address the core question or misses any subtext or implicit aspects.
|
| 42 |
+
Score 2: The response addresses the main question but overlooks subtle nuances or related concerns.
|
| 43 |
+
Score 3: The response is relevant and comprehensive but fails to prioritize the most critical aspects of the question.
|
| 44 |
+
Score 4: The response is highly relevant, prioritizes well, but doesn't explore all possible interpretations of the question.
|
| 45 |
+
Score 5: The response demonstrates perfect relevance, addresses all explicit and implicit aspects, and provides valuable additional context.
|
| 46 |
+
|
| 47 |
Provide:
|
| 48 |
+
- A numeric score (1-5, where 5 is near impossible to achieve)
|
| 49 |
+
- A detailed critique justifying the score, analyzing how well each part of the question was addressed
|
| 50 |
+
- Specific suggestions for improvement, including unexplored angles or interpretations of the question
|
| 51 |
"""
|
| 52 |
|
| 53 |
CLARITY_PROMPT = """
|
| 54 |
+
Evaluate the response on Clarity: Is the response structured with perfect logical flow, using precise language that leaves no room for misinterpretation?
|
| 55 |
+
|
| 56 |
Scoring Rubric:
|
| 57 |
+
Score 1: The response has any structural issues, unclear transitions, or imprecise language use.
|
| 58 |
+
Score 2: The response is generally clear but contains minor ambiguities or could be more concise.
|
| 59 |
+
Score 3: The response is well-structured and clear, but lacks optimal organization for the subject matter.
|
| 60 |
+
Score 4: The response demonstrates excellent clarity and structure, but falls short of absolute perfection in precision.
|
| 61 |
+
Score 5: The response exhibits flawless organization, crystal-clear explanations, and language so precise it could serve as a technical reference.
|
| 62 |
+
|
| 63 |
Provide:
|
| 64 |
+
- A numeric score (1-5, where 5 is near impossible to achieve)
|
| 65 |
+
- A detailed critique justifying the score, analyzing sentence structure, word choice, and overall organization
|
| 66 |
+
- Specific suggestions for improvement, including restructuring ideas or refining language for ultimate clarity
|
| 67 |
"""
|
| 68 |
|
| 69 |
DEPTH_PROMPT = """
|
| 70 |
+
Evaluate the response on Depth: Does the response provide extraordinarily comprehensive coverage, offering cutting-edge insights and exploring the topic to its fullest extent?
|
| 71 |
+
|
| 72 |
Scoring Rubric:
|
| 73 |
+
Score 1: The response lacks depth, misses key concepts, or fails to go beyond surface-level information.
|
| 74 |
+
Score 2: The response provides good coverage but doesn't delve into advanced concepts or implications.
|
| 75 |
+
Score 3: The response offers solid depth with some advanced concepts, but doesn't push the boundaries of the topic.
|
| 76 |
+
Score 4: The response provides excellent depth, touching on cutting-edge ideas, but falls short of exhaustive coverage.
|
| 77 |
+
Score 5: The response demonstrates unparalleled depth, offering groundbreaking insights, and exhaustively covering all aspects including future implications.
|
| 78 |
+
|
| 79 |
Provide:
|
| 80 |
+
- A numeric score (1-5, where 5 is near impossible to achieve)
|
| 81 |
+
- A detailed critique justifying the score, analyzing the breadth and depth of concepts covered
|
| 82 |
+
- Specific suggestions for improvement, including additional advanced topics, interdisciplinary connections, or futuristic implications that could have been explored
|
| 83 |
"""
|
| 84 |
|
| 85 |
# Initialize API keys from environment variables or Streamlit secrets
|
|
|
|
| 160 |
clarity_task = evaluate_dimension(inputs["question"], inputs["response"], CLARITY_PROMPT)
|
| 161 |
depth_task = evaluate_dimension(inputs["question"], inputs["response"], DEPTH_PROMPT)
|
| 162 |
|
| 163 |
+
# Run all evaluations concurrently using asyncio.gather
|
| 164 |
+
accuracy_result, relevance_result, clarity_result, depth_result = await asyncio.gather(
|
| 165 |
+
accuracy_task, relevance_task, clarity_task, depth_task
|
| 166 |
+
)
|
| 167 |
+
|
| 168 |
+
# Unpack results
|
| 169 |
+
accuracy_score, accuracy_critique = accuracy_result
|
| 170 |
+
relevance_score, relevance_critique = relevance_result
|
| 171 |
+
clarity_score, clarity_critique = clarity_result
|
| 172 |
+
depth_score, depth_critique = depth_result
|
| 173 |
|
| 174 |
# Calculate average score
|
| 175 |
avg_score = (accuracy_score + relevance_score + clarity_score + depth_score) / 4
|