The rise of large language models (LLMs) has introduced a new type of programming: natural language programming. Users write prompts, which are instructions in natural language, to direct LLMs to perform tasks such as natural language processing, code generation, reasoning, etc. An emerging area of research enables interoperability between prompts and programs. We present a novel programming abstraction, shared program state, that removes the manual work required to enable interoperability between prompts and program states. With shared program state, programmers can write prompts that directly access program variables, compute with program objects, and implement control flow in the program. We present a schema for specifying natural function interfaces that extend programming systems to support programs with prompts and leverage this schema to specify shared program state as a natural function interface. We implement shared program state in the Nightjar programming system. Nightjar enables programmers to write Python programs containing prompts that share the Python program state. We show that Nightjar programs achieve comparable or higher task accuracy than manually written implementations (+4-19%), while decreasing the lines of code by 39.6% on average. The tradeoff is that Nightjar may incur runtime overhead (0.4-4.3x manual implementations).
翻译:大型语言模型(LLM)的兴起催生了一种新型编程范式:自然语言编程。用户通过编写自然语言指令形式的提示(prompts)来引导LLM执行自然语言处理、代码生成、推理等任务。一个新兴的研究领域致力于实现提示与程序之间的互操作性。本文提出一种新颖的编程抽象——共享程序状态,该抽象消除了实现提示与程序状态互操作性所需的手动工作。借助共享程序状态,程序员能够编写直接访问程序变量、使用程序对象进行计算并在程序中实现控制流的提示。我们提出一种用于规范自然函数接口的框架,该框架可扩展编程系统以支持包含提示的程序,并利用此框架将共享程序状态定义为一种自然函数接口。我们在Nightjar编程系统中实现了共享程序状态。Nightjar使程序员能够编写包含提示的Python程序,这些提示可共享Python程序状态。实验表明,Nightjar程序在任务准确率上达到甚至超过手动编写的实现(提升4-19%),同时平均减少39.6%的代码行数。其代价是Nightjar可能产生运行时开销(达到手动实现的0.4-4.3倍)。