This repo is about building LLMs to solve code challenges from LeetCode
Size | Hugging Face Repo | Base Model |
---|---|---|
7B | khaimaitien/leetcode_solver_7b | codellama/CodeLlama-7b-Instruct-hf |
You can download the training data from: khaimaitien/leetcode_problem_solution
This dataset was crawled from: https://github.com/AnasImloul/Leetcode-Solutions/tree/main
First you need to install the requirements:
pip install -r requirements.txt
python run_inference.py --input-file test_cases/problem1.txt --model-path khaimaitien/leetcode_solver_7b
Where first parameter is the leetcode problem stored in a text file, you can take a look at the format in test_cases/problem1.txt
Here is the output from above command:
class Solution:
def isUgly(self, n: int) -> bool:
if n == 1:
return True
if n == 0:
return False
if n % 2 == 0:
return self.isUgly(n // 2)
if n % 3 == 0:
return self.isUgly(n // 3)
if n % 5 == 0:
return self.isUgly(n // 5)
return False
python run_inference.py --leetcode-url https://leetcode.com/problems/merge-k-sorted-lists/ --model-path khaimaitien/leetcode_solver_7b
Here is the output from above command:
class Solution:
def mergeKLists(self, lists: List[ListNode]) -> ListNode:
if not lists:
return None
return self.merge(lists)
def merge(self, lists):
if len(lists) == 1:
return lists[0]
mid = len(lists) // 2
l1 = self.merge(lists[:mid])
l2 = self.merge(lists[mid:])
return self.mergeTwoLists(l1, l2)
def mergeTwoLists(self, l1, l2):
if not l1:
return l2
if not l2:
return l1
if l1.val < l2.val:
l1.next = self.mergeTwoLists(l1.next, l2)
return l1
else:
l2.next = self.mergeTwoLists(l1, l2.next)
return l2