通过 API 创建画像模板、提取画像并获取用户画像
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
通过 API 创建画像模板、提取画像并获取用户画像
DASHSCOPE_API_KEY 环境变量{workspaceId} 替换为真实的业务空间 ID;使用 Python SDK 时设置 MEMORY_SERVICE_ENDPOINT,详见服务地址# 1. 创建画像模板(CreateProfileSchema)
curl -X POST https://{workspaceId}.cn-beijing.maas.aliyuncs.com/api/v2/apps/memory/profile_schemas \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header "Content-Type: application/json" \
--data '{
"name": "用户基础画像",
"description": "包含年龄和兴趣的用户信息",
"attributes": [
{"name": "年龄", "description": "用户年龄"},
{"name": "爱好", "description": "用户的兴趣爱好"},
{"name": "职业", "description": "用户职业"}
]
}'
# 2. 添加对话并提取画像(AddMemory,传入上面返回的 profile_schema_id)
curl -X POST https://{workspaceId}.cn-beijing.maas.aliyuncs.com/api/v2/apps/memory/add \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header "Content-Type: application/json" \
--data '{
"user_id": "user_001",
"messages": [
{"role": "user", "content": "我今年28岁,是一名软件工程师。周末喜欢踢足球。"},
{"role": "assistant", "content": "很高兴认识你!"}
],
"profile_schema": "YOUR_SCHEMA_ID"
}'
# 3. 获取用户画像(GetUserProfile,等待3秒后执行)
curl -X GET "https://{workspaceId}.cn-beijing.maas.aliyuncs.com/api/v2/apps/memory/profile_schemas/{YOUR_SCHEMA_ID}/user_profile?user_id=user_001" \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header "Content-Type: application/json"