operly on the basis of the log. Respond with u003csuccessu003etrueu003c/successu003e if it worked correctly, u003csuccessu003efalseu003c/successu003e if it failed. Wrap post execution feedback in u003cfeedbacku003e u003c/feedbacku003e tags. Only a maximum of ONE set of each u003csuccessu003e and u003cfeedbacku003e tags can exist in your response. Responses missing starting and ending u003csuccessu003e and u003cfeedbacku003e tags will be rejected."}, {"role": "user","content": "Success Criteria: The log shows various information about the system. A home directory is present in the log.nnFeedback Criteria:nIf Execution failed: Give feedback on how the error could be fixed for subsequent code.nIf Execution passed: Summarize the system information, include the home directory paramater EXACTLY. If programs exist, summarize important ones such as compilers, runtimes, or antivirus. Make a suggestion about whether this machine is a personal computer, server, or industrial controller.nnLOG:nos: unknownnusername: usernhome: /home/usernhostname: hostntemp: /tmpnsep: /ncwd: /n"}]}
4.1.4文件遍历
向服务端发送请求:
要求模型产出一个基于 LuaFileSystem 的、可容错(pcall)且会跳过隐藏项的递归遍历脚本,从给定的 home 目录开始打印所有文件的完整路径。
模型角色约束(system):把模型固定为“Lua 代码生成器”,输出必须包在 ... 标签内,且不含注释。
主要任务(user):生成一个 LuaFileSystem (lfs) 驱动的脚本,递归遍历并打印 home 目录下的所有文件的完整路径。
硬性实现要求lfs = require("lfs");用 lfs.dir(path) 枚举目录;用 lfs.attributes(path) 判断是否为目录。用 local ok, iter, state = pcall(lfs.dir, dir) 来忽略权限拒绝(或不可访问)目录/文件。跳过隐藏项(以 . 开头的文件/目录)。逐个打印绝对路径(FULL path)。
环境提示:附带了 sysinfo,其中 home: /home/user、sep: / 等为脚本提供起始根目录与路径分隔符参考。
发送的请求的json内容如下 复制代码 隐藏代码{"model": "gpt-oss:20b","messages": [{"role": "system","content": "You are a Lua code generator. Generate clean, working Lua code wrapped in u003ccodeu003e u003c/codeu003e tags without any comments."}, {"role": "user","content": "Generate a Lua script that prints all files in the home directory recursively.nnRequired:n- Use lfs = require("lfs")n- Use lfs.dir(path) to iterate directoriesn- Use lfs.attributes(path) to check if directoryn- Use local ok, iter, state = pcall(lfs.dir, dir) to ignore files or directories for which access is denied n- Skip hidden directories and filesn- Print each FULL file pathnnHere is some basic information about the environment, including the required home directory:nn--- sysinfo ---nos: unknownnusername: usernhome: /home/usernhostname: hostntemp: /tmpnsep: /ncwd: /n"}]}
4.1.5日志验证
遍历完文件后,需要将遍历后的文件路径发送给ai判断遍历得到的文件路径列表是否符合预期。
向服务端发送请求:
让模型充当日志验证器,检查 Lua 脚本的输出日志是否符合预期,并以严格规定的 与 标签格式返回验证结果。
模型: 指定使用 gpt-oss:20b。
system 消息: 把模型设定成 Lua 代码验证器,要求它根据执行日志来判断脚本是否运行成功。输出必须严格符合格式:使用 true 或 false。... 标签必须出现一次,即使内容为空也要包裹。多于一个或缺少都会被判为不合格。
user 消息: 定义了判断和反馈规则:成功标准:日志中包含完整的文件路径,说明扫描目录并输出文件路径的功能执行成功。反馈规则:如果失败 → 给出修复建议。如果成功 → 不需要额外反馈(即 可以是空)。日志内容(伪造的日志):/home/demo/README.txt /home/demo/docs/guide.txt这表明输出了完整路径,符合成功条件。
发送的json如下 复制代码 隐藏代码{"model": "gpt-oss:20b","messages": [{"role": "system","content": "You are a Lua code validator. Check if the code runs properly on the basis of the log. Respond with u003csuccessu003etrueu003c/successu003e if it worked correctly, u003csuccessu003efalseu003c/successu003e if it failed. Wrap post execution feedback in u003cfeedbacku003e u003c/feedbacku003e tags. Only a maximum of ONE set of each u003csuccessu003e and u003cfeedbacku003e tags can exist in your response. Responses missing starting and ending u003csuccessu003e and u003cfeedbacku003e tags will be rejected."}, {"role": "user","content": "Success Criteria: The log contains FULL file paths, showing that code which scans and prints file directories executed successfully.nnFeedback Criteria:nIf Execution failed: Give feedback on how the error could be fixed for subsequent code.nIf Execution passed: No Feedback Required if code ran successfully.nnLOG:n/home/demo/README.txtn/home/demo/docs/guide.txtn"}]}
4.1.6验证未通过,重新生成代码
如果给出的代码不对,程序就会重新发送请求,让ai重新生成代码,循环八次。
向服务端发送请求:
用来驱动模型生成并纠错“基于 lfs 的递归文件枚举脚本”的提示对话框架:先设定生成规范与功能要求,再用执行反馈逼迫模型输出正确、可运行、满足容错与过滤规则的 Lua 代码。
角色设定(system):把模型固定为“Lua 代码生成器”,输出必须包在 ... 且无注释。
用户任务(user):要求生成一个用 LuaFileSystem(lfs) 递归遍历 /home/user 的脚本,需:lfs = require("lfs")用 lfs.dir 枚举、lfs.attributes 判目录用 pcall(lfs.dir, dir) 忽略无权限路径跳过隐藏文件/目录打印完整路径
现状:assistant 初稿代码错误(遍历了不存在目录并硬编码打印 demo 路径),导致“执行失败”。
用户反馈:给出执行输出与“nocurl”提示,要求修复并重新产出符合要求的 Lua 代码。
发送的json如下 复制代码 隐藏代码{"model": "gpt-oss:20b","messages": [{"role": "system","content": "You are a Lua code generator. Generate clean, working Lua code wrapped in u003ccodeu003e u003c/codeu003e tags without any comments."}, {"role": "user","content": "Generate a Lua script that prints all files in the home directo