{"id":16517870,"url":"https://github.com/erhant/leet-assistant","last_synced_at":"2026-04-09T23:47:22.188Z","repository":{"id":211167736,"uuid":"713491605","full_name":"erhant/leet-assistant","owner":"erhant","description":"A personalized LeetCode assistant.","archived":false,"fork":false,"pushed_at":"2023-12-14T14:24:53.000Z","size":1068,"stargazers_count":1,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-13T06:43:20.797Z","etag":null,"topics":["daisyui","firstbatch","langchain","pinecone","solidjs","tailwindcss"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/erhant.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-02T16:18:08.000Z","updated_at":"2024-09-27T19:02:52.000Z","dependencies_parsed_at":"2023-12-14T15:50:49.018Z","dependency_job_id":null,"html_url":"https://github.com/erhant/leet-assistant","commit_stats":null,"previous_names":["erhant/leet-assistant"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erhant%2Fleet-assistant","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erhant%2Fleet-assistant/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erhant%2Fleet-assistant/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erhant%2Fleet-assistant/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/erhant","download_url":"https://codeload.github.com/erhant/leet-assistant/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241564432,"owners_count":19982958,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["daisyui","firstbatch","langchain","pinecone","solidjs","tailwindcss"],"created_at":"2024-10-11T16:34:06.500Z","updated_at":"2026-04-09T23:47:17.147Z","avatar_url":"https://github.com/erhant.png","language":"TypeScript","readme":"\u003cdiv\u003e\n  \u003ch1 align=\"center\"\u003e\n    Leet Assistant\n  \u003c/h1\u003e\n  \u003cp align=\"center\"\u003e\n    \u003ci\u003eA personalized LeetCode assistant, guiding you about problems to solve based on your performance \u0026 interests.\u003c/i\u003e\n  \u003c/p\u003e\n\u003c/div\u003e\n\n## Motivation\n\n[LeetCode](https://leetcode.com/) is an online platform where you solve coding challenges, such as coding interview questions and competitive programming questions. It has over 2000 problems, with a wide variety of topics.\n\n[Leet Assistant](https://leet-assistant.vercel.app/) is a proof-of-concept tool that demonstrates effortless plug-and-play personalization of [FirstBatch User Embeddings](https://userembeddings.firstbatch.xyz/).\n\nThe general idea is as follows:\n\n- You are greeted with a batch of random questions.\n- You can look at these questions, and you can notify FirstBatch with one of the following:\n  - **solve**: you have solved this question\n  - **retry**: you have solved it, but would like to try it again later\n  - **fail**: you have not been able to solve it\n- When you are done with the current batch of questions, you can request a new batch; this new batch will be more tailored towards your session! For example, if you were unable to solve `array` topics, you will see more `array` questions in the new batch.\n\nA chat-bot is also provided that is connected to ChatGPT. It uses the batch of questions retrieved by FirstBatch to create a context, and using LangChain we make Retrival-Augmented Generation (RAG) to answer certain questions about the given batch of questions.\n\n## Personalization\n\nSo how does personalizaton work with FirstBatch? The docs describe it perfectly (see [here](https://firstbatch.gitbook.io/firstbatch-sdk/get-started/introduction)), but we will also provide a short description here as well.\n\nThe algorithm designed for this use-case can be found under the [img folder](./img/algorithm.png).\n\n### Creating a Session\n\nFirst, the user create a session through a POST request at `/session`, which corresponds to the following call:\n\n```ts\nconst session = await personalized.session(\n  constants.FIRSTBATCH.ALGORITHM_NAME,\n  constants.FIRSTBATCH.VECTORDB_ID,\n  {\n    customId: constants.FIRSTBATCH.ALGORITHM_ID,\n  }\n);\n```\n\nThe user stores the returned session object (which is just an ID and a bool related to persistence) for future calls.\n\n### Requesting a Batch\n\nAt any point in time, we can request a set of random data points from our embedding space. We do this via a POST request to `/batch` with our sessionId, which corresponds to the following call:\n\n```ts\nconst batch = await personalized.batch(session);\n```\n\n### Making a Signal\n\nFor any of the returned questions, we have a id as it appears within the Pinecone index, we refer to this as `contentId`. To make a signal w.r.t to a question, we make a POST request to `/signal` endpoint, which corresponds to the following calls:\n\n```ts\nawait personalized.addSignal(session, constants.ACTIONS[signal], contentId);\n```\n\nHere, `constants.ACTIONS` is just an object of prepared `UserAction` objects, see more [here](https://firstbatch.gitbook.io/firstbatch-sdk/learn/signals).\n\n## Setup\n\nYou can locally setup this project by following either of the following steps:\n\n- Simply set `VITE_BASE_URL` to be `https://leet-assistant.vercel.app/api` in `.env` and use the existing backend.\n\nOr, use your own backend APIs as follows:\n\n- Create a new [Pinecone](https://www.pinecone.io/) index, and get your API KEY.\n- You will also need an [OpenAI](https://chat.openai.com/) API KEY to compute embeddings.\n- Convert the questions to embeddings, and upload them to your Pinecone index; see [below](#data) for instructions.\n- Get a [FirstBatch User Embeddings](https://userembeddings.firstbatch.xyz/) API key.\n\n### Structure\n\n- [**App**](./app/) is a simple RESTful api, using [Solid](https://www.solidjs.com/) for the webapp and API endpoits that correspond to serverless edge functions at Vercel, with [Tailwind](https://tailwindcss.com) + [Daisy](https://daisyui.com/) for the frontend and [FirstBatch](https://www.firstbatch.xyz/) + [LangChain](https://www.langchain.com/) + [Pinecone](https://www.pinecone.io/) for the backend (via serverless functions under [api routes](./app/src/routes/api/)).\n- [**Data**](./data/) has the logic to convert the given set of [LeetCode Questions](https://www.kaggle.com/datasets/manthansolanki/leetcode-questions) to embeddings and store them in a vectorDB, using [LangChain](https://www.langchain.com/) + [Pinecone](https://www.pinecone.io/).\n\nTo run the app, simply navigate to the [app](./app/) folder, install packages and run the development server:\n\n```sh\ncd app\npnpm install\npnpm dev\n```\n\nIf you try to build the server, it will fail due to the Vercel adapter; however, you can comment that out within the [Vite config](./app/vite.config.ts).\n\n### Dataset\n\nThe dataset here has been retrieved from \u003chttps://www.kaggle.com/datasets/manthansolanki/leetcode-questions/\u003e. Download the dataset and place the CSV file as `./res/leetcode_questions.csv`. We use OpenAI and Pinecone to generate embeddings from the dataset and store them at Pinecone.\n\nWe have used Bun for this, but any other runtime should work as well.\n\n```sh\nbun install\n```\n\nWe provide some helper scripts within [package.json](./package.json).\n\n```bash\ncd data\nbun run pinecone  # describe Pinecone index\nbun run questions # print random questions to console\nbun run train     # compute question embeddings \u0026 upload them to Pinecone\n```\n\n## Remarks\n\n- I had initially written everything with Bun, with Elysia as backend and Solid as frontend. However, deploying a Bun backend within a free-tier plan was a total nightmare, so I changed the backend to reside within the api routes of the Solid app. See this version of the code at the [`bun`](https://github.com/erhant/leet-assistant/tree/bun) branch in this repo.\n\n- Everything is deployed at Vercel in a free-tier plan, so api endpoints may sometimes timeout (especially ChatGPT ones) because Vercel imposes some limits on the runtime duration of serverless functions.\n\n- There is a lot of fine-tuning to do, both for the ChatGPT prompts and for the personalization through FirstBatch user embeddings.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferhant%2Fleet-assistant","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ferhant%2Fleet-assistant","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferhant%2Fleet-assistant/lists"}