johnnytay commited on
Commit
03d4523
·
verified ·
1 Parent(s): 4fb1b02

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +21 -10
app.py CHANGED
@@ -148,7 +148,8 @@ async def _ensure_kb_agent():
148
  f"{inventory}\n\n"
149
  "Workflow:\n"
150
  "1. Pick the article most likely to cover the ticket.\n"
151
- "2. Call `read_text_file` with path=\"<filename>\" - basename only.\n"
 
152
  "3. Return the COMPLETE relevant section(s) verbatim, prefixed with the filename.\n"
153
  " If a section lists variants (per-tier rules, per-method steps), include ALL\n"
154
  " of them - do not filter.\n\n"
@@ -191,15 +192,24 @@ async def fetch_kb_context(state: TicketStateV2):
191
  history_block = (
192
  f"\nPrior conversation:\n{history_snippet}\n" if history_snippet else ""
193
  )
194
- result = await kb_lookup_agent.ainvoke({
195
- "messages": [(
196
- "user",
197
- f"Category: {state['category']}\n"
198
- f"Declared tier (may be stale): {state['customer_tier']}{history_block}\n"
199
- f"Current customer message: {state['customer_message']}"
200
- )]
201
- })
202
- excerpt = result["messages"][-1].content
 
 
 
 
 
 
 
 
 
203
  hit = "NO_RELEVANT_ARTICLE" not in excerpt
204
  return {
205
  "kb_context": excerpt,
@@ -397,6 +407,7 @@ demo = gr.ChatInterface(
397
  fn=respond,
398
  title="LADP Customer Support Assistant",
399
  description="Describe your issue. The agent will consult the internal KB and stream its reply.",
 
400
  examples=[
401
  "My subscription was charged twice this month - please refund one of the charges.",
402
  "I've lost my 2FA device and can't log in. What should I do?",
 
148
  f"{inventory}\n\n"
149
  "Workflow:\n"
150
  "1. Pick the article most likely to cover the ticket.\n"
151
+ "2. Call `read_text_file` with path set to the EXACT filename from the list,\n"
152
+ " including extension (for example: \"password_reset.md\").\n"
153
  "3. Return the COMPLETE relevant section(s) verbatim, prefixed with the filename.\n"
154
  " If a section lists variants (per-tier rules, per-method steps), include ALL\n"
155
  " of them - do not filter.\n\n"
 
192
  history_block = (
193
  f"\nPrior conversation:\n{history_snippet}\n" if history_snippet else ""
194
  )
195
+ try:
196
+ result = await kb_lookup_agent.ainvoke({
197
+ "messages": [(
198
+ "user",
199
+ f"Category: {state['category']}\n"
200
+ f"Declared tier (may be stale): {state['customer_tier']}{history_block}\n"
201
+ f"Current customer message: {state['customer_message']}"
202
+ )]
203
+ })
204
+ excerpt = result["messages"][-1].content
205
+ except Exception as e:
206
+ # Never crash the whole app if KB tool lookup fails.
207
+ excerpt = "NO_RELEVANT_ARTICLE"
208
+ return {
209
+ "kb_context": excerpt,
210
+ "processing_log": [f"fetch_kb_context -> tool_error ({type(e).__name__})"],
211
+ }
212
+
213
  hit = "NO_RELEVANT_ARTICLE" not in excerpt
214
  return {
215
  "kb_context": excerpt,
 
407
  fn=respond,
408
  title="LADP Customer Support Assistant",
409
  description="Describe your issue. The agent will consult the internal KB and stream its reply.",
410
+ cache_examples=False,
411
  examples=[
412
  "My subscription was charged twice this month - please refund one of the charges.",
413
  "I've lost my 2FA device and can't log in. What should I do?",