December 202310:0727.1k views

Cody: the AI assistant that actually knows your codebase

About

I tried Cody across a couple of different codebases and was super pleased with the way that the context worked. It felt like it actually understood my projects moreso than any of the other assistants.

Thank you to SourceGraph for supporting the channel!

Transcript

Everything I said

00:00

A few weeks ago, the team at Sourcegraph reached out to me and they're like, "Do you wanna make a YouTube video about Cody?" And I was like, "Yeah, I would love to make a YouTube video about Cody." And you may be thinking, who is Cody and what is this video going to be about? A better question is, what is Cody? Cody is an AI coding assistant, and it's just totally free for personal use, which is kinda crazy.

00:20

You can pay for it for your enterprise, but for personal use, it's just free forever, which is kinda wild. But more interestingly, I think, is it knows your code base. So it, like, ingests your entire repo, and that gives it context to answer the questions instead of just kind of making stuff up, which can be super frustrating.

00:40

So let me show you how it works here on the Laravel repo. I've just pulled down the entire Laravel framework, and, eh, we're just gonna start asking it some questions. So whenever you enter a new project and you're like, "Ooh, I don't really know what's going on here," this might be a good use case for you. So I've got the repo open in VS Code here, and I've just named it Laravel Cody because my creativity knows no bounds. And I'm gonna open Cody, and we're gonna start chatting with the code base.

01:03

Instead of using Claude 2.0, or is it Cloud? I'm gonna use ChatGPT-4. This is one of the things I do like, is it lets you select the model. Presumably, as new models come out, I just get to, to use them. I don't have to, I don't have to do anything. So I like that they let you choose the model. Um, and then down here, you can enable that enhanced context, which is where it knows your entire code base.

01:26

And so I've en- enabled those embeddings, so now we can just start chatting. So I can say, um, "Can you give me an overview of this repo?" Coming into a brand-new code base, this would be really, really useful to kinda get an overview, especially when there's no documentation or README or something like that. One of the things that I super love about Cody is it cites its sources.

01:51

So one of the things that's really frustrating with AI is sometimes you feel like it makes stuff up. But here, it tells you where it got or some of the places it looked for its information, and you can go dive in and look at those same places. So let's see how it did. Um, yeah, I mean, this, this is right. This is right. It's telling me everything about Laravel.

02:11

Um, I imagine it's pulling a lot of it from the README. So it looks like this probably came from security. This came from the license. Um, this is interesting 'cause it's not specifically laid out in the README. It's just the repository structure. And yeah, this is all, you know, this is all right. If I didn't know this code base, this would be more interesting, but this is not interesting to me, so let's just clear the screen, and let's do another one.

02:36

Let's go to ChatGPT-4 again, and I wanna say... What do we wanna do? Um, how do I add a scope to a model? Let's see if it can figure out how I can add a scope to a model. So it looks like it read 15 files, um, and I'm very curious to see what this comes back with. So it looks like to add a scope, you need to define a method with @scope prefix.

03:03

That is correct. Ah, and it's actually writing out a scope for me. This is great. Um, so it tells me all of the steps, which is nice. You know, if I, if I were to read, that would be really helpful. We don't read. Developers don't read. You should read the docs, but we don't read. So moving on, it shows me exactly how to do it, and it actually got the doc blocks right and everything. And then it shows me how to use it.

03:25

So that's pretty cool. Um, yeah, remember, scopes are chainable. Yeah, very cool. Now, I kinda asked it a, a specific question, right? Like, I knew-- I know what the word scope means. If I'm coming into a project and I'm not super familiar with Laravel or, say, I'm opening a Rails project for the first time and I'm trying to figure something out, what I would probably ask is something more like, "How can I..." Let's see.

03:52

What would I say? How can I create a bit of a reusable query on my models? Let's see how that does. So instead of using the specific, like, jargon word of how do I create a scope, I say like, "Hey, here's what I'm trying to do. How do I do it?" And yes, thank goodness, it nailed it.

04:13

Um, this is great. So you can create reusable queries by defining query scopes. A scope, so it, it picked up that word for me. And then it goes on to say there are local scopes and there are global scopes. And it shows me, um, a couple of instances of a local scope, how to use it, and then a couple instances of a global scope and how to use it, which this, this is great.

04:34

This is exactly what I'm looking for. Um, and it's continuing to go on with the global scope and shows me how to-- oh, that's nice, how to turn off a global scope as well. It's just, it's continuing to, it- it's just continuing to produce. I didn't know if I knew about anonymous global scopes, so this is pretty good, right? But there's a lot of content about Laravel out there, and I feel like, I don't know, it's kind of a softball.

04:57

Give it a huge well-known framework, ask a, you know, a medium level question, and it gets it right. We're gonna look at a repo that is slightly less well-known than the Laravel repo, and that is the personal and private repository for aaronfrancis.com. Not quite as much has been written about that. So let's look for something completely random, completely esoteric, and boy, do I have the file for you.

05:20

It's called BladePortal. Now, imagine if Laravel Blade had portals. That would be pretty cool. Would it be useful? Not super useful, but it would be very, very cool. And so I wrote that. Now, BladePortal, never been seen before. Nobody has any context on it. I'm gonna highlight the whole thing and ask Cody. I don't want Claude.

05:40

I wish it would stay on ChatGPT-4. I'm gonna ask Cody, uh, "What is going on here?" And it's gonna take that context and send it off, and it's gonna figure out what is going on in this completely novel bit of code. And it says, "It's a utility for managing content placeholders and portals within Laravel Blade templates." It tells me what Blade is, and then it gives me a breakdown of the entire class.

06:05

And you can see it looked a few other places for context. Um, I don't know that it got anything valuable out of any of these. Maybe in, uh, this one it registers a service provider, but it looked at a few places. But mo- most importantly, it looked at this entire file, and then here is, here's the overview. Here's the documentation that I didn't write for BladePortal.

06:27

Um, BladePortal Eh, I don't know. I don't think it's that useful. Uh, it's kinda cool. Uh, maybe I'll do a video on that someday. But the important thing is Qody figured it out. It's never been published before. I sent it off, it came back with some actually useful information. We've been using Qody to understand code, which is nice, but why understand code when you can just write bad code and have the computer fix it?

06:48

That's a joke. You need to understand your code. But anyway, let's say we open up Qody here, and we say, "Show me the smells in Blade Portal." And this is gonna look through the Blade Portal file and figure out what some of the code smells are. There's a, a document code command, there's a generate tests command, and there's one more that I'm gonna show you, which is just, like, kinda clean up or, or make the code better.

07:13

But here's the result. Here's the result from the smells, uh, command, and it says it's generally sound OOP, which that's what I'm looking for. I just want a computer to tell me I'm doing a good job. It does tell me, "Hey, here are some things that you can fix." The last thing I wanna show you is some actual code generation here. So here we are in the command that puts the articles on my website. It just looks in a views articles folder and then does some stuff.

07:36

But what I'm actually looking for is, yeah, actually that right there. I'm actually just looking for markdown. So it figured that out, and it wrote that for me. I could say, you know, something like, "Ignore hidden files," and drop down here, and there you go. It would do that. But since we restricted it to markdown only, I don't super need that. So it does do that auto-completion. And then very interestingly, I can come down here and highlight this bit of code and hit Command + Shift + V, and then I can tell it to do something with this particular bit of code.

08:05

And I can say, "Combine these filter and reject, uh, functions into one function." And it's gonna work on that. And so the thing here is I'm mapping over this collection twice, and, you know, I don't really need to be. And so it's gonna do something and then put it back together.

08:26

So now I'm filtering to say if it has an ID, well, it has to have an ID, and if the app is local, that's fine. Otherwise, it can't be a draft. And so it combined those two, um, it combined those two callbacks into one callback, which in this case doesn't super matter. But this is a nice way to refactor, to say like, "Hey, here's the code I have.

08:47

I'm gonna tell you what to do. You write the first draft, and then I'll come in and do it again." And here it pretty much nailed it the first draft. I may do a little formatting change, but this is what I'm looking for. I can see this giving me superpowers on a project that I'm already familiar with or helping me get up to speed on a project that I'm not really that familiar with. Maybe best of all, maybe the best use case is when I open a project that I wrote and I haven't touched in six months.

09:11

There's no worse coder in the world than me six months ago. Not today, six months ago. And so instead of looking at this code and thinking, "What did I do here?" I can just ask Qody, "What did I do here?" And it will tell me. If you're watching this video, which logically you must be watching this video, then Qody is generally available. As of December 14th, it is generally available. I have found there are a few rough edges.

09:31

Sometimes the models time out. Sometimes it grabs weird context to send off. And I just kind of run it again, and it works. I do wish the PhpStorm integration was a little bit better. I know that they're working on it. Um, but everyone in the world uses VS Code except for me. So the VS Code one is great. The PhpStorm one is coming, but they put most of their energy into VS Code.

09:51

So try it out. Go to sourcegraph.com/qody. Let me know what you think. Leave very nice comments here for the Sourcegraph team. I really appreciate them, um, sponsoring the channel this way. So try it out. Let me know what you think. See ya.

AI & agents

More videos on AI & agents

All videos

Get the next one by email

I’ll send you some more. Not too many.

Join 7,500+ other readers.

Read past issues