Codeserv is a simplified code generation service designed to transform code from a public GitHub repository based on specific prompts, such as converting the code to a different language (e.g., TypeScript). The service outputs the difference (diff) between the original and transformed code. Had a blast and hope you enjoy my implementation :)
To build this service, my implementation uses FastAPI, Supabase DB for storage, and AWS EC2 to host the API along with a collection of small Python utility functions to fetch code, transform code, store code, and return a diff.
For more detailed information about the implementation of this FastAPI service. The page breaks down how I approached this technical challenge, the process, and docs for future maintenance of this app. You can visit my Notion page: Deniz Jasarbasic's TinyGen
The base URL for the Codeserv API is base_api_url
= http://3.22.241.58
Methods | Endpoints | Description |
---|---|---|
GET | / |
Returns a welcome message. |
POST | /run |
Executes Codeserv with required parameters repoUrl and prompt in the request body. Return a unified diff of suggested changes. |
GET | /docs |
Provides interactive API documentation via Swagger UI. |
{
"repoUrl": "a public GitHub URL",
"prompt": "A prompt, ex: Convert the source code to Java."
}
{
"diff": ...
}
- The
diff
attribute contains a unified diff (as a string) between the orginal code and modified suggested code by ChatGPT.
Codeserv returns the following status codes in its API:
Status Code | Description |
---|---|
200 | OK |
400 | BAD REQUEST |
422 | UNPROCESSABLE ENTITY |
500 | INTERNAL SERVER ERROR |
Click the button below to import the Postman collection and environment file. Play around with the Welcome
and Run
steps. The example in the collection below uses a simple multi-file python repository and asks a simple prompt to convert the code to Java. Feel free to play around with this example or use your own:
Explore the API endpoints using the interactive Swagger documentation tool at http://3.22.241.58/docs
Codeserv uses Python 3. All necessary libraries are listed in the requirements.txt
file. Install them by running pip install -r requirements.txt
.
- Python โฅ 3.9.7
- Libraries: difflib, os, OpenAI, python-dotenv, PyGithub, supabase, uvicorn, pydantic, fastapi
You can create a .env file locally to store the key information below, or pass it via secrets when deployed.
# ChatGPT API Access
OPENAI_API_KEY=""
# GitHub API Access
GITHUB_TOKEN=""
# Supabase Configuration
SUPABASE_URL=""
SUPABASE_KEY=""
Go to the app/
directory and run:
python3 -m uvicorn main:app --reload