一句话:提出 Code2API,用大语言模型结合思维链与少样本提示,自动将 Stack Overflow 代码片段转化为可复用 API。
Stack Overflow 上的代码片段通常是无法直接测试与验证的部分代码,开发者需手工将其转化为可调用、可执行的 API(即 APIzation),但该过程涉及方法命名、输入参数列表与返回语句推断等多个步骤,成本高且易出错。本文提出 Code2API——一个 Google Chrome 扩展,利用大语言模型自动完成代码片段的 APIzation:通过精心设计的提示,结合 Chain-of-Thought 推理与 few-shot in-context learning,引导 LLM 以接近开发者的方式理解并解决该任务。评估结果表明,Code2API 大幅优于基于规则的方法。该工具的完整论文已作为研究论文发表于 FSE'24。
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 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. Code2API 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. The full paper of this tool has been published in FSE'24 as a research paper [11].
DOI 原文 ·
@inproceedings{paperbot9601,
title = {Code2API: A Tool for Generating Reusable APIs from Stack Overflow Code Snippets},
author = {Yubo Mai and Zhipeng Gao and Xing Hu and Lingfeng Bao and Jingyuan Chen and Jianling Sun},
booktitle = {ISSTA},
year = {2025},
doi = {10.1145/3713081.3731741}
}