arXiv:2501.02138cs.PLcs.AI2025-01被引 4

用自然语言和测试规范生成可靠代码,降低AI编程风险

Effective LLM-Driven Code Generation with Pythoness

  • 以测试和自然语言描述为输入,生成可验证的代码
  • 结合测试与生成代码,产出质量优于单一规范的结果
  • 适合希望提升生成代码可靠性、避免调试陷阱的开发者

大型语言模型(LLMs)为编程工具带来新可能,但生成代码缺乏正确性保障。开发者面临优化、集成与维护AI生成代码的难题。我们提出嵌入式领域特定语言Pythoness,使开发者在更高抽象层级使用LLMs编程。无需直接操作生成代码,开发者通过行为规范(如单元测试、属性测试)定义函数、类或程序,这些规范可用形式化语言或自然语言表达。Pythoness基于规范生成通过测试的代码,并支持运行时持续检查。实验表明,结合测试与代码生成可显著提升代码质量,优于仅依赖规范的方式。本研究展示了原型实现并验证了该方法的有效性。

原文摘要 · Abstract (English)

The advent of large language models (LLMs) has paved the way for a new era of programming tools with both significant capabilities and risks, as the generated code lacks guarantees of correctness and reliability. Developers using LLMs currently face the difficult task of optimizing, integrating, and maintaining code generated by AI. We propose an embedded domain-specific language (DSL), Pythoness, to address those challenges. In Pythoness, developers program with LLMs at a higher level of abstraction. Rather than interacting directly with generated code, developers using Pythoness operate at the level of behavioral specifications when writing functions, classes, or an entire program. These specifications can take the form of unit tests and property-based tests, which may be expressed formally or in natural language. Guided by these specifications, Pythoness generates code that both passes the tests and can be continuously checked during execution. We posit that the Pythoness approach lets developers harness the full potential of LLMs for code generation while substantially mitigating their inherent risks. We describe our current prototype implementation of Pythoness and demonstrate that it can successfully leverage a combination of tests and code generation to yield higher quality code than specifications alone.

代码生成LLM应用测试驱动

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。