graph, prompts are added
Browse files- app.py +66 -4
- ats.py +72 -0
- config.py +5 -1
- graph.py +20 -3
- prompts.py +104 -0
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import logging
|
| 2 |
import sys
|
| 3 |
import uuid
|
|
|
|
| 4 |
|
| 5 |
import gradio as gr
|
| 6 |
from langchain_core.messages import AIMessage, HumanMessage
|
|
@@ -8,6 +9,7 @@ from langchain_core.messages import AIMessage, HumanMessage
|
|
| 8 |
from config import ConfigError, get_settings
|
| 9 |
from graph import build_graph
|
| 10 |
from observability import build_run_config, flush
|
|
|
|
| 11 |
|
| 12 |
logging.basicConfig(level=logging.INFO, format="%(levelname)s %(name)s: %(message)s")
|
| 13 |
logger = logging.getLogger("job-chat")
|
|
@@ -19,6 +21,10 @@ except (ConfigError, FileNotFoundError) as exc:
|
|
| 19 |
sys.exit(f"Startup failed: {exc}")
|
| 20 |
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
def new_thread_id():
|
| 23 |
return str(uuid.uuid4())
|
| 24 |
|
|
@@ -35,28 +41,66 @@ def add_user_message(user_query, chat_history):
|
|
| 35 |
return "", chat_history + [{"role": "user", "content": user_query}]
|
| 36 |
|
| 37 |
|
| 38 |
-
def
|
| 39 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
if not chat_history or chat_history[-1]["role"] != "user":
|
| 41 |
yield chat_history
|
| 42 |
return
|
| 43 |
|
| 44 |
job_description = (job_description or "").strip()
|
| 45 |
state = {
|
| 46 |
-
"messages": [HumanMessage(content=chat_history[-1]["content"])],
|
| 47 |
"job_description": job_description,
|
|
|
|
| 48 |
}
|
| 49 |
config = build_run_config(thread_id, job_description)
|
| 50 |
|
| 51 |
chat_history = chat_history + [{"role": "assistant", "content": ""}]
|
| 52 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
for chunk, _meta in GRAPH.stream(state, config, stream_mode="messages"):
|
| 54 |
if isinstance(chunk, AIMessage) and chunk.content:
|
| 55 |
chat_history[-1]["content"] += chunk.content
|
| 56 |
yield chat_history
|
| 57 |
except Exception as exc:
|
| 58 |
logger.exception("Request failed")
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
yield chat_history
|
| 61 |
|
| 62 |
|
|
@@ -79,6 +123,12 @@ with gr.Blocks(title="job-chat", fill_height=True, analytics_enabled=False) as d
|
|
| 79 |
clear_jd_btn = gr.Button("Clear job description")
|
| 80 |
|
| 81 |
with gr.Column(scale=2):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
chatbot = gr.Chatbot(height=520, show_label=False, resizable=True)
|
| 83 |
query_box = gr.Textbox(
|
| 84 |
placeholder="Ask a question...",
|
|
@@ -104,6 +154,18 @@ with gr.Blocks(title="job-chat", fill_height=True, analytics_enabled=False) as d
|
|
| 104 |
outputs=chatbot,
|
| 105 |
)
|
| 106 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
|
| 108 |
if __name__ == "__main__":
|
| 109 |
logger.info("Model: %s | tracing: %s", SETTINGS.model, SETTINGS.tracing_enabled)
|
|
|
|
| 1 |
import logging
|
| 2 |
import sys
|
| 3 |
import uuid
|
| 4 |
+
from functools import partial
|
| 5 |
|
| 6 |
import gradio as gr
|
| 7 |
from langchain_core.messages import AIMessage, HumanMessage
|
|
|
|
| 9 |
from config import ConfigError, get_settings
|
| 10 |
from graph import build_graph
|
| 11 |
from observability import build_run_config, flush
|
| 12 |
+
from prompts import ACTIONS
|
| 13 |
|
| 14 |
logging.basicConfig(level=logging.INFO, format="%(levelname)s %(name)s: %(message)s")
|
| 15 |
logger = logging.getLogger("job-chat")
|
|
|
|
| 21 |
sys.exit(f"Startup failed: {exc}")
|
| 22 |
|
| 23 |
|
| 24 |
+
# Actions whose node returns one structured object rather than a token stream.
|
| 25 |
+
STRUCTURED_ACTIONS = {"ats"}
|
| 26 |
+
|
| 27 |
+
|
| 28 |
def new_thread_id():
|
| 29 |
return str(uuid.uuid4())
|
| 30 |
|
|
|
|
| 41 |
return "", chat_history + [{"role": "user", "content": user_query}]
|
| 42 |
|
| 43 |
|
| 44 |
+
def show_action_label(label, chat_history):
|
| 45 |
+
"""Show the button's short label in the chat instead of its full instruction."""
|
| 46 |
+
return chat_history + [{"role": "user", "content": f"**{label}**"}]
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def run_action(key, chat_history, job_description, thread_id):
|
| 50 |
+
_, instruction = ACTIONS[key]
|
| 51 |
+
yield from stream_response(
|
| 52 |
+
chat_history, job_description, thread_id, model_query=instruction, action=key
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def stream_response(chat_history, job_description, thread_id, model_query=None, action=""):
|
| 57 |
+
"""Stream the assistant reply for the last user message.
|
| 58 |
+
|
| 59 |
+
model_query lets a preset action send its full instruction to the model
|
| 60 |
+
while the chat shows only a short label. Structured actions cannot stream
|
| 61 |
+
token by token, so they show a placeholder and then replace it.
|
| 62 |
+
"""
|
| 63 |
if not chat_history or chat_history[-1]["role"] != "user":
|
| 64 |
yield chat_history
|
| 65 |
return
|
| 66 |
|
| 67 |
job_description = (job_description or "").strip()
|
| 68 |
state = {
|
| 69 |
+
"messages": [HumanMessage(content=model_query or chat_history[-1]["content"])],
|
| 70 |
"job_description": job_description,
|
| 71 |
+
"action": action,
|
| 72 |
}
|
| 73 |
config = build_run_config(thread_id, job_description)
|
| 74 |
|
| 75 |
chat_history = chat_history + [{"role": "assistant", "content": ""}]
|
| 76 |
try:
|
| 77 |
+
if action in STRUCTURED_ACTIONS:
|
| 78 |
+
chat_history[-1]["content"] = "_Extracting and scoring keywords…_"
|
| 79 |
+
yield chat_history
|
| 80 |
+
result = GRAPH.invoke(state, config)
|
| 81 |
+
chat_history[-1]["content"] = result["messages"][-1].content
|
| 82 |
+
yield chat_history
|
| 83 |
+
return
|
| 84 |
+
|
| 85 |
for chunk, _meta in GRAPH.stream(state, config, stream_mode="messages"):
|
| 86 |
if isinstance(chunk, AIMessage) and chunk.content:
|
| 87 |
chat_history[-1]["content"] += chunk.content
|
| 88 |
yield chat_history
|
| 89 |
except Exception as exc:
|
| 90 |
logger.exception("Request failed")
|
| 91 |
+
detail = str(exc)
|
| 92 |
+
if "tokens per day" in detail or "TPD" in detail:
|
| 93 |
+
detail = (
|
| 94 |
+
"Groq daily token limit reached. The quota resets on a rolling "
|
| 95 |
+
"24-hour basis, or you can raise it on the Groq billing page."
|
| 96 |
+
)
|
| 97 |
+
elif "rate_limit" in detail or "413" in detail:
|
| 98 |
+
detail = (
|
| 99 |
+
"Groq per-minute token limit hit. The profile, job description, and "
|
| 100 |
+
"reserved response tokens exceed the allowance for one request. Shorten "
|
| 101 |
+
"the job description, lower LLM_MAX_TOKENS, or wait a minute and retry."
|
| 102 |
+
)
|
| 103 |
+
chat_history[-1]["content"] = f"**Request failed.** {detail}"
|
| 104 |
yield chat_history
|
| 105 |
|
| 106 |
|
|
|
|
| 123 |
clear_jd_btn = gr.Button("Clear job description")
|
| 124 |
|
| 125 |
with gr.Column(scale=2):
|
| 126 |
+
with gr.Row():
|
| 127 |
+
action_buttons = {
|
| 128 |
+
key: gr.Button(label, size="sm")
|
| 129 |
+
for key, (label, _) in ACTIONS.items()
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
chatbot = gr.Chatbot(height=520, show_label=False, resizable=True)
|
| 133 |
query_box = gr.Textbox(
|
| 134 |
placeholder="Ask a question...",
|
|
|
|
| 154 |
outputs=chatbot,
|
| 155 |
)
|
| 156 |
|
| 157 |
+
for key, button in action_buttons.items():
|
| 158 |
+
button.click(
|
| 159 |
+
partial(show_action_label, ACTIONS[key][0]),
|
| 160 |
+
inputs=chatbot,
|
| 161 |
+
outputs=chatbot,
|
| 162 |
+
queue=False,
|
| 163 |
+
).then(
|
| 164 |
+
partial(run_action, key),
|
| 165 |
+
inputs=[chatbot, jd_box, thread_id],
|
| 166 |
+
outputs=chatbot,
|
| 167 |
+
)
|
| 168 |
+
|
| 169 |
|
| 170 |
if __name__ == "__main__":
|
| 171 |
logger.info("Model: %s | tracing: %s", SETTINGS.model, SETTINGS.tracing_enabled)
|
ats.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""ATS keyword analysis.
|
| 2 |
+
|
| 3 |
+
The model classifies keywords; Python computes the score. Counting and
|
| 4 |
+
arithmetic are exactly what language models are unreliable at, so the score is
|
| 5 |
+
derived from the length of the returned lists and cannot disagree with them.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
from pydantic import BaseModel, Field
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class MatchedKeyword(BaseModel):
|
| 12 |
+
keyword: str = Field(description="The keyword exactly as written in the job description.")
|
| 13 |
+
evidence: str = Field(description="Where it appears in the candidate documents: project, role, or skill list.")
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class MissingKeyword(BaseModel):
|
| 17 |
+
keyword: str = Field(description="The keyword exactly as written in the job description.")
|
| 18 |
+
closest: str = Field(description="The nearest thing the candidate does have, or 'no adjacent experience'.")
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
class PriorityFix(BaseModel):
|
| 22 |
+
keyword: str = Field(description="A missing keyword worth addressing.")
|
| 23 |
+
can_honestly_add: bool = Field(
|
| 24 |
+
description="True if evidence already exists in the documents and only needs surfacing. "
|
| 25 |
+
"False if the candidate would have to genuinely acquire the skill."
|
| 26 |
+
)
|
| 27 |
+
note: str = Field(description="One sentence on what to do about it.")
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
class ATSAnalysis(BaseModel):
|
| 31 |
+
"""Keyword classification of a job description against the candidate documents."""
|
| 32 |
+
|
| 33 |
+
matched: list[MatchedKeyword] = Field(
|
| 34 |
+
description="Every job-description keyword the candidate documents support."
|
| 35 |
+
)
|
| 36 |
+
missing: list[MissingKeyword] = Field(
|
| 37 |
+
description="Every job-description keyword the candidate documents do not support."
|
| 38 |
+
)
|
| 39 |
+
priority_fixes: list[PriorityFix] = Field(
|
| 40 |
+
description="Up to three missing keywords that would most improve the score, most valuable first."
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def format_ats_report(analysis: ATSAnalysis) -> str:
|
| 45 |
+
"""Render the analysis, computing the score from the list lengths."""
|
| 46 |
+
matched, missing = analysis.matched, analysis.missing
|
| 47 |
+
total = len(matched) + len(missing)
|
| 48 |
+
if total == 0:
|
| 49 |
+
return "No keywords could be extracted from the job description. Check that one is loaded."
|
| 50 |
+
|
| 51 |
+
score = round(100 * len(matched) / total)
|
| 52 |
+
|
| 53 |
+
lines = [
|
| 54 |
+
f"## ATS score: {score}%",
|
| 55 |
+
"",
|
| 56 |
+
f"**{len(matched)} of {total}** job-description keywords are supported by your documents.",
|
| 57 |
+
"",
|
| 58 |
+
f"## Matched keywords ({len(matched)})",
|
| 59 |
+
"",
|
| 60 |
+
]
|
| 61 |
+
lines += [f"{i}. **{k.keyword}** — {k.evidence}" for i, k in enumerate(matched, 1)] or ["_None._"]
|
| 62 |
+
|
| 63 |
+
lines += ["", f"## Missing keywords ({len(missing)})", ""]
|
| 64 |
+
lines += [f"{i}. **{k.keyword}** — {k.closest}" for i, k in enumerate(missing, 1)] or ["_None._"]
|
| 65 |
+
|
| 66 |
+
if analysis.priority_fixes:
|
| 67 |
+
lines += ["", "## Priority fixes", ""]
|
| 68 |
+
for i, fix in enumerate(analysis.priority_fixes, 1):
|
| 69 |
+
tag = "can surface honestly" if fix.can_honestly_add else "requires actually learning it"
|
| 70 |
+
lines.append(f"{i}. **{fix.keyword}** _({tag})_ — {fix.note}")
|
| 71 |
+
|
| 72 |
+
return "\n".join(lines)
|
config.py
CHANGED
|
@@ -13,7 +13,11 @@ PROJECT_ROOT = Path(__file__).parent
|
|
| 13 |
|
| 14 |
DEFAULT_MODEL = "openai/gpt-oss-120b"
|
| 15 |
DEFAULT_TEMPERATURE = 0.0
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
DEFAULT_DATA_DIR = "data"
|
| 18 |
DEFAULT_LANGFUSE_HOST = "https://cloud.langfuse.com"
|
| 19 |
DEFAULT_CHECKPOINT_DB = "checkpoints.sqlite"
|
|
|
|
| 13 |
|
| 14 |
DEFAULT_MODEL = "openai/gpt-oss-120b"
|
| 15 |
DEFAULT_TEMPERATURE = 0.0
|
| 16 |
+
# The preset actions (ATS keyword tables, detailed reviews) run long, so 2048
|
| 17 |
+
# truncated them mid-answer. The ceiling is Groq's free-tier limit of 8000
|
| 18 |
+
# tokens per minute, which counts input + max_tokens together: profile (~3.9k)
|
| 19 |
+
# plus job description plus this value must stay under it.
|
| 20 |
+
DEFAULT_MAX_TOKENS = 3000
|
| 21 |
DEFAULT_DATA_DIR = "data"
|
| 22 |
DEFAULT_LANGFUSE_HOST = "https://cloud.langfuse.com"
|
| 23 |
DEFAULT_CHECKPOINT_DB = "checkpoints.sqlite"
|
graph.py
CHANGED
|
@@ -9,21 +9,24 @@ rewrite.
|
|
| 9 |
import sqlite3
|
| 10 |
from typing import Annotated, TypedDict
|
| 11 |
|
| 12 |
-
from langchain_core.messages import trim_messages
|
| 13 |
from langchain_groq import ChatGroq
|
| 14 |
from langgraph.checkpoint.sqlite import SqliteSaver
|
| 15 |
from langgraph.graph import START, StateGraph
|
| 16 |
from langgraph.graph.message import add_messages
|
| 17 |
|
|
|
|
| 18 |
from config import get_settings
|
| 19 |
from dataloader import ProfileLoader
|
| 20 |
-
from prompts import NO_JD_PLACEHOLDER, build_qa_prompt
|
| 21 |
|
| 22 |
|
| 23 |
class ChatState(TypedDict):
|
| 24 |
# add_messages appends rather than overwrites, so each turn extends the thread.
|
| 25 |
messages: Annotated[list, add_messages]
|
| 26 |
job_description: str
|
|
|
|
|
|
|
| 27 |
|
| 28 |
|
| 29 |
def build_llm():
|
|
@@ -40,6 +43,7 @@ def build_graph():
|
|
| 40 |
settings = get_settings()
|
| 41 |
profile_data = ProfileLoader(settings.data_dir).load_and_format_markdown()
|
| 42 |
chain = build_qa_prompt() | build_llm()
|
|
|
|
| 43 |
|
| 44 |
# Two messages per turn (human + ai).
|
| 45 |
max_history_messages = settings.max_history_turns * 2
|
|
@@ -64,9 +68,22 @@ def build_graph():
|
|
| 64 |
})
|
| 65 |
return {"messages": [response]}
|
| 66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
builder = StateGraph(ChatState)
|
| 68 |
builder.add_node("answer", answer)
|
| 69 |
-
builder.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
# check_same_thread=False: Gradio serves requests from a pool of threads.
|
| 72 |
conn = sqlite3.connect(str(settings.checkpoint_db), check_same_thread=False)
|
|
|
|
| 9 |
import sqlite3
|
| 10 |
from typing import Annotated, TypedDict
|
| 11 |
|
| 12 |
+
from langchain_core.messages import AIMessage, HumanMessage, SystemMessage, trim_messages
|
| 13 |
from langchain_groq import ChatGroq
|
| 14 |
from langgraph.checkpoint.sqlite import SqliteSaver
|
| 15 |
from langgraph.graph import START, StateGraph
|
| 16 |
from langgraph.graph.message import add_messages
|
| 17 |
|
| 18 |
+
from ats import ATSAnalysis, format_ats_report
|
| 19 |
from config import get_settings
|
| 20 |
from dataloader import ProfileLoader
|
| 21 |
+
from prompts import NO_JD_PLACEHOLDER, build_qa_prompt, render_system_prompt
|
| 22 |
|
| 23 |
|
| 24 |
class ChatState(TypedDict):
|
| 25 |
# add_messages appends rather than overwrites, so each turn extends the thread.
|
| 26 |
messages: Annotated[list, add_messages]
|
| 27 |
job_description: str
|
| 28 |
+
# "ats" routes to structured keyword analysis; anything else answers as chat.
|
| 29 |
+
action: str
|
| 30 |
|
| 31 |
|
| 32 |
def build_llm():
|
|
|
|
| 43 |
settings = get_settings()
|
| 44 |
profile_data = ProfileLoader(settings.data_dir).load_and_format_markdown()
|
| 45 |
chain = build_qa_prompt() | build_llm()
|
| 46 |
+
structured_llm = build_llm().with_structured_output(ATSAnalysis)
|
| 47 |
|
| 48 |
# Two messages per turn (human + ai).
|
| 49 |
max_history_messages = settings.max_history_turns * 2
|
|
|
|
| 68 |
})
|
| 69 |
return {"messages": [response]}
|
| 70 |
|
| 71 |
+
def ats_analysis(state: ChatState):
|
| 72 |
+
"""Classify keywords with structured output, then score them in Python."""
|
| 73 |
+
analysis = structured_llm.invoke([
|
| 74 |
+
SystemMessage(content=render_system_prompt(profile_data, state.get("job_description"))),
|
| 75 |
+
HumanMessage(content=state["messages"][-1].content),
|
| 76 |
+
])
|
| 77 |
+
return {"messages": [AIMessage(content=format_ats_report(analysis))]}
|
| 78 |
+
|
| 79 |
builder = StateGraph(ChatState)
|
| 80 |
builder.add_node("answer", answer)
|
| 81 |
+
builder.add_node("ats_analysis", ats_analysis)
|
| 82 |
+
builder.add_conditional_edges(
|
| 83 |
+
START,
|
| 84 |
+
lambda state: "ats_analysis" if state.get("action") == "ats" else "answer",
|
| 85 |
+
["answer", "ats_analysis"],
|
| 86 |
+
)
|
| 87 |
|
| 88 |
# check_same_thread=False: Gradio serves requests from a pool of threads.
|
| 89 |
conn = sqlite3.connect(str(settings.checkpoint_db), check_same_thread=False)
|
prompts.py
CHANGED
|
@@ -61,9 +61,113 @@ If the documents genuinely do not cover something, say so directly and stop. "Th
|
|
| 61 |
"""
|
| 62 |
|
| 63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
def build_qa_prompt() -> ChatPromptTemplate:
|
| 65 |
return ChatPromptTemplate.from_messages([
|
| 66 |
("system", QA_SYSTEM_PROMPT),
|
| 67 |
MessagesPlaceholder("history"),
|
| 68 |
("user", "{user_query}"),
|
| 69 |
]).partial(candidate_name=get_settings().candidate_name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
"""
|
| 62 |
|
| 63 |
|
| 64 |
+
def render_system_prompt(context_text, job_description) -> str:
|
| 65 |
+
"""The system prompt as plain text, for paths that bypass the chat template."""
|
| 66 |
+
return QA_SYSTEM_PROMPT.format(
|
| 67 |
+
candidate_name=get_settings().candidate_name,
|
| 68 |
+
context_text=context_text,
|
| 69 |
+
job_description=job_description or NO_JD_PLACEHOLDER,
|
| 70 |
+
)
|
| 71 |
+
|
| 72 |
+
|
| 73 |
def build_qa_prompt() -> ChatPromptTemplate:
|
| 74 |
return ChatPromptTemplate.from_messages([
|
| 75 |
("system", QA_SYSTEM_PROMPT),
|
| 76 |
MessagesPlaceholder("history"),
|
| 77 |
("user", "{user_query}"),
|
| 78 |
]).partial(candidate_name=get_settings().candidate_name)
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
# ---------------------------------------------------------------------------
|
| 82 |
+
# Preset actions.
|
| 83 |
+
#
|
| 84 |
+
# These are sent as the user turn, so they inherit the system prompt above —
|
| 85 |
+
# the grounding rules (STATED / INFERRED / UNSUPPORTED) apply to all of them
|
| 86 |
+
# and are deliberately not repeated here. Each one specifies its output format
|
| 87 |
+
# explicitly, because a named heading the model must fill is followed far more
|
| 88 |
+
# reliably than a described shape it has to infer.
|
| 89 |
+
# ---------------------------------------------------------------------------
|
| 90 |
+
|
| 91 |
+
DETAILED_REVIEW = """Produce a detailed fit review of the candidate against the loaded job description.
|
| 92 |
+
|
| 93 |
+
If no job description is loaded, say exactly that and stop.
|
| 94 |
+
|
| 95 |
+
Use these headings, in this order, with no others:
|
| 96 |
+
|
| 97 |
+
## Verdict
|
| 98 |
+
One line: Strong fit / Moderate fit / Weak fit, then a single sentence of justification.
|
| 99 |
+
|
| 100 |
+
## Requirement-by-requirement
|
| 101 |
+
A markdown table with columns: Requirement | Status | Evidence
|
| 102 |
+
- One row per meaningful requirement in the job description. Skip filler requirements ("team player", "fast-paced environment").
|
| 103 |
+
- Status is exactly one of: MET, PARTIAL, MISSING.
|
| 104 |
+
- Evidence names the specific project, role, or skill from the candidate documents. For MISSING, write "Not in documents".
|
| 105 |
+
|
| 106 |
+
## Strengths to lead with
|
| 107 |
+
Exactly three bullets, strongest first. Each names concrete evidence and why it matters for this specific role.
|
| 108 |
+
|
| 109 |
+
## Gaps that matter
|
| 110 |
+
Ranked, most damaging first. For each: the gap, then DISQUALIFYING or LEARNABLE, then one sentence of reasoning. Omit trivial gaps.
|
| 111 |
+
|
| 112 |
+
## Likely interview probes
|
| 113 |
+
Three to five questions an interviewer would most likely press on, drawn from the gaps above.
|
| 114 |
+
|
| 115 |
+
## Recommendation
|
| 116 |
+
One of: Apply / Apply with preparation / Do not apply. Then one or two sentences on why, and what to do first if relevant.
|
| 117 |
+
|
| 118 |
+
Do not invent requirements absent from the job description, and do not credit experience absent from the candidate documents."""
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
ATS_SCORE = """Produce an ATS keyword analysis of the candidate documents against the loaded job description.
|
| 122 |
+
|
| 123 |
+
If no job description is loaded, say exactly that and stop.
|
| 124 |
+
|
| 125 |
+
Extract keywords ONLY from the text inside the <job_description> tags. The categories below define what counts as a keyword — they are descriptions of term TYPES, not a checklist. Never output a term that does not literally appear in the job description.
|
| 126 |
+
|
| 127 |
+
Counts as a keyword: programming languages; frameworks and libraries; cloud platforms; infrastructure, container, and orchestration tools; databases and data stores; ML/AI techniques and methods; MLOps, CI/CD, and experiment-tracking tooling; named certifications; specific technical domains.
|
| 128 |
+
|
| 129 |
+
Does not count: soft skills and personality traits; job titles; company names; benefits; generic verbs; years-of-experience phrases; vague qualities like "fast-paced" or "team player".
|
| 130 |
+
|
| 131 |
+
Be exhaustive. Include keywords from every part of the job description, including "nice to have" sections.
|
| 132 |
+
|
| 133 |
+
Matching rules:
|
| 134 |
+
- MATCHED means the keyword appears in the candidate documents by name or as an unambiguous variant (K8s = Kubernetes, JS = JavaScript, GCP = Google Cloud Platform).
|
| 135 |
+
- Adjacent but different does NOT match. Docker is not Kubernetes; TensorFlow is not PyTorch. Those belong in Missing.
|
| 136 |
+
- Judge only on what the documents say. Give no credit for anything assumed.
|
| 137 |
+
|
| 138 |
+
Every keyword you extract must go into exactly one of the two lists — matched or missing. Do not omit any, and do not place the same keyword in both. Do not compute a score or any totals; that is calculated separately from your lists.
|
| 139 |
+
|
| 140 |
+
For priority fixes, choose up to three missing keywords that would most improve the candidate's standing, most valuable first. Mark one as honestly addable only when the evidence already exists in the documents and merely needs surfacing. Never suggest claiming a keyword the candidate cannot truthfully support."""
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
COVER_LETTER = """Write a cover letter for the candidate applying to the loaded job description.
|
| 144 |
+
|
| 145 |
+
If no job description is loaded, say exactly that and stop.
|
| 146 |
+
|
| 147 |
+
Length: 250-400 words in the letter body. This is a hard constraint.
|
| 148 |
+
|
| 149 |
+
Structure:
|
| 150 |
+
- Opening, 2-3 sentences: name the specific role and the single strongest reason this candidate fits it. Lead with evidence, not enthusiasm.
|
| 151 |
+
- Body paragraph 1: the most relevant experience, named specifically, tied to a requirement in the job description.
|
| 152 |
+
- Body paragraph 2: a second, genuinely distinct strength — a different project or skill, not a restatement of the first.
|
| 153 |
+
- Closing, 2-3 sentences: what the candidate wants to contribute, then a plain sign-off.
|
| 154 |
+
|
| 155 |
+
Voice and content:
|
| 156 |
+
- First person, the candidate's own voice, natural professional register.
|
| 157 |
+
- Every claim must trace to the candidate documents. No invented employers, dates, metrics, or outcomes.
|
| 158 |
+
- If a sentence needs a number the documents lack, insert a bracketed placeholder such as [ADD METRIC: latency improvement] instead of inventing one.
|
| 159 |
+
- Address it to "Dear Hiring Manager" unless the job description names someone.
|
| 160 |
+
- Do not open with "I am writing to express my interest" or any equivalent cliché.
|
| 161 |
+
- No filler adjectives: passionate, dynamic, results-driven, proven track record.
|
| 162 |
+
- Do not raise requirements the candidate does not meet.
|
| 163 |
+
|
| 164 |
+
After the letter, output:
|
| 165 |
+
Word count: <number>
|
| 166 |
+
and, if you used any placeholders, a short list of what the candidate needs to fill in."""
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
ACTIONS = {
|
| 170 |
+
"review": ("Detailed review", DETAILED_REVIEW),
|
| 171 |
+
"ats": ("ATS score & keywords", ATS_SCORE),
|
| 172 |
+
"cover_letter": ("Cover letter", COVER_LETTER),
|
| 173 |
+
}
|