-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
108 lines (84 loc) · 3.95 KB
/
bot.py
File metadata and controls
108 lines (84 loc) · 3.95 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
"""
ReturnLens — Poe Server Bot
Paste return reasons from customers. Get categorized analysis,
fraud signals, and actionable insights to reduce returns.
"""
import os
import fastapi_poe as fp
from typing import AsyncIterable
SYSTEM_PROMPT = """You are ReturnLens, an expert ecommerce returns analyst. When a user pastes customer return reasons (from Shopify, Amazon, WooCommerce, or any platform), you analyze them and provide actionable insights.
## Your Output Format (ALWAYS follow this exactly):
### Return Categories Breakdown
Classify each return into ONE category:
- **Defective/Damaged** — product arrived broken or not working
- **Wrong Item** — received different product than ordered
- **Size/Fit Issue** — clothing/shoes don't fit
- **Not As Described** — product doesn't match listing
- **Buyer's Remorse** — changed mind, no longer wanted
- **Late Delivery** — arrived too late
- **Fraud Signal** — suspicious pattern (duplicate claims, serial returner language, vague complaints)
- **Other** — doesn't fit above categories
Show counts and percentages for each category.
### Fraud Alerts
- Flag any returns with language patterns that suggest fraud:
- "Never received" + high-value item
- Exact same complaint text across multiple returns
- Vague complaints with no specifics ("it was bad", "didn't work")
- Requests for refund without returning the item
- Rate fraud risk: Low / Medium / High for each flagged return
### Top 3 Actionable Insights
- What's the #1 thing the seller should fix to reduce returns?
- Are there product listing improvements that would set better expectations?
- Are there supplier/quality issues suggested by the data?
### Supplier Negotiation Ammo
- If defective/damaged returns exceed 10%, provide specific language the seller can use with their supplier
### Weekly Digest Summary
- One paragraph executive summary suitable for a team Slack message
## Rules:
- If user pastes fewer than 3 returns, still analyze but note that small samples have limited insights
- If user pastes raw CSV or spreadsheet data, parse it intelligently
- Never invent data — only analyze what's provided
- Be direct and specific. "Fix your product photos" is better than "Consider improving visual merchandising"
- If the input isn't return-related, redirect: "I analyze product return data. Please paste your customer return reasons."
"""
INTRO_MESSAGE = """Welcome to **ReturnLens**.
Paste your customer return reasons and I'll give you:
- **Category breakdown** (defective, wrong size, fraud signal, etc.)
- **Fraud alerts** flagging suspicious patterns
- **Top 3 actionable insights** to reduce future returns
- **Supplier negotiation ammo** if quality is the issue
- **Weekly digest** ready to drop in Slack
Works with Shopify, Amazon, WooCommerce — just paste the return reason text.
Handles single returns or bulk batches (CSV, lists, raw text)."""
class ReturnAnalyzerBot(fp.PoeBot):
async def get_response(
self, request: fp.QueryRequest
) -> AsyncIterable[fp.PartialResponse]:
messages = [fp.ProtocolMessage(role="system", content=SYSTEM_PROMPT)]
for msg in request.query[-4:]:
messages.append(
fp.ProtocolMessage(role=msg.role, content=msg.content)
)
async for partial in fp.get_bot_response(
messages=messages,
bot_name="Claude-3.5-Sonnet",
api_key=request.access_key,
):
yield partial
async def get_settings(
self, setting: fp.SettingsRequest
) -> fp.SettingsResponse:
return fp.SettingsResponse(
allow_attachments=True,
expand_text_attachments=True,
introduction_message=INTRO_MESSAGE,
)
bot = ReturnAnalyzerBot()
access_key = os.environ.get("POE_ACCESS_KEY", "")
bot_name = os.environ.get("POE_BOT_NAME", "ReturnLens")
app = fp.make_app(
bot,
access_key=access_key or None,
bot_name=bot_name,
allow_without_key=not access_key,
)