回复评价能让客户感受到有人在倾听,潜在买家也会阅读这些回复。但每周要用多种语言认真写出几百条回复,得花上好几个小时。本文用本地大语言模型为每条评价起草回复,使用与评价相同的语言,并遵循你的品牌说明和一套严格的规则。它会标记出需要人工处理的评价,例如低分评价、安全问题、法律威胁或疑似欺诈,并把所有内容写入一张表格供审核。任何内容都不会自动发布。
使用用本地大模型分析商品评价中配置好的 /opt/reviews 环境和 Ollama。同一个评价 CSV 文件在这里也能直接使用;脚本需要 id 和 text 两列,如果有 rating 列也会一并使用。
模型会依据这份说明确定语气、联系方式以及可以提及的事实。内容要简短、实事求是:
cat > /data/reviews/brand.txt <<'EOF2'
Business: ACME Home, sells bamboo office accessories online.
Tone: warm and simple, no slang, no emoji.
Support contact: the "Contact seller" button on the order page, or [email protected].
Facts you may mention: 12-month warranty on all stands.
Sign off as: The ACME Home team
EOF2
cat > /opt/reviews/replies.py <<'EOF2'
import csv, json, os, re, sys
import ollama
MODEL = os.environ.get("MODEL", "qwen2.5:7b")
BRAND = open(os.environ.get("BRAND_FILE", "brand.txt"), encoding="utf-8").read()
ESCALATE = re.compile(os.environ.get("ESCALATE",
r"refund|chargeback|injur|burn|fire|smoke|allerg|lawyer|lawsuit|scam|fraud|fake|police|退款|投诉|受伤|起火|过敏|律师|骗"), re.I)
SCHEMA = {"type": "object", "properties": {
"reply": {"type": "string"}, "needs_human": {"type": "boolean"}, "reason": {"type": "string"}},
"required": ["reply", "needs_human", "reason"]}
SYSTEM = """You draft public replies to customer reviews for the business described in the brand notes.
Rules:
- Reply in the same language as the review, in 2 to 4 sentences.
- Thank the customer and respond to the specific point they made. Vary your wording.
- Never admit legal liability. Never promise refunds, replacements, discounts or compensation.
- Never ask the customer to change or remove their review, and never offer anything in return for a review.
- Never include order numbers, names or other personal data.
- For problems, apologise briefly and invite the customer to contact support as described in the brand notes.
- Set needs_human to true for safety issues, legal threats, suspected fraud, abuse, or if you are unsure,
and give the reason. Otherwise leave reason empty.
Brand notes:
""" + BRAND
src, out = sys.argv[1], "replies.csv"
done = set()
if os.path.exists(out):
with open(out, encoding="utf-8-sig") as f:
done = {r["id"] for r in csv.DictReader(f)}
with open(src, encoding="utf-8-sig") as f:
reviews = [r for r in csv.DictReader(f) if r.get("text", "").strip()]
new_file = not os.path.exists(out)
with open(out, "a", newline="", encoding="utf-8-sig") as f:
w = csv.writer(f)
if new_file:
w.writerow(["id", "rating", "text", "draft_reply", "needs_human", "reason", "approved", "final_reply"])
for r in reviews:
if r["id"] in done:
continue
res = ollama.chat(model=MODEL, format=SCHEMA, options={"temperature": 0.5}, messages=[
{"role": "system", "content": SYSTEM},
{"role": "user", "content": f"Rating: {r.get('rating', '?')} of 5\nReview: {r['text'][:3000]}"}])
d = json.loads(res.message.content)
reasons = [d["reason"]] if d["needs_human"] and d["reason"] else []
if r.get("rating", "").isdigit() and int(r["rating"]) <= 2:
reasons.append("low rating")
if ESCALATE.search(r["text"]):
reasons.append("keyword: " + ESCALATE.search(r["text"]).group(0))
w.writerow([r["id"], r.get("rating", ""), r["text"], d["reply"].strip(),
"yes" if reasons or d["needs_human"] else "no", "; ".join(reasons), "", ""])
f.flush()
print(r["id"], "NEEDS HUMAN" if reasons or d["needs_human"] else "draft ok", flush=True)
print("done: replies.csv")
EOF2
当模型自己要求人工处理、评分为 2 分或以下,或者文本匹配 ESCALATE 关键词列表时,这条评价就会被标记为需要人工处理。每条评价处理完成后立即保存,下次运行时会跳过。
cd /data/reviews
/opt/reviews/bin/python /opt/reviews/replies.py reviews.csv
结果文件为 replies.csv,包含 id、rating、text、draft_reply、needs_human、reason、approved 和 final_reply 列。
replies.csv,先筛选出 needs_human = yes 的行。这些评价请亲自处理:通过平台私下联系客户,解决问题后再公开回复。final_reply 列,并把 approved 设为 yes。ESCALATE 中补充客户所用语言的关键词,例如泰语、西班牙语或日语。技术上可以通过平台 API 实现,但我们建议保留人工审核。错误的公开回复很难挽回,而且很多平台要求卖家对每一句话负责。
规则中已要求模型变换措辞,0.5 的温度也会增加一些变化。最有效的办法是在品牌说明中加入结构各不相同的示例回复。
优先回复差评和内容详细的评价,好的回复可能改变潜在买家的想法。简短的好评最多回一句简单的感谢即可。如果想整体了解客户在抱怨什么,请参阅用 Embedding 向量把评价归类成话题。
如果按以上步骤操作后问题仍未解决,请提交工单联系 IMIDC 7×24 技术支持,并附上服务器 IP、所用的模型以及报错信息,方便工程师快速定位。