arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2511.13972cs.SEcs.CL
收藏

展示与说明:多轮大语言模型代码生成中用于风格控制的提示策略

Show and Tell: Prompt Strategies for Style Control in Multi-Turn LLM Code Generation

Jeremiah Bohr

AI总结:

针对多轮LLM代码生成中的风格控制问题,本研究对比三类提示策略在两轮代码生成-增强流程中的表现,发现指令与示例结合的提示可实现最稳定的风格控制效果。

摘要:

大语言模型生成的功能正确代码往往过于冗长,包含繁杂的文档说明和防御性编程模式,与人类编写的基准代码存在差异。目前已有两类用于风格控制的提示机制:一是基于指令的提示,用于表述抽象的规则要求;二是基于示例的提示,用于提供具体的代码演示。核心研究问题是,当模型在保持高功能准确率的前提下为初始实现添加额外功能时,风格约束是否仍然有效。本研究发现,在一轮功能增强的交互过程中,基于指令的提示、基于示例的提示以及二者结合的提示,会在初始风格控制和扩展规范性上表现出不同的模式。我们采用配对的两轮交互协议,设置四种系统提示条件开展实验:模型首先针对中等难度的Python任务生成解决方案,随后在通用改进指令下修订代码,用户任务保持固定,共收集160组配对程序。实验结果显示,组合提示实现了最强的初始代码压缩效果和最佳的扩展规范性;指令类提示初始效果显著,但扩展规范性一般;示例类提示初始效果有限,且不具备扩展规范性。这些结果表明,提示的初始效果与扩展规范性是提示设计中相互独立的两个维度,组合方法在该两轮工作流中可提供最稳定的风格控制能力。

英文摘要:

Language models generate functionally correct code that tends toward excessive verbosity, with elaborate documentation and defensive patterns that diverge from human baselines. Two prompting mechanisms have emerged for stylistic control: instruction based prompts that articulate abstract directives, and example based prompts that provide concrete code demonstrations. The core problem is whether stylistic constraints persist when models enhance initial implementations with additional features while maintaining high functional accuracy. Here we show that instruction-based, example-based, and combined prompts produce distinct patterns of initial control and expansion discipline over one enhancement turn. We manipulated system prompts across four conditions in a paired two-turn protocol where models first generated solutions to an intermediate Python task, then revised their code under general improvement directives, holding the user task fixed (N = 160 paired programs). Combined prompts produced the strongest initial compression and greatest expansion discipline. Instructions showed large initial effects and moderate expansion discipline. Examples showed modest initial effects with no expansion discipline. These results show that initial prompt effectiveness and expansion discipline are separate aspects of prompt design, and that combined approaches provide the most stable stylistic control in this two-turn workflow.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑