Model API
The project provides a REST API built with FastAPI, exposing a /predict endpoint for classifying code comments by their programming language. This API allows developers to send text snippets and receive predicted labels along with model metadata.
Test the API Locally
Tip
Make sure the git repository has been cloned and all dependencies are installed before running the server.
1. Start the Server
Run the FastAPI server locally using Uvicorn:
- The
--reloadflag enables automatic reloading whenever code changes are detected - By default, the server runs at
http://127.0.0.1:8000
2. Request Payload
Send a JSON request containing:
texts: a list of code commentslanguage: the language context for prediction
3. Response Body
The API returns a JSON response with:
labels: predicted labels for each input textpredictions: numeric labels for each input textmodel_info: metadata about the model used for prediction
Example Response
{
"predictions": [
[1, 0, 0, 0, 0, 0, 0],
[1, 0, 0, 0, 0, 0, 0]
],
"labels": [
["summary"],
["summary"]
],
"model_info": {
"artifact": "RandomForestTfIdf_java",
"language": "java"
}
}
Supported Languages
- Java: Fine-tuned CodeBERTa model
- Python: GraphCodeBERT model
- Pharo: GraphCodeBERT model
Interactive API Documentation
FastAPI automatically provides interactive API documentation:
- Swagger UI: http://127.0.0.1:8000/docs
- ReDoc: http://127.0.0.1:8000/redoc
You can test the API directly from these interfaces by clicking "Try it out" on any endpoint.