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

通过检索增强生成和约束解码减轻大语言模型生成的Web API调用中的错误

Mitigating Errors in LLM-Generated Web API Invocations via Retrieval-Augmented Generation and Constrained Decoding

Technische Universität Darmstadt(德累斯顿技术大学);Hessian Center for Artificial Intelligence (hessian.AI)(黑森人工智能中心);Pariton AI;National Research Center for Applied Cybersecurity ATHENE(应用网络安全国家研究中心ATHENE)

Daniel Maninger, Leon Chemnitz, Jannis Brugger, Tushar Lamba, Amir Molzam Sharifloo, Mira Mezini

AI总结:

研究如何减轻大语言模型生成的Web API调用错误,提出检索增强生成(RAG)和约束解码(CD)两种互补方法,设计相应技术细节,在合成和真实数据集上评估,结果显示RAG、CD各有优劣,能提升Web API调用代码正确性。

摘要:

Web API集成是现代软件系统的基石,但由于API规范复杂且不断演变,编写正确的Web API调用代码仍然具有挑战性。尽管大语言模型越来越多地用于代码生成,但先前的工作已通过实证表明,它们生成正确的Web API集成的能力有限。同时,缓解技术及其在这种情况下的有效性仍未得到充分理解。在本文中,我们提出并系统地评估了检索增强生成(RAG)和约束解码(CD)作为两种互补的方法,以改进大语言模型生成的Web API调用代码。对于RAG,我们设计了一个检索器,该检索器处理OpenAPI规范并检索紧凑的端点表示,以注入到模型提示中。对于CD,我们引入了从OpenAPI规范到基于正则表达式的约束的自动转换,这些约束在生成过程中强制执行。我们在WAPIIBench的现有合成数据集和从GitHub存储库派生的新真实世界数据集上评估了这两种方法。我们的结果表明,RAG在生成完整的API调用时减少了幻觉并提高了正确性,但在已经提供端点时会降低正确性,因为它鼓励生成不必要的参数。相比之下,CD可靠地防止了非法URL、HTTP方法和参数,并显著提高了两种起始代码的整体正确性。

英文摘要:

Integration of web APIs is a cornerstone of modern software systems, yet writing correct web API invocation code remains challenging due to complex and evolving API specifications. Although LLMs are increasingly used for code generation, previous work has empirically shown that their ability to generate correct web API integrations is limited. At the same time, mitigation techniques and their effectiveness for this setting remain insufficiently understood. In this paper, we propose and systematically evaluate retrieval-augmented generation (RAG) and constrained decoding (CD) as two complementary approaches to improving LLM-generated web API invocation code. For RAG, we design a retriever that processes OpenAPI specifications and retrieves compact endpoint representations to inject into model prompts. For CD, we introduce an automatic translation from OpenAPI specifications to regex-based constraints enforced during generation. We evaluate both approaches on WAPIIBench's existing synthetic dataset and on a new real-world dataset derived from GitHub repositories. Our results show that RAG reduces hallucinations and improves correctness when generating full API invocations but reduces it when the endpoint is already provided as it encourages the generation of unnecessary parameters. In contrast, CD reliably prevents illegal URLs, HTTP methods, and arguments and substantially improves overall correctness for both starter codes.

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

↑