mlsanityData to 7 Oct 2026

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

arXiv 2405.03509 ↗First posted 6 May 2024cs.SEcited by 2

On the map: LLM reasoning → Reasoning for agents, planning and code

Abstract (arXiv)

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.

Key facts. Cited by 2 papers in the map (data through 7 Oct 2026). Placed in Reasoning for agents, planning and code, one of 17 directions in LLM reasoning. Builds on 31 of its 69 references that are in the map. First posted on arXiv 6 May 2024.

Builds on

31 of 69 references.

References · 31

  1. 2018BERT: Pre-training of Deep Bidirectional Transformers for Language Understandingcited by 40,204
  2. 2023LLaMA: Open and Efficient Foundation Language Modelscited by 13,958
  3. 2021Evaluating Large Language Models Trained on Codecited by 8,053
  4. 2022PaLM: Scaling Language Modeling with Pathwayscited by 5,304
  5. 2022Self-Instruct: Aligning Language Models with Self-Generated Instructionscited by 2,674
  6. 2023A Survey of Large Language Modelscited by 2,537
  7. 2023Code Llama: Open Foundation Models for Codecited by 2,105
  8. 2023Gorilla: Large Language Model Connected with Massive APIscited by 1,302
  9. 2020CodeBERT: A Pre-Trained Model for Programming and Natural Languagescited by 1,286
  10. 2020Making Pre-trained Language Models Better Few-shot Learnerscited by 1,255
  11. 2021CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generationcited by 890
  12. 2021CodeXGLUE: A Machine Learning Benchmark Dataset for Code Understanding and Generationcited by 732
19 more
  1. 2022A Survey on In-context Learningcited by 717
  2. 2022InCoder: A Generative Model for Code Infilling and Synthesiscited by 492
  3. 2023How Good Are GPT Models at Machine Translation? A Comprehensive Evaluationcited by 344
  4. 2023CodeGeeX: A Pre-Trained Model for Code Generation with Multilingual Benchmarking on HumanEval-Xcited by 294
  5. 2023Self-collaboration Code Generation via ChatGPTcited by 255
  6. 2023Software Testing with Large Language Models: Survey, Landscape, and Visioncited by 163
  7. 2023Exploring the Limits of ChatGPT for Query or Aspect-based Text Summarizationcited by 122
  8. 2023ChatUniTest: A Framework for LLM-Based Test Generationcited by 94
  9. 2020PyMT5: multi-mode translation of natural language and Python code with transformerscited by 80
  10. 2023CodeIE: Large Code Generation Models are Better Few-Shot Information Extractorscited by 67
  11. 2023Using Large Language Models to Generate JUnit Tests: An Empirical Studycited by 53
  12. 2023SelfEvolve: A Code Evolution Framework via Large Language Modelscited by 43
  13. 2023Prompting Is All You Need: Automated Android Bug Replay with Large Language Modelscited by 40
  14. 2022Code Generation Tools (Almost) for Free? A Study of Few-Shot, Pre-Trained Language Models on Codecited by 39
  15. 2023ToolCoder: Teach Code Generation Models to use API search toolscited by 37
  16. 2023Large Language Model Instruction Following: A Survey of Progresses and Challengescited by 31
  17. 2023Copilot for Xcode: Exploring AI-Assisted Programming by Prompting Cloud-based Large Language Modelscited by 11
  18. 2023Measuring and Mitigating Constraint Violations of In-Context Learning for Utterance-to-API Semantic Parsingcited by 6
  19. 2023A Chain of AI-based Solutions for Resolving FQNs and Fixing Syntax Errors in Partial Codecited by 4

Built on by

Cited by year (2026 to 7 Oct)

Citing papers per year: 2025: 1; 2026: 1.

2 papers.

Similar, not cited

Close in wording, no citation either way

  1. 2025Code2API: A Tool for Generating Reusable APIs from Stack Overflow Code Snippets ↗
  2. 2024APIGen: Generative API Method Recommendation
  3. 2026Pseudo2CodeQA: A Benchmark for LLM-Based Structured Algorithmic Reasoning in Code Generation
  4. 2025Code Execution as Grounded Supervision for LLM Reasoning
  5. 2024A Comprehensive Framework for Evaluating API-oriented Code Generation in Large Language Models
  6. 2025Guided Code Generation with LLMs: A Multi-Agent Framework for Complex Code Tasks
  7. 2026Toward Interactive Understanding of Code APIs
  8. 2026Evaluating LLMs Code Reasoning Under Real-World Context