Dify自动测试:将问题excel给到大模型,批量输出批改
大模型查询数据库每次调优后,要进行测试浪费时间,所以使用dify搭建了一个上传excel的若干问题,大模型帮你判定是否正确。
·
功能说明:大模型查询数据库每次调优后,要进行测试浪费时间,所以使用dify搭建了一个上传excel的若干问题,大模型帮你判定是否正确。
为啥写代码:应该有更专业的软件Langfuse,但是还没有分析明白,不会使用。先解决问题,在逐渐精进吧
解决办法:使用deepseek编写处理程序
发文原因:解决使用dify搭建自动化测试的方案
踩坑日志:
1. dify的回复如何换行?答:回车(该怎么换行就怎么换行)
2. dify的迭代模块,仅允许一个变量输入,怎么办?答:在迭代循环中写python找到你想要的变量值

使用python把excel数据改成数组
def main(arg1: str) -> dict:
result = {
"_id": [], # 字符串列表
"question": [], # 字符串列表
"answer": [] # 保持数值类型
}
# 类型预处理
input_str = '\n'.join(arg1) if isinstance(arg1, list) else arg1
for line in input_str.split('\n'):
line = line.strip()
if not line or line.startswith('|---'):
continue
cols = [c.strip() for c in line.split('|') if c.strip()]
if len(cols) != 3:
continue
try:
# 明确类型转换
result["_id"].append(str(cols[0])) # → 强制转为字符串
result["question"].append(str(cols[1])) # → 强制转为字符串
result["answer"].append(str(cols[2])) # → 保持数值类型
except ValueError:
continue
return result

输出内容标准化
def main(index, question, answer):
# 类型安全转换
try:
idx = int(index)
except (ValueError, TypeError):
raise ValueError(f"索引必须为数字,当前值: {repr(index)}")
# 类型校验
if not isinstance(question, list):
raise TypeError(f"question 必须是列表类型,当前类型: {type(question).__name__}")
if not isinstance(answer, list):
raise TypeError(f"answer 必须是列表类型,当前类型: {type(answer).__name__}")
# 空数组诊断
error_msgs = []
if len(question) == 0:
error_msgs.append("question 数组为空")
if len(answer) == 0:
error_msgs.append("answer 数组为空")
if error_msgs:
raise ValueError(" | ".join(error_msgs))
# 智能取最小有效长度
valid_length = min(len(question), len(answer))
# 索引边界检查
if idx < 0 or idx >= valid_length:
raise IndexError(f"索引 {idx} 越界 (有效范围: 0-{valid_length-1})")
return {
'iindex': idx,
'question': question[idx],
'answer': answer[idx]
}


魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐

所有评论(0)