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

TL;DR
This paper introduces Code2API, a novel method leveraging chain-of-thought reasoning and in-context learning with LLMs to automatically generate APIs from code snippets without extra training, outperforming existing approaches.
Contribution
The paper presents a training-free APIzation approach using LLMs with prompt engineering, chain-of-thought reasoning, and few-shot learning, demonstrating high accuracy and generalizability.
Findings
Achieves 65% accuracy in method parameter identification
Surpasses state-of-the-art APIzator by 15-16.5%
Extends effectively to Python datasets
Abstract
Inspired by the great potential of Large Language Models (LLMs) for solving complex coding tasks, in this paper, we propose a novel approach, named Code2API, to automatically perform APIzation for Stack Overflow code snippets. Code2API 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, Code2API 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 chain-of-thought (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 Code2API achieves a remarkable accuracy in identifying method parameters (65%) and return statements…
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
