提出自动化框架AutoAPIEval,评估大模型生成调用特定API的代码能力。
A Comprehensive Framework for Evaluating API-oriented Code Generation in Large Language Models
- 构建可适配任意带文档库的自动化评估框架,聚焦API推荐与代码示例生成。
- 发现不同大模型在任务中表现差异大,ChatGPT更遵从指令,其他模型代码生成效果相近。
- 识别出API热度与模型置信度是影响代码质量的关键因素,可高效检测错误推荐与无效代码。
大型语言模型(如GitHub Copilot和ChatGPT)已成为提升编程效率的重要工具。然而,现有基准多关注通用代码生成,缺乏对面向API代码生成(即调用特定库API的代码)的系统性评估。为此,本文提出AutoAPIEval——一个轻量级、自动化的评估框架,适用于任何提供API文档的库。该框架针对两个核心任务:API推荐与代码示例生成,并采用四项指标评估结果,包括任务1中错误推荐比例,任务2中未调用具体API、无法编译或不可执行的代码示例比例。我们以ChatGPT、MagiCoder和DeepSeek Coder三款模型及Java Runtime Environment 8为例进行案例研究,结果表明模型间性能差异显著:ChatGPT更遵守指令,而其他两模型在代码生成上表现相似。研究还发现API流行度与模型置信度显著影响代码质量,并构建高精度分类器以检测错误的API推荐与错误代码。检索增强生成可提升代码质量,但其效果因模型而异。
原文摘要 · Abstract (English)
Large language models (LLMs) like GitHub Copilot and ChatGPT have emerged as powerful tools for code generation, significantly enhancing productivity and accelerating software development. However, existing benchmarks primarily focus on general code generation without considering API-oriented code generation, i.e., generating code that invokes APIs from specific libraries. Given the growing demand for API-oriented code generation, there is a pressing need for a systematic and automated approach to evaluate LLM on API-oriented code generation. To address this gap, we propose AutoAPIEval, a lightweight and automated framework designed to evaluate the capabilities of LLMs in API-oriented code generation. Our framework works with any library that provides API documentation and focuses on two unit tasks: API recommendation and code example generation, along with four metrics to evaluate the generated APIs and code examples, such as the proportion of incorrect API recommendations for Task 1, and the proportion of code examples where no specific API is invoked and uncompilable/unexecutable code examples for Task 2. In addition, we conducted a case study on three LLMs (ChatGPT, MagiCoder, and DeepSeek Coder) and Java Runtime Environment 8 to demonstrate the framework's effectiveness. Our findings reveal substantial variability in LLM performance across tasks, with ChatGPT adhering better to instructions, while sharing similar effectiveness in code example generation with its counterparts (i.e., MagiCoder and DeekSeek Coder). We also identify key factors associated with code quality, such as API popularity and model confidence, and build classifiers that achieve high accuracy in detecting incorrect API recommendations and erroneous code examples. Retrieval-augmented generation enhances the quality of code generated by LLMs, though its effectiveness varies across different LLMs.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。