RefleXGen:未经审视的代码不值得使用
RefleXGen:The unexamined code is not worth using
AI总结:
针对大语言模型代码生成的安全挑战,提出结合RAG与引导式自反思的RefleXGen方法,无需大量资源即可迭代优化代码安全性,在多个主流模型上实现了4.5%至13.6%的安全提升。
摘要:
在应用大语言模型(LLM)时,代码生成的安全性仍是一项核心挑战。本文提出RefleXGen,这是一种创新方法,通过将检索增强生成(RAG)技术与LLM内置的引导式自反思机制相结合,显著提升代码安全性。传统方法依赖于对LLM进行微调或构建专门的安全代码数据集,这类过程往往资源消耗巨大,而RefleXGen无需大量资源,通过自我评估与反思迭代优化代码生成流程。在该框架内,模型会持续积累并完善其知识库,从而逐步提升生成代码的安全性。实验结果表明,RefleXGen在多个模型上大幅提升了代码安全性:在GPT-3.5 Turbo上提升13.6%,在GPT-4o上提升6.7%,在CodeQwen上提升4.5%,在Gemini上提升5.8%。研究结果表明,提升模型自反思的质量是强化AI生成代码安全性的一种有效且实用的策略。
英文摘要:
Security in code generation remains a pivotal challenge when applying large language models (LLMs). This paper introduces RefleXGen, an innovative method that significantly enhances code security by integrating Retrieval-Augmented Generation (RAG) techniques with guided self-reflection mechanisms inherent in LLMs. Unlike traditional approaches that rely on fine-tuning LLMs or developing specialized secure code datasets - processes that can be resource-intensive - RefleXGen iteratively optimizes the code generation process through self-assessment and reflection without the need for extensive resources. Within this framework, the model continuously accumulates and refines its knowledge base, thereby progressively improving the security of the generated code. Experimental results demonstrate that RefleXGen substantially enhances code security across multiple models, achieving a 13.6% improvement with GPT-3.5 Turbo, a 6.7% improvement with GPT-4o, a 4.5% improvement with CodeQwen, and a 5.8% improvement with Gemini. Our findings highlight that improving the quality of model self-reflection constitutes an effective and practical strategy for strengthening the security of AI-generated code.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。