Bhanumani12 commited on
Commit
17483c8
·
verified ·
1 Parent(s): 9f00d49

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -13
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 (Final Improved Prompt) ----------
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. You answer Salesforce questions with 100% accuracy and clarity, using official platform knowledge.
163
 
164
- Guidelines:
165
- - Always give answers that are at least 2 full lines long.
166
- - When asked about Apex limits (e.g., DML, SOQL, heap), always:
167
- - Mention the numeric limit (e.g., 150 DML statements)
168
- - Include the transaction context (sync/async)
169
- - Suggest using monitoring methods like Limits.getDMLStatements()
170
- - Avoid making up numbers if unsure, suggest Trailhead or official docs.
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()) < 20:
187
- output += "\n\nPlease refer to: https://developer.salesforce.com/docs"
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:]