GithubHelp home page GithubHelp logo

tiny_gen's Introduction

Safeimagekit-resized-img

Deniz Jasarbasic's Codeserv

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 :)

Overview

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.

Notion Page

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

Usage

Basics

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.

Request Body

{
    "repoUrl": "a public GitHub URL",
    "prompt": "A prompt, ex: Convert the source code to Java."
}

Response

{
  "diff": ...
}
  • The diff attribute contains a unified diff (as a string) between the orginal code and modified suggested code by ChatGPT.

Status Codes

Codeserv returns the following status codes in its API:

Status Code Description
200 OK
400 BAD REQUEST
422 UNPROCESSABLE ENTITY
500 INTERNAL SERVER ERROR

Run in Postman

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:

Run In Postman

Interactive Swagger Docs Tool

Explore the API endpoints using the interactive Swagger documentation tool at http://3.22.241.58/docs

Local Setup

Step 1: Dependencies

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

Step 2: Environment Variables

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=""

Step 3: Running Codeserv

Go to the app/ directory and run:

python3 -m uvicorn main:app --reload

tiny_gen's People

Contributors

deniz-jasa avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.