TL;DR
This paper introduces WAPIIBench, a novel dataset and evaluation pipeline to benchmark Large Language Models (LLMs) on generating web API integration code. Their findings reveal that even state-of-the-art LLMs struggle significantly with this task, often producing incorrect code with hallucinated endpoints and arguments, highlighting a critical gap in current LLM capabilities for real-world software development.
What Problem Does This Paper Address?
Modern software development heavily relies on integrating various services through web APIs. However, writing correct code to interact with these APIs is notoriously difficult. Developers need to understand complex specifications, handle diverse data formats, and keep up with evolving APIs. While LLMs have shown promise in code generation, their ability to automate the creation of correct web API integration code remains largely unexplored. This paper aims to fill that gap by systematically evaluating how well LLMs can generate code that accurately invokes web APIs, addressing the crucial question of whether LLMs can truly streamline this complex development process.
Methods
The authors developed a comprehensive benchmark called WAPIIBench, consisting of four key stages:
- Dataset Creation: They synthesized a dataset of nearly 400 task-configuration pairs for four real-world APIs (Asana, Google Calendar, Google Sheets, Slack). This involved using a powerful LLM (Gemini 1.5 Pro) with OpenAPI specifications to generate initial tasks and their corresponding correct request configurations (URL, HTTP method, parameters). This synthetic approach was chosen to ensure comprehensive coverage and unambiguous task descriptions, which are often lacking in real-world code. The dataset underwent rigorous manual review and correction.
- Code Generation: LLMs were tasked with generating JavaScript code using the Axios library to perform specific API operations described in natural language comments. They evaluated models in two setups: "full completion" (generating the entire Axios call) and "argument completion" (generating only the arguments, with the endpoint and method provided).
- Code Execution: A controlled, sandboxed environment was created to safely execute the generated code. This environment intercepts API requests and captures their configurations, preventing unintended interactions with external servers. It also includes mechanisms to handle "excess code" (code generated after the intended task).
- Correctness Analysis: The captured request configurations were compared against the ground-truth configurations from the dataset. This analysis went beyond simple string matching, employing fine-grained metrics to assess correctness at various levels (URL, method, arguments) and to identify specification violations.
Datasets
The paper introduces WAPIIBench, a novel benchmark dataset specifically designed for evaluating LLM performance in generating web API integration code. It comprises approximately 400 pairs of natural language task descriptions and their corresponding correct API request configurations. The dataset covers four popular real-world APIs: Asana, Google Calendar, Google Sheets, and Slack. This dataset is unique in its focus on web API invocations and its execution-based evaluation methodology, differentiating it from existing code generation datasets that often focus on local function calls or have less rigorous evaluation.
Key Insights and Ideas
- LLMs struggle with API integration: Despite their advancements, LLMs are not yet reliable for generating correct web API integration code. The complexity of API specifications and the need for precise parameter handling pose significant challenges.
- Hallucinations are rampant: A major issue is LLMs "hallucinating" incorrect information, such as non-existent API endpoints or invalid argument names and values. This is a critical concern for code correctness and reliability.
- Argument completion is slightly better, but still flawed: While providing the correct endpoint and method (argument completion) improves performance, LLMs still frequently fail to correctly assemble the arguments, indicating a deeper issue with understanding API constraints.
- Model size isn't everything: The study observed that medium-sized models sometimes underperform compared to smaller or larger variants within the same family, suggesting that architecture and training data play a crucial role beyond just parameter count.
- API specificity matters: LLM performance varies across different APIs, likely due to the prevalence of those APIs in their training data. Google Calendar, for instance, seems to be better understood by most models.
Key Results
- Low overall correctness: None of the evaluated open-source LLMs could solve more than 40% of the tasks correctly in the "full completion" scenario.
- High error rates: Hallucinated endpoint URLs occurred in up to 39% of tasks, and incorrect argument names in up to 31% of tasks.
- Argument completion improvement: In the "argument completion" setup, the best open-source model (Code Llama 70B) achieved around 40% correctness, a significant improvement but still far from ideal.
- GPT-4o leads, but not perfectly: Even proprietary models like GPT-4o achieved the highest correctness (around 60% for full completion), but still made errors, highlighting the general difficulty of the task.
- Executability is high, correctness is low: While many generated code snippets were executable (over 94% for most models), the correctness of the API invocation was often compromised.
Limitations and Future Work
The authors acknowledge several limitations:
- Simplified context: The evaluation used limited program context before the API invocation, which might not reflect real-world scenarios.
- Focus on outgoing requests: The evaluation only assessed the correctness of the outgoing API request, not how the incoming response is handled.
- Dataset limitations: While carefully curated, the synthetic dataset might still contain subtle errors or use placeholder values that limit generalizability. The limited number of APIs also means results might not generalize to all APIs.
- Prompt engineering: The study used a consistent prompt for all models, and customized prompt engineering could potentially improve individual model performance.
Future work could explore:
- Retrieval-augmented generation: Investigating how LLMs can better leverage external knowledge sources.
- Fine-tuning and reasoning: Developing specialized training techniques to improve API understanding.
- Feedback loops and constrained decoding: Exploring methods to guide LLMs towards correct API usage during generation.
- Extending to other languages and libraries: Adapting the WAPIIBench methodology to different programming languages and API interaction libraries.
Summary updated