1
📥
Ambil COD orderAPI platform — fetch COD orders terkini
2
🔍
Semak profil pelangganSejarah bayaran, alamat, nilai pesanan
3
⚠️
Kira risiko returnGuna model LLM + peraturan perniagaan
4
📊
Alert & laporanNotifikasi untuk order risiko tinggi
import requests, json
from openai import OpenAI
API_ORDERS = "https://api.shopee.com/v2/orders"
client = OpenAI(base_url="http://192.168.1.50:8000/v1", api_key="none")
def fetch_cod_orders():
resp = requests.get(API_ORDERS, params={"payment": "cod"})
return resp.json().get("orders", [])
def assess_return_risk(order):
features = {
"amount": order["total"],
"history": order.get("return_count", 0),
"new_customer": order.get("order_count", 0) < 3
}
resp = client.chat.completions.create(
model="llama-3.1-8b",
messages=[{"role":"user","content":
f"Rate return risk (low/med/high): {json.dumps(features)}"}])
return resp.choices[0].message.content
for order in fetch_cod_orders():
risk = assess_return_risk(order)
if risk == "high":
requests.post("http://192.168.1.50:9000/alert",
json={"text": f"COD return risk: {order['id']}"})
print(json.dumps({"order": order["id"], "risk": risk}))