245 lines
9.9 KiB
Python
245 lines
9.9 KiB
Python
"""向知识库上传示例保险产品文档。"""
|
||
import requests
|
||
import base64
|
||
import json
|
||
import sys
|
||
import time
|
||
|
||
# ============ 保险产品数据 ============
|
||
PRODUCTS = [
|
||
{
|
||
"name": "康乐一生重疾险",
|
||
"company": "复星联合健康",
|
||
"type": "重疾险",
|
||
"coverage": ["30万", "50万", "100万"],
|
||
"premium": {"30岁男": "4500元/年", "30岁女": "4200元/年", "35岁男": "5800元/年", "35岁女": "5400元/年"},
|
||
"coverage_period": "终身",
|
||
"waiting_period": "90天",
|
||
"diseases": "110种重疾 + 25种中症 + 50种轻症",
|
||
"features": "重疾不分组赔付3次,中症赔付60%保额,轻症赔付30%保额,自带被保人豁免",
|
||
"age_range": "0-55岁",
|
||
},
|
||
{
|
||
"name": "达尔文6号重疾险",
|
||
"company": "国富人寿",
|
||
"type": "重疾险",
|
||
"coverage": ["30万", "40万", "50万"],
|
||
"premium": {"30岁男": "5200元/年", "30岁女": "4800元/年", "35岁男": "6800元/年", "35岁女": "6300元/年"},
|
||
"coverage_period": "终身",
|
||
"waiting_period": "180天",
|
||
"diseases": "110种重疾 + 25种中症 + 50种轻症",
|
||
"features": "60岁前首次重疾额外赔付80%保额,癌症二次赔付间隔期3年",
|
||
"age_range": "0-55岁",
|
||
},
|
||
{
|
||
"name": "超级玛丽7号重疾险",
|
||
"company": "和泰人寿",
|
||
"type": "重疾险",
|
||
"coverage": ["30万", "50万", "60万"],
|
||
"premium": {"30岁男": "5500元/年", "30岁女": "5100元/年", "35岁男": "7200元/年", "35岁女": "6700元/年"},
|
||
"coverage_period": "终身",
|
||
"waiting_period": "180天",
|
||
"diseases": "110种重疾 + 25种中症 + 55种轻症",
|
||
"features": "癌症二次赔付间隔期仅1年,赔付比例120%保额,心脑血管二次赔付",
|
||
"age_range": "0-55岁",
|
||
},
|
||
{
|
||
"name": "e享护-医享无忧百万医疗险",
|
||
"company": "太平洋健康",
|
||
"type": "医疗险",
|
||
"coverage": ["400万"],
|
||
"premium": {"30岁男": "268元/年", "30岁女": "288元/年", "35岁男": "358元/年", "35岁女": "388元/年"},
|
||
"coverage_period": "1年(保证续保20年)",
|
||
"waiting_period": "30天",
|
||
"diseases": "住院医疗、特殊门诊、门诊手术、住院前后门急诊",
|
||
"features": "保证续保20年,涵盖外购药、质子重离子治疗,100%报销",
|
||
"age_range": "0-65岁",
|
||
"deductible": "1万元",
|
||
},
|
||
{
|
||
"name": "蓝医保长期医疗险",
|
||
"company": "太平洋健康",
|
||
"type": "医疗险",
|
||
"coverage": ["400万"],
|
||
"premium": {"30岁男": "298元/年", "30岁女": "318元/年", "35岁男": "398元/年", "35岁女": "428元/年"},
|
||
"coverage_period": "1年(保证续保20年)",
|
||
"waiting_period": "30天",
|
||
"diseases": "住院医疗、特殊门诊、门诊手术、住院前后门急诊、重疾住院津贴",
|
||
"features": "保证续保20年,重疾0免赔,涵盖外购药、质子重离子,含重疾住院津贴100元/天",
|
||
"age_range": "0-65岁",
|
||
"deductible": "1万元(重疾0免赔)",
|
||
},
|
||
{
|
||
"name": "平安e生保长期医疗险",
|
||
"company": "平安健康",
|
||
"type": "医疗险",
|
||
"coverage": ["200万", "400万"],
|
||
"premium": {"30岁男": "320元/年", "30岁女": "340元/年", "35岁男": "420元/年", "35岁女": "450元/年"},
|
||
"coverage_period": "1年(保证续保20年)",
|
||
"waiting_period": "30天",
|
||
"diseases": "住院医疗、特殊门诊、门诊手术、住院前后门急诊",
|
||
"features": "保证续保20年,平安品牌,服务体系完善,支持垫付医疗费",
|
||
"age_range": "0-65岁",
|
||
"deductible": "1万元",
|
||
},
|
||
{
|
||
"name": "小蜜蜂3号意外险",
|
||
"company": "鼎和保险",
|
||
"type": "意外险",
|
||
"coverage": ["50万", "100万"],
|
||
"premium": {"30岁男": "158元/年", "30岁女": "158元/年", "35岁男": "158元/年", "35岁女": "158元/年"},
|
||
"coverage_period": "1年",
|
||
"waiting_period": "无",
|
||
"diseases": "意外身故/伤残、意外医疗、意外住院津贴、猝死保障",
|
||
"features": "含猝死保障50万,意外医疗0免赔100%报销,不限社保",
|
||
"age_range": "18-60岁",
|
||
},
|
||
{
|
||
"name": "大护甲5号意外险",
|
||
"company": "人保财险",
|
||
"type": "意外险",
|
||
"coverage": ["50万", "100万"],
|
||
"premium": {"30岁男": "168元/年", "30岁女": "168元/年", "35岁男": "168元/年", "35岁女": "168元/年"},
|
||
"coverage_period": "1年",
|
||
"waiting_period": "无",
|
||
"diseases": "意外身故/伤残、意外医疗、意外住院津贴、交通意外额外赔付",
|
||
"features": "交通意外额外赔付,意外医疗0免赔,不限社保,含住院津贴150元/天",
|
||
"age_range": "18-60岁",
|
||
},
|
||
{
|
||
"name": "华贵大麦2024定期寿险",
|
||
"company": "华贵人寿",
|
||
"type": "寿险",
|
||
"coverage": ["50万", "100万", "200万"],
|
||
"premium": {"30岁男": "590元/年", "30岁女": "310元/年", "35岁男": "810元/年", "35岁女": "450元/年"},
|
||
"coverage_period": "20年/30年/至60岁/至65岁/至70岁",
|
||
"waiting_period": "90天",
|
||
"diseases": "身故/全残保障",
|
||
"features": "免责条款仅3条,健康告知宽松,最高可投保300万,支持减保",
|
||
"age_range": "18-60岁",
|
||
},
|
||
{
|
||
"name": "擎天柱9号定期寿险",
|
||
"company": "横琴人寿",
|
||
"type": "寿险",
|
||
"coverage": ["50万", "100万", "300万"],
|
||
"premium": {"30岁男": "620元/年", "30岁女": "330元/年", "35岁男": "850元/年", "35岁女": "480元/年"},
|
||
"coverage_period": "20年/30年/至60岁/至65岁/至70岁",
|
||
"waiting_period": "90天",
|
||
"diseases": "身故/全残保障,可选猝死额外赔付",
|
||
"features": "可选猝死额外赔付50%保额,健康告知宽松,支持月缴",
|
||
"age_range": "18-60岁",
|
||
},
|
||
{
|
||
"name": "增多多3号增额终身寿险",
|
||
"company": "弘康人寿",
|
||
"type": "储蓄险",
|
||
"coverage": ["按保费确定保额"],
|
||
"premium": {"趸交": "10万起", "3年交": "3万/年起", "5年交": "2万/年起", "10年交": "1万/年起"},
|
||
"coverage_period": "终身",
|
||
"waiting_period": "无",
|
||
"diseases": "身故/全残保障",
|
||
"features": "保额每年递增3.5%,现金价值高,支持减保取现,可作为养老储备",
|
||
"age_range": "0-70岁",
|
||
},
|
||
{
|
||
"name": "年金险-如意享",
|
||
"company": "信泰人寿",
|
||
"type": "年金险",
|
||
"coverage": ["按缴费确定"],
|
||
"premium": {"趸交": "5万起", "3年交": "2万/年起", "5年交": "1万/年起", "10年交": "5000元/年起"},
|
||
"coverage_period": "终身",
|
||
"waiting_period": "无",
|
||
"diseases": "身故保障 + 年金领取",
|
||
"features": "55岁/60岁/65岁开始领取年金,保证领取20年,活多久领多久,可附加万能账户",
|
||
"age_range": "0-60岁",
|
||
},
|
||
]
|
||
|
||
|
||
def build_document(product: dict) -> str:
|
||
"""将产品信息转为文档文本。"""
|
||
lines = [
|
||
f"# {product['name']}",
|
||
f"",
|
||
f"## 基本信息",
|
||
f"- 产品名称:{product['name']}",
|
||
f"- 所属保险公司:{product['company']}",
|
||
f"- 险种类型:{product['type']}",
|
||
f"- 投保年龄:{product['age_range']}",
|
||
f"- 保障期限:{product['coverage_period']}",
|
||
f"- 等待期:{product['waiting_period']}",
|
||
f"",
|
||
f"## 保额选择",
|
||
f"可选保额:{'、'.join(product['coverage'])}",
|
||
f"",
|
||
f"## 费率表",
|
||
]
|
||
for age, premium in product['premium'].items():
|
||
lines.append(f"- {age}:{premium}")
|
||
lines.extend([
|
||
f"",
|
||
f"## 保障内容",
|
||
f"- 保障范围:{product['diseases']}",
|
||
f"",
|
||
f"## 产品特色",
|
||
f"{product['features']}",
|
||
])
|
||
if 'deductible' in product:
|
||
lines.extend([f"", f"## 免赔额", f"{product['deductible']}"])
|
||
return "\n".join(lines)
|
||
|
||
|
||
def main():
|
||
session = requests.Session()
|
||
|
||
# Login
|
||
password_b64 = base64.b64encode('taiyi1224'.encode()).decode()
|
||
resp = session.post('http://localhost:5001/console/api/login', json={
|
||
'email': 'taiyi@baodan.com',
|
||
'password': password_b64
|
||
})
|
||
if resp.status_code != 200:
|
||
sys.stdout.buffer.write(f'Login failed: {resp.status_code}\n'.encode('utf-8'))
|
||
return
|
||
csrf_token = session.cookies.get('csrf_token')
|
||
sys.stdout.buffer.write(b'Login OK\n')
|
||
|
||
DATASET_ID = 'ec920b75-758a-4fa1-9132-22cb5e22126e'
|
||
|
||
# Build documents
|
||
docs = []
|
||
for p in PRODUCTS:
|
||
docs.append({
|
||
"name": f"{p['name']}({p['company']})",
|
||
"text": build_document(p),
|
||
})
|
||
|
||
# Upload as one batch via create_by_text
|
||
# Dify API: POST /console/api/datasets/{dataset_id}/documents/create-by-text
|
||
for doc in docs:
|
||
resp = session.post(
|
||
f'http://localhost:5001/console/api/datasets/{DATASET_ID}/document/create-by-text',
|
||
json={
|
||
"name": doc["name"],
|
||
"text": doc["text"],
|
||
"indexing_technique": "high_quality",
|
||
"process_rule": {
|
||
"mode": "automatic",
|
||
},
|
||
},
|
||
headers={'X-CSRF-Token': csrf_token},
|
||
)
|
||
status = resp.status_code
|
||
if status in (200, 201):
|
||
sys.stdout.buffer.write(f" ✓ {doc['name']} uploaded\n".encode('utf-8'))
|
||
else:
|
||
sys.stdout.buffer.write(f" ✗ {doc['name']} failed ({status}): {resp.text[:200]}\n".encode('utf-8'))
|
||
time.sleep(0.5) # rate limit
|
||
|
||
sys.stdout.buffer.write(b'\nDone!\n')
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main()
|