AI_Assessment_Feature_1 / chain_reports.py
Phoenix21's picture
Create chain_reports.py
25da467 verified
raw
history blame
899 Bytes
# chain_reports.py
from typing import Dict
from langchain import PromptTemplate, LLMChain
from models import chat_model
report_prompt_template = PromptTemplate(
input_variables=["qa_summary"],
template=(
"You are a wellness assistant. The user provided the following answers:\n\n"
"{qa_summary}\n\n"
"Based on these answers, provide a brief, actionable wellness report. "
"Include simple suggestions to improve their sleep, exercise, stress management, and diet. "
"Be concise and helpful.\n\n"
"Report:"
)
)
report_chain = LLMChain(llm=chat_model, prompt=report_prompt_template)
def generate_short_report_for_session(responses: Dict[str, str]) -> str:
qa_summary = "\n".join(f"{q}: {a}" for q, a in responses.items())
raw_report = report_chain.run(qa_summary=qa_summary)
return raw_report.replace("*", "").replace("**", "")