arymandeshwal commited on
Commit ·
54fc86e
1
Parent(s): 66c2554
Feat: Added temp param to model, created summary and scorer agents
Browse files- core/__init__.py +0 -0
- core/model.py +3 -2
- core/response_evaluator.py +169 -0
core/__init__.py
ADDED
|
File without changes
|
core/model.py
CHANGED
|
@@ -5,7 +5,7 @@ from openai import OpenAI
|
|
| 5 |
# Load environment variables from .env file
|
| 6 |
load_dotenv()
|
| 7 |
|
| 8 |
-
def generate_response(system_prompt, user_prompt):
|
| 9 |
"""
|
| 10 |
Generate a response using Gemini LLM.
|
| 11 |
|
|
@@ -34,7 +34,8 @@ def generate_response(system_prompt, user_prompt):
|
|
| 34 |
messages=[
|
| 35 |
{"role": "system", "content": system_prompt},
|
| 36 |
{"role": "user", "content": user_prompt}
|
| 37 |
-
]
|
|
|
|
| 38 |
)
|
| 39 |
|
| 40 |
# Return the generated response
|
|
|
|
| 5 |
# Load environment variables from .env file
|
| 6 |
load_dotenv()
|
| 7 |
|
| 8 |
+
def generate_response(system_prompt: str, user_prompt: str, temp: float = 0.7):
|
| 9 |
"""
|
| 10 |
Generate a response using Gemini LLM.
|
| 11 |
|
|
|
|
| 34 |
messages=[
|
| 35 |
{"role": "system", "content": system_prompt},
|
| 36 |
{"role": "user", "content": user_prompt}
|
| 37 |
+
],
|
| 38 |
+
temperature=temp
|
| 39 |
)
|
| 40 |
|
| 41 |
# Return the generated response
|
core/response_evaluator.py
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from model import generate_response
|
| 2 |
+
import json
|
| 3 |
+
from typing import List
|
| 4 |
+
from pydantic import BaseModel
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
SYS_PROMPT= """
|
| 8 |
+
You are Scorer API. You always respond in proper, directly parsable JSON.
|
| 9 |
+
You are a highly accurate, impartial, JSON-only scoring system.
|
| 10 |
+
Your sole task is to evaluate two written answers to the same question: one from a user and one from a competitor.
|
| 11 |
+
|
| 12 |
+
You are provided with the following input:
|
| 13 |
+
- job_description: a role-specific job description that defines the expected skills, tone, and content quality.
|
| 14 |
+
- question: an open-ended prompt relevant to the job.
|
| 15 |
+
- user: the user's written answer to the question.
|
| 16 |
+
- competitor: the competitor's written answer to the same question.
|
| 17 |
+
|
| 18 |
+
Evaluate each answer based on the rubric and **how well it aligns with the job description**.
|
| 19 |
+
|
| 20 |
+
Rubric criteria (each scored from 0-5):
|
| 21 |
+
1. structure_star - Logical organization and coherence.
|
| 22 |
+
2. depth - Insight, reasoning, and sophistication, especially in relation to the job requirements.
|
| 23 |
+
3. clarity - How clear, readable, and accessible the response is.
|
| 24 |
+
4. correctness - Factual and conceptual accuracy, including relevance to the job description.
|
| 25 |
+
|
| 26 |
+
Important:
|
| 27 |
+
- Improvement tip should be less than 25 words.
|
| 28 |
+
Your output must strictly follow this **parsable JSON format**:
|
| 29 |
+
|
| 30 |
+
{
|
| 31 |
+
"user": {
|
| 32 |
+
"structure_star": {"score": 0-5, "improvement_tip": "STRING"},
|
| 33 |
+
"depth": {"score": 0-5, "improvement_tip": "STRING"},
|
| 34 |
+
"clarity": {"score": 0-5, "improvement_tip": "STRING"},
|
| 35 |
+
"correctness": {"score": 0-5, "improvement_tip": "STRING"}
|
| 36 |
+
},
|
| 37 |
+
"competitor": {
|
| 38 |
+
"structure_star": {"score": 0-5, "improvement_tip": "STRING"},
|
| 39 |
+
"depth": {"score": 0-5, "improvement_tip": "STRING"},
|
| 40 |
+
"clarity": {"score": 0-5, "improvement_tip": "STRING"},
|
| 41 |
+
"correctness": {"score": 0-5, "improvement_tip": "STRING"}
|
| 42 |
+
}
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
Only output a valid JSON object. Do not include any commentary, headers, or extra text outside of the JSON.
|
| 46 |
+
|
| 47 |
+
"""
|
| 48 |
+
|
| 49 |
+
def trim_backticks(model_response: str):
|
| 50 |
+
return model_response[8:-4]
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def scorer(jd:str, ques: str, user: str, competitor: str):
|
| 54 |
+
user_prompt = f"""
|
| 55 |
+
You are Scorer API.
|
| 56 |
+
Please evaluate the following answers based on the rubric criteria (structure_star, depth, clarity, correctness), considering the job description provided.
|
| 57 |
+
Return a **valid, strictly formatted JSON object** as described.
|
| 58 |
+
|
| 59 |
+
job_description:
|
| 60 |
+
{jd}
|
| 61 |
+
|
| 62 |
+
question:
|
| 63 |
+
{ques}
|
| 64 |
+
|
| 65 |
+
user:
|
| 66 |
+
{user}
|
| 67 |
+
|
| 68 |
+
competitor:
|
| 69 |
+
{competitor}
|
| 70 |
+
"""
|
| 71 |
+
response = generate_response(system_prompt=SYS_PROMPT, user_prompt=user_prompt, temp=0.1)
|
| 72 |
+
if response.startswith("```"):
|
| 73 |
+
response = trim_backticks(response)
|
| 74 |
+
|
| 75 |
+
parsed_response = json.loads(response)
|
| 76 |
+
return parsed_response
|
| 77 |
+
|
| 78 |
+
class Collect_score(BaseModel):
|
| 79 |
+
category: str
|
| 80 |
+
score: str
|
| 81 |
+
improvement_tip: str
|
| 82 |
+
|
| 83 |
+
def improvement_summary(scores: List[Collect_score]):
|
| 84 |
+
system_prompt = """
|
| 85 |
+
You are Summarizer, a writing assistant focused on delivering concise improvement insights.
|
| 86 |
+
|
| 87 |
+
You will receive a list of objects, each containing:
|
| 88 |
+
- category (string): the evaluation dimension (e.g., "structure_star", "depth", etc.)
|
| 89 |
+
- score (string): a number between "0" and "5"
|
| 90 |
+
- improvement_tip (string): an actionable suggestion
|
| 91 |
+
|
| 92 |
+
Your task:
|
| 93 |
+
1. For these five, rewrite the `improvement_tip` into a short, readable, properly formatted string.
|
| 94 |
+
2. Each line should start with the category in bold, followed by a colon and the rewritten improvement tip.
|
| 95 |
+
3. Return a simple, plain text string of 5 lines. No extra text or formatting beyond what is specified.
|
| 96 |
+
4. Merge improvement tips of same categories.
|
| 97 |
+
|
| 98 |
+
Format example:
|
| 99 |
+
**structure_star**: Consider using clearer paragraph breaks to improve organization.
|
| 100 |
+
**depth**: Expand on your examples to show deeper understanding.
|
| 101 |
+
...
|
| 102 |
+
|
| 103 |
+
"""
|
| 104 |
+
scores_json = json.dumps([score.model_dump() for score in scores])
|
| 105 |
+
user_prompt = f"""
|
| 106 |
+
Here are the scores and improvement tips to summarize:
|
| 107 |
+
{scores_json}
|
| 108 |
+
|
| 109 |
+
Please provide a concise summary with formatting as described.
|
| 110 |
+
"""
|
| 111 |
+
response = generate_response(system_prompt=system_prompt, user_prompt=user_prompt, temp=0.3)
|
| 112 |
+
return response
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
if __name__ == "__main__":
|
| 117 |
+
jd = """
|
| 118 |
+
We are seeking a product manager with experience in agile development,
|
| 119 |
+
cross-functional collaboration, and data-driven decision-making.
|
| 120 |
+
Strong communication skills and the ability to prioritize customer needs
|
| 121 |
+
are essential.
|
| 122 |
+
"""
|
| 123 |
+
ques = "How do you prioritize features during a product sprint?"
|
| 124 |
+
user = """
|
| 125 |
+
I look at customer pain points and align them with strategic goals.
|
| 126 |
+
Then I negotiate with engineering based on effort and value.
|
| 127 |
+
"""
|
| 128 |
+
competitor = """
|
| 129 |
+
I use a RICE scoring model and validate assumptions with customer interviews and
|
| 130 |
+
analytics. Prioritization is then presented in sprint planning.
|
| 131 |
+
"""
|
| 132 |
+
print(scorer(jd=jd,
|
| 133 |
+
ques=ques,
|
| 134 |
+
user=user,
|
| 135 |
+
competitor=competitor))
|
| 136 |
+
|
| 137 |
+
scores = [
|
| 138 |
+
Collect_score(
|
| 139 |
+
category="structure_star",
|
| 140 |
+
score="3",
|
| 141 |
+
improvement_tip="Use more paragraph breaks and bullet points"
|
| 142 |
+
),
|
| 143 |
+
Collect_score(
|
| 144 |
+
category="depth",
|
| 145 |
+
score="4",
|
| 146 |
+
improvement_tip="Include more specific industry examples"
|
| 147 |
+
),
|
| 148 |
+
Collect_score(
|
| 149 |
+
category="clarity",
|
| 150 |
+
score="2",
|
| 151 |
+
improvement_tip="Simplify technical jargon for broader audience"
|
| 152 |
+
),
|
| 153 |
+
Collect_score(
|
| 154 |
+
category="correctness",
|
| 155 |
+
score="5",
|
| 156 |
+
improvement_tip="Excellent factual accuracy, maintain this standard"
|
| 157 |
+
),
|
| 158 |
+
Collect_score(
|
| 159 |
+
category="depth",
|
| 160 |
+
score="3",
|
| 161 |
+
improvement_tip="include more in depth approach."
|
| 162 |
+
)
|
| 163 |
+
]
|
| 164 |
+
summary = improvement_summary(scores)
|
| 165 |
+
print(summary)
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
|