Extract Memory
基于 MemOS 自研抽取模型,从对话消息中直接抽取并返回事实与偏好记忆。
POST
import os
import requests
import json
# 替换成你的 API Key
os.environ["MEMOS_API_KEY"] = "YOUR_API_KEY"
os.environ["MEMOS_BASE_URL"] = "https://memos.memtensor.cn/api/openmem/v1"
data = {
"messages": [
{"role": "user", "content": "我暑假定好去广州旅游,住宿的话有哪些连锁酒店可选?"},
{"role": "assistant", "content": "您可以考虑【七天、全季、希尔顿】等等"},
{"role": "user", "content": "我选七天"},
{"role": "assistant", "content": "好的,有其他问题再问我。"}
],
"extraction_types": ["memory", "preference"]
}
headers = {
"Content-Type": "application/json",
"Authorization": f"Token {os.environ['MEMOS_API_KEY']}"
}
url = f"{os.environ['MEMOS_BASE_URL']}/extract/memory"
res = requests.post(url=url, headers=headers, data=json.dumps(data))
print(f"result: {res.json()}")
curl --request POST \
--url https://memos.memtensor.cn/api/openmem/v1/extract/memory \
--header 'Authorization: Token YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
"messages": [
{"role": "user", "content": "我暑假定好去广州旅游,住宿的话有哪些连锁酒店可选?"},
{"role": "assistant", "content": "您可以考虑【七天、全季、希尔顿】等等"},
{"role": "user", "content": "我选七天"},
{"role": "assistant", "content": "好的,有其他问题再问我。"}
],
"extraction_types": ["memory", "preference"]
}'
Authorizations
Authorization
string
header
required
Token API_key,可在 API 控制台>接口密钥 中查看
请求体
application/json
messages
ExtractMemoryMessage·object[]
required
需要抽取记忆的消息对象数组,数组中所有消息的总 Token 数上限为8k。
展示属性
extraction_types
string[]
限定抽取的记忆类型;不传则抽取全部支持的类型。
memory:事实记忆,从对话中提取用户相关的事实性信息。preference:偏好记忆,从对话中提取用户的偏好信息,包含显性偏好(用户明确表达)和隐性偏好(从行为推断)。
Enum:"memory""preference"
响应体
application/json
Successful Response
code
number
required
接口状态码,更多内容可查阅错误码列表了解详情。
Example: 0
data
object
展示属性
message
string
required
接口提示信息。
Example: "ok"
import os
import requests
import json
# 替换成你的 API Key
os.environ["MEMOS_API_KEY"] = "YOUR_API_KEY"
os.environ["MEMOS_BASE_URL"] = "https://memos.memtensor.cn/api/openmem/v1"
data = {
"messages": [
{"role": "user", "content": "我暑假定好去广州旅游,住宿的话有哪些连锁酒店可选?"},
{"role": "assistant", "content": "您可以考虑【七天、全季、希尔顿】等等"},
{"role": "user", "content": "我选七天"},
{"role": "assistant", "content": "好的,有其他问题再问我。"}
],
"extraction_types": ["memory", "preference"]
}
headers = {
"Content-Type": "application/json",
"Authorization": f"Token {os.environ['MEMOS_API_KEY']}"
}
url = f"{os.environ['MEMOS_BASE_URL']}/extract/memory"
res = requests.post(url=url, headers=headers, data=json.dumps(data))
print(f"result: {res.json()}")
curl --request POST \
--url https://memos.memtensor.cn/api/openmem/v1/extract/memory \
--header 'Authorization: Token YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
"messages": [
{"role": "user", "content": "我暑假定好去广州旅游,住宿的话有哪些连锁酒店可选?"},
{"role": "assistant", "content": "您可以考虑【七天、全季、希尔顿】等等"},
{"role": "user", "content": "我选七天"},
{"role": "assistant", "content": "好的,有其他问题再问我。"}
],
"extraction_types": ["memory", "preference"]
}'