File size: 1,476 Bytes
55f820f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from langchain_groq import ChatGroq
from langchain_core.prompts import PromptTemplate
import os
from dotenv import load_dotenv
load_dotenv()

llm = ChatGroq(model="llama-3.1-8b-instant", api_key=os.getenv("GROQ_API_KEY"))

prompt = PromptTemplate.from_template("""

You are RiskGuard AI, a professional digital bank assistant.



Below is the user's credit evaluation:



• Probability of Default: {probability}%

• Credit Score: {credit_score}

• Rating Category: {rating}



Write a short, friendly message (4–6 lines) following this format:



1) A polite greeting such as:

   "Thank you for using RiskGuard AI for your loan assessment."



2) A clear decision tone:

   - If the score and risk level are strong: indicate the loan is likely suitable for approval.

   - If risk is high: indicate that approval may be difficult at this time.



3) Give one or two simple, actionable suggestions for improvement (if needed).



4) Close with a short support line such as:

   "If you have questions or want guidance, feel free to talk to our loan advisor chatbot."



Tone: concise, professional, supportive. No long bullet lists, no emojis, no legal claims.

""")


def generate_advice(probability, credit_score, rating):
    formatted_prompt = prompt.format(
        probability=round(probability * 100, 2),
        credit_score=credit_score,
        rating=rating
    )

    result = llm.invoke(formatted_prompt)
    return result.content