Are Human Rules Necessary? Generating Reusable APIs with CoT Reasoning and In-Context Learning
Yubo Mai, Zhipeng Gao, Xing Hu, Lingfeng Bao, Yu Liu, Jianling Sun
摘要
Nowadays, more and more developers resort to Stack Overflow for solutions (e.g., code snippets) when they encounter technical problems. Although domain experts provide huge amounts of valuable solutions in Stack Overflow, these code snippets are often difficult to reuse directly. Developers have to digest the information within relevant posts and make necessary modifications, and the whole solution-seeking process can be time-consuming and tedious. To facilitate the reuse of Stack Overflow code snippets, Terragni et al. first explored transforming a code snippet in Stack Overflow into a well-formed method API ( A pplication P rogram I nterface) by using a rule-based approach, named APIzator. The reported performance of their approach is promising, however, after our in-depth analysis of their experiment results, we find that (1) 92.5% of APIs generated by APIzator are pointless and thus are difficult to use in practice. This is because the method name generated by APIzator (extracting verb + object ) can rarely represent the method’s functionality, which can hardly be claimed as meaningful/reusable APIs. (2) The authors manually summarized a number of rules to identify parameter variables and return statements for Java methods. These hand-crafted rules are extremely complex and sophisticated, and the manual rule design process is labor-intensive and error-prone. Moreover, since these rules are designed for Java, they can hardly be extended to other programming languages. Inspired by the great potential of Large Language Models (LLMs) for solving complex coding tasks, in this paper, we propose a novel approach, named Code 2API, to automatically perform APIzation for Stack Overflow code snippets. Code 2API does not require additional model training or any manual crafting rules and can be easily deployed on personal computers without relying on other external tools. Specifically, Code 2API guides the LLMs through well-designed prompts to generate well-formed APIs for given code snippets. To elicit knowledge and logical reasoning from LLMs, we used c hain- o f- t hought (CoT) reasoning and few-shot in-context learning, which can help the LLMs fully understand the APIzation task and solve it step by step in a manner similar to a developer. Our evaluations show that Code 2API achieves a remarkable accuracy in identifying method parameters (65%) and return statements (66%) equivalent to human-generated ones, surpassing the current state-of-the-art approach, APIzator, by 15.0% and 16.5% respectively. Moreover, compared with APIzator, our user study demonstrates that Code 2API exhibits superior performance in generating meaningful method names, even surpassing the human-level performance, and developers are more willing to use APIs generated by our approach, highlighting the applicability of our tool in practice. Finally, we successfully extend our framework to the Python dataset, achieving a comparable performance with Java, which verifies the generalizability of our tool.
问 Lune
几分钟读透这篇 Paper,不用再花一下午。
Lune 能读完全文,也能读引用它的顶会 Paper,讲清它的结论、证据和局限,每一点都注明出自哪篇 Paper。不用硬啃,也不靠猜。
已有 5 篇顶会 Paper 引用了它。别等审稿人问起,先弄清它们发现了什么。
脉络
- SelfPiCo: Self-Guided Partial Code Execution with LLMs 引用了 CodeBERT: A Pre-Trained Model for Programming and Natural Languages
- SelfPiCo: Self-Guided Partial Code Execution with LLMs 引用了 Chain-of-Thought Prompting Elicits Reasoning in Large Language Models
- Coding in a Bubble? Evaluating LLMs in Resolving Context Adaptation Bugs during Code Adaptation 引用了 Language Models are Few-Shot Learners
- Coding in a Bubble? Evaluating LLMs in Resolving Context Adaptation Bugs during Code Adaptation 引用了 Chain-of-Thought Prompting Elicits Reasoning in Large Language Models
- Towards Better Answers: Automated Stack Overflow Post Updating 引用了 SelfPiCo: Self-Guided Partial Code Execution with LLMs
- Towards Better Answers: Automated Stack Overflow Post Updating 引用了 CodeBERT: A Pre-Trained Model for Programming and Natural Languages
- Towards Better Answers: Automated Stack Overflow Post Updating 引用了 Chain-of-Thought Prompting Elicits Reasoning in Large Language Models
- Large Language Models are Zero-Shot Reasoners 引用了 Language Models are Few-Shot Learners
- Large Language Models are Zero-Shot Reasoners 引用了 Chain-of-Thought Prompting Elicits Reasoning in Large Language Models
- Large Language Models are Zero-Shot Reasoners 引用了 Training language models to follow instructions with human feedback
- Large Language Model-Aided Partial Program Dependence Analysis 引用了 CodeBERT: A Pre-Trained Model for Programming and Natural Languages
- Actionable Warning Is Not Enough: Recommending Valid Actionable Warnings with Weak Supervision 引用了 SelfPiCo: Self-Guided Partial Code Execution with LLMs
- Actionable Warning Is Not Enough: Recommending Valid Actionable Warnings with Weak Supervision 引用了 Towards Better Answers: Automated Stack Overflow Post Updating
- Chain-of-Thought Prompting Elicits Reasoning in Large Language Models 引用了 Training language models to follow instructions with human feedback
- Training language models to follow instructions with human feedback 引用了 Language Models are Few-Shot Learners
引用它的顶会 Paper5
- SelfPiCo: Self-Guided Partial Code Execution with LLMsZhipeng Xue, Zhipeng Gao, Shaohua Wang, Xing Hu 等ISSTA 2024 · 8 次引用
- Towards Better Answers: Automated Stack Overflow Post UpdatingYubo Mai, Zhipeng Gao, Haoye Wang, Tingting Bi 等ICSE 2025 · 4 次引用
- Large Language Model-Aided Partial Program Dependence AnalysisXiaokai Rong, Aashish Yadavally, Tien N. NguyenICSE 2026 · 1 次引用
- Coding in a Bubble? Evaluating LLMs in Resolving Context Adaptation Bugs during Code AdaptationTanghaoran Zhang, Xinjun Mao, Shangwen Wang, Yuxin Zhao 等FSE 2026
- Actionable Warning Is Not Enough: Recommending Valid Actionable Warnings with Weak SupervisionZhipeng Xue, Zhipeng Gao, Tongtong Xu, Xing Hu 等ICSE 2026
它引用的 Paper14
- Language Models are Few-Shot LearnersTom B. Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah 等NeurIPS 2020 · 64,255 次引用
- Training language models to follow instructions with human feedbackLong Ouyang, Jeffrey Wu, Xu Jiang, Diogo Almeida 等NeurIPS 2022 · 24,707 次引用
- Chain-of-Thought Prompting Elicits Reasoning in Large Language ModelsJason Wei, Xuezhi Wang, Dale Schuurmans, Maarten Bosma 等NeurIPS 2022 · 22,562 次引用
- Large Language Models are Zero-Shot ReasonersTakeshi Kojima, Shixiang Shane Gu, Machel Reid, Yutaka Matsuo 等NeurIPS 2022 · 8,168 次引用
- CodeBERT: A Pre-Trained Model for Programming and Natural LanguagesZhangyin Feng, Daya Guo, Duyu Tang, Nan Duan 等EMNLP Findings 2020 · 2,828 次引用
相关 Paper
- CKTyper: Enhancing Type Inference for Java Code Snippets by Leveraging Crowdsourcing Knowledge in Stack OverflowAnji Li, Neng Zhang, Ying Zou, Zhixiang Chen 等FSE 2025 · 1 次引用
- APIzation: Generating Reusable APIs from StackOverflow Code SnippetsValerio Terragni, Pasquale SalzaASE 2021 · 12 次引用
- ExploraCoder: Advancing Code Generation for Multiple Unseen APIs via Planning and Chained ExplorationYunkun Wang, Yue Zhang, Zhen Qin, Chen Zhi 等ACL 2025 · 13 次引用
- Question Answering as Programming for Solving Time-Sensitive QuestionsXinyu Zhu, Cheng Yang, Bei Chen, Siheng Li 等EMNLP 2023 · 6 次引用
- Instruct or Interact? Exploring and Eliciting LLMs' Capability in Code Snippet Adaptation Through Prompt EngineeringTanghaoran Zhang, Yue Yu, Xinjun Mao, Shangwen Wang 等ICSE 2025 · 3 次引用
