Free Copilot to Take Your Coding to the NEXT LEVEL

LARRUZ shows how to set up Llama 3 as a free coding assistant in VS Code using the Code GPT extension and GROQ API. The extension has 1.2M downloads and lets you explain code, refactor, add docs, find bugs, and generate tests without paying. Future videos will cover fully local setups with LM Studio or Ollama.
Questions this video answers
LARRUZ
May 6, 2024
Code GPT Chat and AI Agents
Over 1.2 million downloads
GROQ API with Llama 3 (70 billion model)
Chapters
This is probably the easiest way of using LLAMA 3 as your programming copilot in Visual Studio code, and it's free. To set up our copilot, we will use this VS code extension called code GPT. And for llama 3 we will use the GROQ API. So here we will use the 70 billion model. Now, code GPT offers different tiers. There is a free tier which I have found to be more than enough. This video is not sponsored by them. I have been using this setup personally for the last few days and have really enjoyed the experience and that's why I wanted to create this video. So to install the Code GPT extension, we're going to go to Extensions, then type Code GPT and you want to select this one Code GPT Chat and AI Agents. So it seems to be doing a lot more than a simple copilot. But that might be a subject of a future video. So click on install this will install the extension on VS Code. It has over 1.2 million downloads, so it's a pretty useful and famous extension. Now, once the installation is complete, you will see Code GPT in a new tab, so you can click on this. Now in the list of providers which you can select from here you can see it has support for different API providers, including OpenAI, Anthropic, go here. And there is even support for Ollama as Well as for LM Studio. So I'll probably create more videos using the Llama 3 models locally. But for this video we are going to be using the Groq version. That's why I'm going to select Groq and then you want to set your connection which is basically providing your API key. So go ahead, copy your Groq API key, provide it here, then click Connect. Next you also want to select the model that you want to use. So I will be using the 70 billion model and now you can start interacting with your copilot. So I like to use it as a copilot to do quick implementations. So for example, here's a command. Write a python function that Download files from S3 so I don't have to look it up on Stack Overflow or Ask ChatGPT. Everything is within, which is pretty neat. But the main usage that I have found is when you are working with your own code base. So for example, I'm currently working on the newest version of Local GPT which is going to be coming out pretty soon. So let me just select a function here which implements a retriever. Then we're going to right click on it and you will see a number of different options and we are going to look at all of them in this video. So here it says explain code GPT refactor document, find problems and unit tests. So let's see if the Llama 3 model can explain our code. So I'm going to select the explain code GPT option and let's see what explanation llama3 comes up with. So it's actually trying to explain the code that it sees. Now the code uses a lot of LangChain and especially in this specific function. So the probably llama 370 billion model hasn't seen a lot of lang change. So it may not give us the best explanation. But let's see what it came up with. So it says function signature, it talks about what are the inputs of the function. So there is docs list embedding model, then collection name. Right. Then function body. So it says initialize two recursive character text splitter objects. So basically telling us what is going on in the function but not really providing it a lot of details because I don't think it has a lot of context when it comes to LangChain. So I'm going to try to give it a code that it probably can explain. So this is a re ranking method, so which re ranks context provided to the LLM. So let's see if it can explain this code to us. Now here we have a bunch of if else conditional statements and let's quickly look at some of the explanation that it provided. So it talks about the function signature, then the body of the function. So it says the function initialize an instance of re ranking class which is not defined in this code snippet. So I'm actually importing it from another file. But since I provided only this small function, so it says it's not provided in this context. Right. Other than that, this actually gives us a pretty good explanation of what exactly is going on in this specific function. Now one thing which I really like about llama3 is you can use it to improve the quality of your code. So let me show you that example through code. Now you can select a piece of code, it can be a function or multiple functions for that matter, and then you can ask it to refactor the code for you. So we're going to click on refactor code GPT instantly we have a refactor version of the code. Now as I said, this code uses a lot of conditional statements, but in the refactor version is actually using a dictionary to do the conditional checks. It says created a dictionary rerank method to map re ranking models to their corresponding methods. This makes the code more readable and efficient, which is actually a really nice implementation. And then use get method to the dictionary to retrieve the re ranking method based on the re ranking model. This makes the code more concise and easier to maintain. And I think it's talking about this get method. Okay. Then it says improve code readability by adding white spaces and using consistent indentation. So this is pretty cool. Now here's the really cool part. You can just select the initial implementation. If you are happy with this implementation, just click on this insert code button and it will replace your original code, which is pretty cool. Now since we are using the chat model so we can actually keep asking questions regarding the changes it made or further improvements it can make. So let's say I'm going to say alright, so I said can you replace the last if else statement in your code with the dictionary? Can you explain why didn't you do that? I'm talking about this conditional statement and let's see what the model comes up with. I didn't do this initially because I was following the original code structure and didn't think to refactor it further. However, using a dictionary to handle the default behavior is a great way to simplify the code and make it more concise. Alright, so let's see what changes it made. Now in this code it replaced the last if else statement with the default get value and the default value is just returning exactly the same context that we provided in the same model. So that was the behavior I actually implemented and it seems to be working. So I'm going to just replace my code. And now we have updated code here. Now it's a great way of actually not only using is as a copilot, but you can learn a lot from the model itself and it's available for free for you in your visual code studio. Now the next option is document code GPT. So let's see if it can document the code that we are providing. And in this case it added some extra comments to the code. So it didn't really change the code, but it added some helpful comments that will further explain the code. What is. What is happening in here? Now in general you want to write pretty neat and concise code and you want to avoid adding comments. You want to make sure that the code is readable and understandable. So anybody who is just reading the code should be able to understand the logic as well. But it's also sometimes good to have these comments in case if the code is complicated. Now the next option is to find problems in the code so you can provide a snippet of code and ask llama3 to figure out what problems are in the code. So we're going to use the Same code that llama3 has been updating and ask it to find problems in the code. Let's see if it can actually make any further improvements. Alright. Okay, so, so it says issues found, lack of error handling. And yeah, I don't see any error handling in this code and type hinting. Okay, so These are the two things that llama3 is recommending, but let me show you what actually is happening behind the scene. So basically whenever you select one of these four or five options, it sends the user command, which is, let's say find problems along with the actual context or the code that you selected. Right. So very simple prompting is going on. Nothing really crazy, but in this case it was able to add some error handling. Let me see, where did it add the error handling? So this is I guess the only place where it added some error handling. It says check if the re ranking. The re ranking model is valid or not. And it says explanation. I added a type hint for the retrieved documents parameters as list. Yeah, it is actually a list of documents. So this is good. And then I removed the default methods from re ranking model dictionary and instead added a check to raise a value error if the re ranking model is not one of these expected values. But I don't want that. I want if. If the user doesn't provide a default model, rather than raising an exception, we are going to basically return the chunks in the same order. Right. So I'm not going to implement this suggestion, although this, the suggestion that it has recommended makes sense, but not in the context of the implementation that I'm trying to achieve. Okay, for the last option, which is the unit test, writing this could be extremely helpful, But I think 11 needs to have a lot more context for this to work on your code base. So I selected a streamlit app that I'm trying to implement as a part of local GPT improvements and let's see if it can actually write working unit tests. Alright, so it took different segments of the code that I'm providing and started writing unit tests. Now, by looking at the unit test that I see here, this does make sense. And yeah, I think this could be something that they can definitely use in the code. Now, not for this specific part of the code, because this is just creating a streamlit app, but in general I think these could be extremely useful. Okay, so this is how you use it, but let me show you if actually with all the changes that we have been making, if this thing actually works or not. So I'm creating a whole different series of videos in which I'm documenting the whole process, but we're going to just run the streamlit app. So for that we're going to run the streamlet run and then app_streamlit v2.PI. And let's see with the changes that I haven't actually tested or we're going to see if it has broken any code or not. Okay, so we uploaded a document, it is able to process it and I'm going to ask it what is this document about? And we get a pretty good response regarding the document. Okay, so the code changes seems to be working. There you have it. It's a very simple and very easy way of using Lama T as a copilot in VS code. Now, in a subsequent video, I'll also show you how to use the same models using LM Studio or Ollama. That's going to be truly local implementation of the copilot, but at least the Groq API is free for the time being and it's blazing fast, so I'll highly recommend. If you are a programmer or you're learning programming, make sure to check this out. This could be a very valuable resource when it comes to both improving your code as well as learning how to program. I hope you found this video useful. Thanks for watching and as always, see you in the next one.










