# 测试示例 - 验证用户输入是否被正确使用 ## 如何测试 ### 方法 1: 通过 Web 界面测试 1. 启动应用: ```bash cd /Users/yufan_zhou/Documents/deeppersona/deeppersona-experience python app.py ``` 2. 在浏览器中打开 `http://localhost:7860` 3. 输入测试数据(例如): - **Age**: 28 - **Gender**: Male - **Occupation**: Data Scientist - **City**: San Francisco - **Country**: USA - **Personal Values**: (留空,测试自动生成) - **Life Attitude**: "Curious and analytical" - **Life Story**: (留空,测试自动生成) - **Interests and Hobbies**: "Machine learning, hiking" 4. 点击 "Generate Character Profile" 5. **检查控制台输出**,应该看到类似: ``` Found existing user_profile.json, using preset inputs... ✓ Using user-provided age: 28 ✓ Using user-provided gender: Male ✓ Using user-provided location: San Francisco, USA ✓ Using user-provided occupation: Data Scientist ✗ Personal values not provided, generated based on user inputs ✓ Using user-provided life attitude: Curious and analytical ✗ Life story not provided, generated based on user inputs ✓ Using user-provided interests: Machine learning, hiking ``` 6. **检查生成的 Profile**,应该包含: - 年龄 28 岁 - 性别 Male - 职业 Data Scientist - 地点 San Francisco, USA - 生活态度包含 "Curious and analytical" - 兴趣包含 "Machine learning" 和 "hiking" ### 方法 2: 通过命令行测试 1. 创建测试输入文件 `test_input.json`: ```json { "basic_info": { "age": 25, "gender": "Female", "occupation": { "status": "Software Engineer" }, "location": { "city": "Tokyo", "country": "Japan" } }, "custom_values": { "personal_values": "Values innovation and teamwork", "life_attitude": "", "life_story": "", "interests_hobbies": "Coding, anime, gaming" } } ``` 2. 运行测试: ```bash cd /Users/yufan_zhou/Documents/deeppersona/deeppersona-experience/generate_user_profile_final/code python web_api_bridge.py --input test_input.json --attributes 200 ``` 3. **检查输出**,应该显示: ``` ✓ Using user-provided age: 25 ✓ Using user-provided gender: Female ✓ Using user-provided location: Tokyo, Japan ✓ Using user-provided occupation: Software Engineer ✓ Using user-provided personal values: Values innovation and teamwork ✗ Life attitude not provided, generated based on user inputs ✗ Life story not provided, generated based on user inputs ✓ Using user-provided interests: Coding, anime, gaming ``` ## 验证要点 ### ✅ 正确行为 1. 用户输入的字段显示 `✓ Using user-provided ...` 2. 未输入的字段显示 `✗ ... not provided, generated ...` 3. 生成的 profile 包含所有用户输入的内容 4. 未输入的字段基于已输入内容合理生成(不是完全随机) ### ❌ 错误行为(如果看到这些,说明修复失败) 1. 所有字段都显示 `✗ ... not provided, generated ...`(说明用户输入被忽略) 2. 用户输入的年龄、性别等与生成的 profile 不匹配 3. 生成的内容与用户输入完全无关 ## 调试提示 如果测试失败,检查以下内容: 1. **检查 `user_profile.json` 是否正确保存**: ```bash cat /Users/yufan_zhou/Documents/deeppersona/deeppersona-experience/generate_user_profile_final/output/user_profile.json ``` 2. **检查控制台是否显示 "Found existing user_profile.json"**: - 如果没有,说明文件路径不对 - 如果显示 "No existing user_profile.json found",说明文件没有被保存 3. **检查是否有错误信息**: - 查看完整的 traceback - 检查是否有 JSON 解析错误 - 检查是否有字段类型不匹配的错误