OpenAI GitHub Readme Generator

This is my first project using OpenAI. I was inspired by Jack Herrington,

Libraries and Framework

Challenges

Open AI response is not fast, so we are going to mitigate that by using next.js Defer. (not implemented yet)

Getting started

1. Install the dependencies

yarn

2. Deploy on Vercel and Defer

Make sure to get a GitHub personal access token and an OpenAI API Key.

Then, configure the application on Defer and Vercel.


How it works

The Next.js API Route /api/gitHubProfile/[usernameOrExecID] is used as follow:

  • Trigger a new generation: POST /api/gitHubProfile/charlypoly
  • Get the status and result of a profile text generation: GET /api/gitHubProfile/2MeNNf2OTVZP0MUrs1ghwXaUtm4

The generateGitHubProfile() Defer background function handles fetching data from GitHub and forwarding the proper prompt to OpenAI.

Triggering an execution of generateGitHubProfile() is achieved by simply calling it from the Next.js API Route:

import { NextRequest, NextResponse } from "next/server";
import generateGitHubProfile from "@/defer/generateGitHubProfile";

export async function POST(
  _request: NextRequest,
  { params }: { params: { usernameOrExecId: string } }
) {
  const ret = await generateGitHubProfile(params.usernameOrExecId);
  return NextResponse.json(ret);
}