Update app.py
Browse files
app.py
CHANGED
|
@@ -35,7 +35,7 @@ severities = {
|
|
| 35 |
"Best Practice": "Low"
|
| 36 |
}
|
| 37 |
|
| 38 |
-
# ---------- Load QnA Model ----------
|
| 39 |
qa_pipeline = pipeline("text2text-generation", model="google/flan-t5-large")
|
| 40 |
|
| 41 |
# ---------- Logging ----------
|
|
@@ -140,7 +140,7 @@ def validate_metadata(metadata, admin_id=None):
|
|
| 140 |
|
| 141 |
return mtype, issue, recommendation
|
| 142 |
|
| 143 |
-
# ---------- Salesforce Chatbot (
|
| 144 |
conversation_history = []
|
| 145 |
|
| 146 |
def salesforce_chatbot(query, history=[]):
|
|
@@ -159,16 +159,15 @@ def salesforce_chatbot(query, history=[]):
|
|
| 159 |
history_summary = "\n".join([f"User: {q}\nAssistant: {a}" for q, a in conversation_history[-4:]])
|
| 160 |
|
| 161 |
prompt = f"""
|
| 162 |
-
You are a certified Salesforce developer and architect.
|
| 163 |
|
| 164 |
-
|
| 165 |
-
- Always
|
| 166 |
-
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
-
|
| 171 |
-
- Format clearly, using bullet points or code if helpful.
|
| 172 |
|
| 173 |
Conversation History:
|
| 174 |
{history_summary}
|
|
@@ -183,8 +182,8 @@ Assistant:
|
|
| 183 |
if output.startswith("Assistant:"):
|
| 184 |
output = output.replace("Assistant:", "").strip()
|
| 185 |
|
| 186 |
-
if len(output.split()) <
|
| 187 |
-
output += "\n\
|
| 188 |
|
| 189 |
conversation_history.append((query, output))
|
| 190 |
conversation_history = conversation_history[-6:]
|
|
|
|
| 35 |
"Best Practice": "Low"
|
| 36 |
}
|
| 37 |
|
| 38 |
+
# ---------- Load QnA Model (no fallback) ----------
|
| 39 |
qa_pipeline = pipeline("text2text-generation", model="google/flan-t5-large")
|
| 40 |
|
| 41 |
# ---------- Logging ----------
|
|
|
|
| 140 |
|
| 141 |
return mtype, issue, recommendation
|
| 142 |
|
| 143 |
+
# ---------- Salesforce Chatbot (Improved Prompt) ----------
|
| 144 |
conversation_history = []
|
| 145 |
|
| 146 |
def salesforce_chatbot(query, history=[]):
|
|
|
|
| 159 |
history_summary = "\n".join([f"User: {q}\nAssistant: {a}" for q, a in conversation_history[-4:]])
|
| 160 |
|
| 161 |
prompt = f"""
|
| 162 |
+
You are a certified Salesforce developer and architect. Your role is to answer with 100% accurate and detailed technical explanations, especially about limits, code, and platform best practices.
|
| 163 |
|
| 164 |
+
Your answers MUST:
|
| 165 |
+
- Always be at least two lines long.
|
| 166 |
+
- Be correct, clear, and production-safe.
|
| 167 |
+
- Include official Salesforce governor limits when applicable.
|
| 168 |
+
- Use bullet points or code snippets when needed.
|
| 169 |
+
- Recommend Trailhead or official docs if the answer isn't definitive.
|
| 170 |
+
- Follow real-world practices (bulkification, error handling, etc).
|
|
|
|
| 171 |
|
| 172 |
Conversation History:
|
| 173 |
{history_summary}
|
|
|
|
| 182 |
if output.startswith("Assistant:"):
|
| 183 |
output = output.replace("Assistant:", "").strip()
|
| 184 |
|
| 185 |
+
if len(output.split()) < 15:
|
| 186 |
+
output += "\n\nRefer to: https://developer.salesforce.com/docs for more."
|
| 187 |
|
| 188 |
conversation_history.append((query, output))
|
| 189 |
conversation_history = conversation_history[-6:]
|