Are Human Rules Necessary? Generating Reusable APIs with CoT Reasoning and In-Context Learning

Fuente: arXiv
Saved in:
Bibliographic Details
Main Authors: Mai, Yubo, Gao, Zhipeng, Hu, Xing, Bao, Lingfeng, Liu, Yu, Sun, Jianling
Format: Preprint
Published: 2024
Subjects:
Online Access:
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866910436293607424
author Mai, Yubo
Gao, Zhipeng
Hu, Xing
Bao, Lingfeng
Liu, Yu
Sun, Jianling
author_facet Mai, Yubo
Gao, Zhipeng
Hu, Xing
Bao, Lingfeng
Liu, Yu
Sun, Jianling
contents 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 (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 Code2API 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.
format Preprint
id arxiv_https___arxiv_org_abs_2405_03509
institution arXiv
publishDate 2024
record_format arxiv
spellingShingle Are Human Rules Necessary? Generating Reusable APIs with CoT Reasoning and In-Context Learning
Mai, Yubo
Gao, Zhipeng
Hu, Xing
Bao, Lingfeng
Liu, Yu
Sun, Jianling
Software Engineering
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 (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 Code2API 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.
title Are Human Rules Necessary? Generating Reusable APIs with CoT Reasoning and In-Context Learning
topic Software Engineering
url https://arxiv.org/abs/2405.03509