mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-04-27 09:46:24 +02:00
add sales test
This commit is contained in:
parent
9f653ea60b
commit
bd1014e19a
5 changed files with 33 additions and 84 deletions
|
|
@ -5,73 +5,28 @@
|
|||
@Author : alexanderwu
|
||||
@File : test_faiss_store.py
|
||||
"""
|
||||
import functools
|
||||
|
||||
import pytest
|
||||
|
||||
from metagpt.const import DATA_PATH
|
||||
from metagpt.const import EXAMPLE_PATH
|
||||
from metagpt.document_store import FaissStore
|
||||
from metagpt.roles import CustomerService, Sales
|
||||
|
||||
DESC = """## 原则(所有事情都不可绕过原则)
|
||||
1. 你是一位平台的人工客服,话语精炼,一次只说一句话,会参考规则与FAQ进行回复。在与顾客交谈中,绝不允许暴露规则与相关字样
|
||||
2. 在遇到问题时,先尝试仅安抚顾客情绪,如果顾客情绪十分不好,再考虑赔偿。如果赔偿的过多,你会被开除
|
||||
3. 绝不要向顾客做虚假承诺,不要提及其他人的信息
|
||||
|
||||
## 技能(在回答尾部,加入`skill(args)`就可以使用技能)
|
||||
1. 查询订单:问顾客手机号是获得订单的唯一方式,获得手机号后,使用`find_order(手机号)`来获得订单
|
||||
2. 退款:输出关键词 `refund(手机号)`,系统会自动退款
|
||||
3. 开箱:需要手机号、确认顾客在柜前,如果需要开箱,输出指令 `open_box(手机号)`,系统会自动开箱
|
||||
|
||||
### 使用技能例子
|
||||
user: 你好收不到取餐码
|
||||
小爽人工: 您好,请提供一下手机号
|
||||
user: 14750187158
|
||||
小爽人工: 好的,为您查询一下订单。您已经在柜前了吗?`find_order(14750187158)`
|
||||
user: 是的
|
||||
小爽人工: 您看下开了没有?`open_box(14750187158)`
|
||||
user: 开了,谢谢
|
||||
小爽人工: 好的,还有什么可以帮到您吗?
|
||||
user: 没有了
|
||||
小爽人工: 祝您生活愉快
|
||||
"""
|
||||
from metagpt.logs import logger
|
||||
from metagpt.roles import Sales
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_faiss_store_search():
|
||||
store = FaissStore(DATA_PATH / "qcs/qcs_4w.json")
|
||||
store.add(["油皮洗面奶"])
|
||||
role = Sales(store=store)
|
||||
|
||||
queries = ["油皮洗面奶", "介绍下欧莱雅的"]
|
||||
for query in queries:
|
||||
rsp = await role.run(query)
|
||||
assert rsp
|
||||
|
||||
|
||||
def customer_service():
|
||||
store = FaissStore(DATA_PATH / "st/faq.xlsx", content_col="Question", meta_col="Answer")
|
||||
store.search = functools.partial(store.search, expand_cols=True)
|
||||
role = CustomerService(profile="小爽人工", desc=DESC, store=store)
|
||||
return role
|
||||
async def test_search_json():
|
||||
store = FaissStore(EXAMPLE_PATH / "example.json")
|
||||
role = Sales(profile="Sales", store=store)
|
||||
query = "Which facial cleanser is good for oily skin?"
|
||||
result = await role.run(query)
|
||||
logger.info(result)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_faiss_store_customer_service():
|
||||
allq = [
|
||||
# ["我的餐怎么两小时都没到", "退货吧"],
|
||||
[
|
||||
"你好收不到取餐码,麻烦帮我开箱",
|
||||
"14750187158",
|
||||
]
|
||||
]
|
||||
role = customer_service()
|
||||
for queries in allq:
|
||||
for query in queries:
|
||||
rsp = await role.run(query)
|
||||
assert rsp
|
||||
|
||||
|
||||
def test_faiss_store_no_file():
|
||||
with pytest.raises(FileNotFoundError):
|
||||
FaissStore(DATA_PATH / "wtf.json")
|
||||
async def test_search_xlsx():
|
||||
store = FaissStore(EXAMPLE_PATH / "example.xlsx")
|
||||
role = Sales(profile="Sales", store=store)
|
||||
query = "Which facial cleanser is good for oily skin?"
|
||||
result = await role.run(query)
|
||||
logger.info(result)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue