91 lines
2.5 KiB
Python
91 lines
2.5 KiB
Python
|
|
"""
|
|||
|
|
Coze 智能体 API 调用测试脚本
|
|||
|
|
运行前请确保已配置 .env 文件
|
|||
|
|
"""
|
|||
|
|
from coze_client import CozeClient
|
|||
|
|
|
|||
|
|
|
|||
|
|
def test_basic_chat():
|
|||
|
|
"""基础对话测试"""
|
|||
|
|
print("=" * 50)
|
|||
|
|
print("🤖 大沃智能助手 - API 调用测试")
|
|||
|
|
print("=" * 50)
|
|||
|
|
|
|||
|
|
try:
|
|||
|
|
client = CozeClient()
|
|||
|
|
except ValueError as e:
|
|||
|
|
print(f"\n❌ 初始化失败: {e}")
|
|||
|
|
print("请先配置 .env 文件(参考 .env.example)")
|
|||
|
|
return
|
|||
|
|
|
|||
|
|
# 测试用例
|
|||
|
|
test_messages = [
|
|||
|
|
{
|
|||
|
|
"message": "帮我写一段招商文案",
|
|||
|
|
"variables": {"zishu": "200字以内", "fengge": "专业正式"},
|
|||
|
|
"description": "测试招商Agent",
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"message": "早上好",
|
|||
|
|
"variables": {"zishu": "100字以内", "fengge": "轻松活泼"},
|
|||
|
|
"description": "测试问候Agent",
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"message": "介绍一下公司",
|
|||
|
|
"variables": {"zishu": "300字以内", "fengge": "专业正式"},
|
|||
|
|
"description": "测试公司介绍Agent",
|
|||
|
|
},
|
|||
|
|
]
|
|||
|
|
|
|||
|
|
for i, test in enumerate(test_messages, 1):
|
|||
|
|
print(f"\n--- 测试 {i}: {test['description']} ---")
|
|||
|
|
print(f"📝 输入: {test['message']}")
|
|||
|
|
print(f"⚙️ 参数: 字数={test['variables']['zishu']}, 风格={test['variables']['fengge']}")
|
|||
|
|
print("⏳ 等待回复中...")
|
|||
|
|
|
|||
|
|
reply = client.chat_and_poll(
|
|||
|
|
message=test["message"],
|
|||
|
|
custom_variables=test["variables"],
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
print(f"💬 回复:\n{reply}")
|
|||
|
|
print()
|
|||
|
|
|
|||
|
|
|
|||
|
|
def test_interactive():
|
|||
|
|
"""交互式对话测试"""
|
|||
|
|
print("=" * 50)
|
|||
|
|
print("🤖 大沃智能助手 - 交互模式")
|
|||
|
|
print("输入 'quit' 退出")
|
|||
|
|
print("=" * 50)
|
|||
|
|
|
|||
|
|
try:
|
|||
|
|
client = CozeClient()
|
|||
|
|
except ValueError as e:
|
|||
|
|
print(f"\n❌ 初始化失败: {e}")
|
|||
|
|
return
|
|||
|
|
|
|||
|
|
while True:
|
|||
|
|
user_input = input("\n你: ").strip()
|
|||
|
|
if user_input.lower() in ("quit", "exit", "q"):
|
|||
|
|
print("再见!")
|
|||
|
|
break
|
|||
|
|
if not user_input:
|
|||
|
|
continue
|
|||
|
|
|
|||
|
|
print("⏳ 思考中...")
|
|||
|
|
reply = client.chat_and_poll(
|
|||
|
|
message=user_input,
|
|||
|
|
custom_variables={"zishu": "200字以内", "fengge": "轻松活泼"},
|
|||
|
|
)
|
|||
|
|
print(f"\n助手: {reply}")
|
|||
|
|
|
|||
|
|
|
|||
|
|
if __name__ == "__main__":
|
|||
|
|
import sys
|
|||
|
|
|
|||
|
|
if len(sys.argv) > 1 and sys.argv[1] == "--interactive":
|
|||
|
|
test_interactive()
|
|||
|
|
else:
|
|||
|
|
test_basic_chat()
|