arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2504.14331cs.SE
收藏

Code2API:从Stack Overflow代码片段生成可复用API的工具

Code2API: A Tool for Generating Reusable APIs from Stack Overflow Code Snippets

Yubo Mai, Zhipeng Gao, Xing Hu, Lingfeng Bao, Jingyuan Chen, Jianling Sun

AI总结:

针对Stack Overflow代码片段无法直接测试复用的问题,提出Chrome扩展Code2API,利用LLMs的思维链推理和少样本学习自动将其转换为可调用API,评估显示其显著优于基于规则的方法。

摘要:

如今,开发人员经常求助于Stack Overflow解决日常问题,但这些代码片段是无法正确测试和验证的部分代码。测试这些代码片段的一种方法是将其转换为开发人员可以直接调用和执行的API(应用程序接口)。然而,由于需要执行不同的操作(例如,总结合适的方法名、推断输入参数列表和返回语句),开发人员手动执行这种转换(称为API化任务)通常成本高昂且容易出错。为了帮助开发人员快速复用Stack Overflow中的代码片段,本文提出Code2API,这是一款使用大型语言模型(LLMs)自动对Stack Overflow上的代码片段进行API化的谷歌Chrome扩展。Code2API通过精心设计的提示引导LLMs生成可复用API,利用思维链推理和少样本上下文学习帮助LLMs以类似开发人员的方式理解和解决API化任务。评估结果表明,Code2API显著优于基于规则的方法。

英文摘要:

Nowadays, developers often turn to Stack Overflow for solutions to daily problems, however, these code snippets are partial code that cannot be tested and verified properly. One way to test these code snippets is to transform them into APIs (Application Program Interface) that developers can be directly invoked and executed. However, it is often costly and error-prone for developers to manually perform this transformation (referred to as AIPzation task) due to different actions to be taken (e.g., summarizing proper method names, inferring input parameters list and return statements). To help developers quickly reuse code snippets in Stack Overflow, in this paper, we propose Code2API, a Google Chrome extension that uses Large Language Models (LLMs) to automatically perform APIzation of code snippets on Stack Overflow. \toolname guides LLMs through well-designed prompts to generate reusable APIs, using Chain-of-Thought reasoning and few-shot in-context learning to help LLMs understand and solve the APIzation task in a developer-like manner. The evaluation results show that Code2API significantly outperforms the rule-based approach by a large margin.

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

↑