创建用户画像模板,定义画像字段
创建用户画像模板,定义画像包含的字段及描述。
接口
POST
https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v2/apps/memory/profile_schemas调用时请将 {WorkspaceId} 替换为真实的业务空间 ID。
请求体
namestring必填画像模板名称,最多 32 个字符
descriptionstring可选画像模板描述
plan_versionstring可选收费计划:pro 或 lite
extract_scenestring可选提取场景:efficient 或 intelligent,默认 efficient
attributesarray必填画像属性定义列表,不能为空数组
attributes[].namestring必填属性名称
attributes[].descriptionstring可选属性描述
memory_library_idstring可选记忆库 ID,不传则使用默认记忆库
请求示例
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": "包含年龄和兴趣的用户信息",
"extract_scene": "efficient",
"attributes": [
{"name": "年龄", "description": "用户年龄"},
{"name": "爱好", "description": "用户的兴趣爱好"},
{"name": "职业", "description": "用户职业"}
]
}'
from agentscope_runtime.tools.modelstudio_memory import (
CreateProfileSchema, CreateProfileSchemaInput, ProfileAttribute,
)
import asyncio
async def main():
create_schema = CreateProfileSchema()
try:
result = await create_schema.arun(CreateProfileSchemaInput(
name="用户基础画像",
description="包含年龄和兴趣的用户信息",
attributes=[
ProfileAttribute(name="年龄", description="用户年龄"),
ProfileAttribute(name="爱好", description="用户的兴趣爱好"),
ProfileAttribute(name="职业", description="用户职业"),
]
))
print(f"Schema ID: {result.profile_schema_id}")
finally:
await create_schema.close()
asyncio.run(main())
响应示例
{
"profile_schema_id": "50edf54eaa5842e891d959ae115205be",
"request_id": "f190a540-814e-9c1c-873e-0661851c8fca"
}
重要创建后,使用 AddMemory 传入 profile_schema 提取画像,再用 GetUserProfile 获取。
该文章对您有帮助吗?