记忆功能
本页详细介绍了如何在 API 中使用 ChatSonic 的内存功能
ChatSonic 可以维护您的对话上下文,就像您与人交谈一样。它会记住您对话中过去的问题或评论,并可以轻松回答后续问题。
字段格式
以下是如何在 API 中使用 ChatSonic 的记忆功能
- 将字段设置为
enable_memory``true
- 按以下格式将以前的对话添加到
history_data
[{
"is_sent": bool,
"message": string
}]
- 该字段的目的是标记是用户提示还是 ChatSonic 响应
is_sent``message
- 设置为用于用户提示
is_sent``true
- 设置为ChatSonic 响应
is_sent``false
例子
让我们通过一个例子来尝试一下
步骤1
- 我们先来问问ChatSonic
Who is the President of the United States?
- 因为这是第一条消息,所以是一个空的对象数组
history_data
// REQUEST BODY
{
"enable_memory": true,
"enable_google_results": true,
"input_text": "Who is the President of the United States?",
"history_data": []
}
// RESPONSE BODY
{
"message": "The 46th and current President of the United States is Joseph R. Biden, Jr., who was sworn in on January 20, 2021.",
"image_urls": null
}
第2步
- 现在,我们来问一下
When was he born?
- 确保通过之前现场的提示和响应
history_data
is_sent
设置为用户提示true
is_sent
设置为 ChatSonic 响应false
// REQUEST BODY
{
"enable_memory": true,
"enable_google_results": true,
"input_text": "When was he born?",
"history_data": [
{
"is_sent": true,
"message": "Who is the President of the United States?"
},
{
"is_sent": false,
"message": "The 46th and current President of the United States is Joseph R. Biden, Jr., who was sworn in on January 20, 2021."
}
]
}
// RESPONSE BODY
{
"message": "Joseph Robinette Biden Jr. was born on November 20, 1942, in Scranton, Pennsylvania.",
"image_urls": null
}
步骤3
- 现在,我们来问一下
What is his favorite sports team?
- 确保通过之前现场的提示和响应
history_data
is_sent
设置为用户提示true
is_sent
设置为 ChatSonic 响应false
// REQUEST BODY
{
"enable_memory": true,
"enable_google_results": true,
"input_text": "What is his favorite sports team?",
"history_data": [
{
"is_sent": true,
"message": "Who is the President of the United States?"
},
{
"is_sent": false,
"message": "The 46th and current President of the United States is Joseph R. Biden, Jr., who was sworn in on January 20, 2021."
},
{
"is_sent": true,
"message": "When was he born?"
},
{
"is_sent": false,
"message": "Joseph Robinette Biden Jr. was born on November 20, 1942, in Scranton, Pennsylvania."
}
]
}
// RESPONSE BODY
{
"message": "Joe Biden is a Pennsylvania and Delaware native, and he roots for the Philadelphia Eagles. Biden was at Super Bowl LII cheering for his team with his family.",
"image_urls": null
}
最后修改时间: 10 个月前