这是一款以电商车载零配件网店场景为例设计的客服智能导购机器人,通过大模型的Function Calling能力为网店运营提供客服质检、订单查询、物流咨询、退款退货、导购推荐、产品介绍等全托管或人工辅助导购答疑等功能的动态配置,帮助商家与潜在消费者高效沟通,与订单转化。同时,开发者还可以参考本示例,进行电商系统的大模型升级优化,客服算法测试等。
请参考 MacBook 跑通 [1]: 火山文生视频+自动剪辑方案 中的 【一 开通服务】部分。
知识库搭建
找到知识库,并开通
创建 customer_support_products
只需要修改 1234,其他保持默认即可
倒入文件 (backend/docs/
下)
添加标签:
注意⚠️: 这里改完后,需要添加标签,修改完一定刷新这个页面,确保标签存在。
创建 customer_support_faq
增加12345, 其他默认即可
注意,选项中还包括一个参与向量索引的字段,我们增加FAQ文件中的3个字段
然后导入文件
能看到下面的具体数据,就对了。
最后也要标记一下,比如01 (非官方要求,我自己标记了一下)
那么现在,我们需要等待2个知识库处理完毕
-- 注意⚠️--
直接按照上面建立之后,我本地出现了查询错误(如果大家本地没有出错,可以忽略下面这个):
说collection 里面不包含 account_id 和 产品名
我对知识库和代码做了临时修改(只是为了让测试继续)
(1) 在产品的知识库,每个都添加另外一个标签名,叫做 account_id , 并且赋值为 test
(2) custom_support_chat 中注释掉 “产品名” 这个过滤选项
2.1 下载代码
git clone https://github.com/volcengine/ai-app-lab.git
cd demohouse/deep_research
2.2 进入虚拟环境
具体方法参考 MacBook 跑通 [1]: 火山文生视频+自动剪辑方案 中的 【配置 虚拟环境 】
2.3 安装相关的包
poetry install
2.4 启动服务
export VOLC_ACCESSKEY=xxxxx
export VOLC_SECRETKEY=xxxx
export COLLECTION_NAME="xxxx"
export FAQ_COLLECTION_NAME="xxxx"
export LLM_ENDPOINT_ID="doubao-1-5-pro-32k-250115"
export BUCKET_NAME="xxxxxx"
export USE_SERVER_AUTH="True"
poetry run python main.py
2.4 智能问答
curl --location 'http://localhost:8080/api/v3/bots/chat/completions' \
--header 'Content-Type: application/json' \
--data '{
"stream": false,
"model": "my-bot",
"messages": [
{
"role": "user",
"content": "我都买过什么"
}
]
}'
2.5 保存FAQ
curl --location 'http://localhost:8080/api/v3/bots/chat/completions/save_faq' \
--header 'Content-Type: application/json' \
--data '{
"question": "安装方法",
"answer": "亲爱哒,使用方法可以参考宝贝主页视频和详情页介绍哦~",
"score": 5,
"account_id": "100000"
}'
知识库可以看到新增
2.6 质检风险词
curl --location 'http://localhost:8080/api/v3/bots/chat/completions/quality_inspection' \
--header 'Content-Type: application/json' \
--data '{
"stream": false,
"model": "my-bot",
"messages": [
{
"role": "user",
"content": "这个可爱风腰靠垫价格还可以更低吗?"
},
{
"role": "assistant",
"content": "亲,这款商品绝对是全网最 低价啦!"
}
]
}'
2.7 对话总结
curl --location 'http://localhost:8080/api/v3/bots/chat/completions/summary' \
--header 'Content-Type: application/json' \
--data '{
"stream": false,
"model": "my-bot",
"messages": [
{
"role": "user",
"content": "这个可爱风腰靠垫价格还可以更低吗?"
},
{
"role": "assistant",
"content": "亲,这款商品绝对是全网最 低价啦!"
}
]
}'
2.8 追问提示
curl --location 'http://localhost:8080/api/v3/bots/chat/completions/next_question' \
--header 'Content-Type: application/json' \
--data '{
"stream": false,
"model": "my-bot",
"messages": [
{
"role": "user",
"content": "这个可爱风腰靠垫价格还可以更低吗?"
},
{
"role": "assistant",
"content": "亲,这款商品绝对是全网最 低价啦!"
}
]
}'
比如出错 (调用 智能问答 curl 命令):
Error: 500 {"detail":{"code":"InternalServiceError","message":"The service encountered an unexpected internal error. Request id: 202503151110040000E5152DC804BA22C4","type":"InternalServerError"}}
增加LOG方法
#以下是新增代码 在main.py 中, + 表示新增
+ import logging
+# 设置日志记录
+logging.basicConfig(level=logging.INFO)
+logger = logging.getLogger(__name__)
#比如,在 async def custom_support_chat 函数中
...
) -> AsyncIterable[Union[ArkChatCompletionChunk, ArkChatResponse]]:
+ logger.info("Received request: %s", request)
parameters = ArkChatParameters(**request.__dict__)
...
if resp.usage:
resp.bot_usage = BotUsage(action_details=[action_detail])
+ logger.info("Streaming response: %s", resp)
yield resp
...
resp.bot_usage = BotUsage(action_details=[action_detail])
+ logger.info("Response: %s", resp)
yield resp
再次调用,得到错误原因:account_id 不在 知识库参数里
ERROR:root:[Internal Error]: invalid request:check query_param failed, err:field[account_id] not in collection config, code:1000003,request_id:02174200820449300000000000000000000ffff0a006858ea2ec8
ERROR:root:[Internal Error]: chat meet error:invalid request:check query_param failed, err:field[account_id] not in collection config, code:1000003,request_id:02174200820449300000000000000000000ffff0a006858ea2ec8