Although Large Language Models (LLMs) have established pre-dominance in automated code generation, they are not devoid of shortcomings. The pertinent issues primarily relate to the absence of execution guarantees for generated code, a lack of explainability, and suboptimal support for essential but niche programming languages. State-of-the-art LLMs such as GPT-4 and LLaMa2 fail to produce valid programs for Industrial Control Systems (ICS) operated by Programmable Logic Controllers (PLCs). We propose LLM4PLC, a user-guided iterative pipeline leveraging user feedback and external verification tools including grammar checkers, compilers and SMV verifiers to guide the LLM's generation. We further enhance the generation potential of LLM by employing Prompt Engineering and model fine-tuning through the creation and usage of LoRAs. We validate this system using a FischerTechnik Manufacturing TestBed (MFTB), illustrating how LLMs can evolve from generating structurally flawed code to producing verifiably correct programs for industrial applications. We run a complete test suite on GPT-3.5, GPT-4, Code Llama-7B, a fine-tuned Code Llama-7B model, Code Llama-34B, and a fine-tuned Code Llama-34B model. The proposed pipeline improved the generation success rate from 47% to 72%, and the Survey-of-Experts code quality from 2.25/10 to 7.75/10. To promote open research, we share the complete experimental setup, the LLM Fine-Tuning Weights, and the video demonstrations of the different programs on our dedicated webpage.
翻译:尽管大语言模型(LLMs)在自动代码生成领域已占据主导地位,但仍存在固有缺陷。相关问题主要涉及生成代码缺乏执行保障、可解释性不足,以及对重要但非主流编程语言支持欠佳等。当前最先进的LLM(如GPT-4和LLaMa2)无法为可编程逻辑控制器(PLC)驱动的工业控制系统(ICS)生成有效程序。我们提出LLM4PLC系统,这是一个基于用户反馈的迭代流程,通过集成语法检查器、编译器和SMV验证器等外部验证工具引导LLM生成代码,并利用提示工程和基于LoRA的模型微调进一步优化生成能力。我们使用FischerTechnik制造测试平台(MFTB)对该系统进行验证,展示了LLM如何从生成结构缺陷代码演进为工业应用生成可验证的正确程序。我们针对GPT-3.5、GPT-4、Code Llama-7B(及其微调版本)、Code Llama-34B(及其微调版本)开展了完整测试。所提流程将代码生成成功率从47%提升至72%,专家代码质量评分从2.25/10提升至7.75/10。为促进开放研究,我们在专用网页共享了完整实验配置、LLM微调权重及不同程序的视频演示。