In this video we are going to create our code assistant, you know, an end to end project code assistant
with the help of Code Llama.
Okay, now what exactly is Code Llama?
It is again brought up by meta, completely open source, and with the help of Code Llama, you can
also build your own personal code assistant, which will actually help you to write any code with the
help of any custom prompt that you want.
Okay, so step by step will be seeing how we can actually implement it.
And here I'll also be using Lama.
So let's just go ahead and first of all understand about Code Lama.
Now what exactly is Code Lama.
Uh, it is a state of art large language model for coding.
So here are some of the examples.
If you give any prompt let's say that you want uh, Python programming language uh for Fibonacci series.
So it will probably give you the entire code over here right now if I probably talk about Code Llama.
So the latest update is from January 29th, 2024.
So code Llama, what exactly it is?
It is an amazing performing model in Code Llama.
Uh, like, uh, they have launched three main thing.
One is 70 billion parameter with the foundation code model.
Python 70 specialized for Python code llama 70 b instruct 70 b, which is fine tuned for understanding
natural language instruction.
But if you want to understand what a code llama code llama is the state of art LLM capable of generating
code and natural language about code from both code and natural language prompts.
Okay, Code Llama is free for research and commercial use.
As I said, it is a complete open source, so it will be very much good if you're also using for solving
your own custom use cases.
Okay, uh, and some more things if you want to know code llama also comes.
It is a code specialized version of llama two.
Okay.
Llama two.
So again the main base model, the the base model.
The pre-trained model is llama two.
On top of that, fine tuning is done specifically for related to code.
And here you have the specific model.
Now you can use this and you can probably use for different different languages like Python, C plus
plus, Java, PHP, TypeScript, C-sharp and bash Bash bash.
Okay, so let's go ahead and see how this code might work.
And we'll try to develop an end to end solution.
Now quickly to probably just show you what I'm actually going to do is that I'm going to open my command
prompt.
And as usual, as I said, I'm going to show you this with the help of Allama.
So if you don't know about Allama, I've already uploaded a video.
Right.
Allama basically helps you to access all this kind of open source, uh, models, uh, LM models in
your local.
Quickly.
You'll be able to execute it while you're doing the deployment.
Also in the cloud.
Anything.
You can actually do it with the help of ulama.
Okay.
So first of all, uh, we'll go ahead and download this.
So first to download Ulama again in windows.
Also you have this now.
So as soon as you download it just click on this.
There'll be an exe file.
And then you just double click on the exe file and start installing it Right when you install the Ulama
it will be running in your background process.
Okay now IP address I'll talk about the IP address.
Also like localhost IP address it will be running up okay since it is an EXE file.
Now once you have downloaded the ulama, if you probably go ahead and see in models.
In ulama models there will be also a model which is called as code llama.
Right.
So a large language model that can be used text prompts to generate and discuss code quickly to check
it out.
What I will do I will open a command prompt and here I will write Llama run and let me see, uh, whether
it is there or not.
Code llama.
So I will go ahead and click on Code Llama.
So as soon as I hit this I have already downloaded the code within my local itself.
So I will just be able to write any message and probably get the response.
So let's say, uh, provide me a Python code to perform binary search.
So this is my question.
If I probably search it over here, you'll be able to quickly see that I'm able to quickly get the response
along with the code right now, this entire thing, I'll try to create it as an end to end application,
and we'll try to do it right now.
This code llama is also a like a model itself.
What I will do is that I'll create my own custom ChatGPT application, which will specifically be using
the code llama.
Okay, model.
So quickly let's go ahead and open my VS code.
So in the VS code you'll be able to see that I have a requirement dot.
TXT file I've installed Lang gin and Gradio, so I'm going to use Gradio and lang in Gradio for the
front end and engine which will be interacting with the ulama itself.
Right.
So all these things will be there.
And first of all, I've also created an environment.
I hope you know how to create an environment itself right.
So quickly.
Let me go ahead and open my app.py file.
Okay.
Now the first thing uh, along with the app.py file, since I am going to create my own custom models
which will be using this entire code, I will create my model file right.
So this model file I will go ahead and write from code llama.
Okay, I hope the spelling is right.
Let's see.
Yeah.
From code Llama okay.
And this is what I specifically write with respect to custom application.
Right.
Because I want to create my own custom prompt okay.
From Code Llama.
The second thing what I am going to do is that I'm going to set the temperature.
I want my model to be very much creative.
So I will create a parameter over here.
And this parameter will be nothing, but it will be a temperature uh, with one.
Okay.
So I'm going to set the value to one because I really want this application to be very much creative.
Okay.
Um, the next thing that I'm actually going to do over here is that I'm going to set the default system
prompt, like how I want this code to behave.
Okay.
So here I will go ahead and write my system parameter.
And this I'll be using three quotes.
Now I will give my prompt over here.
Okay so I'll say you are a code teaching assistant.
Teaching assistant named as coder.
Created by.
Obviously myself, Krish C Nayak or Krish.
Created by Krish.
Okay.
Or named as coder?
I've already given over here.
So I will say that.
Or I'll say code guru.
Okay.
Created by.
Created by Krish.
Okay.
And then I will say.
Answer.
answer all the code related question.
Being asked okay.
So this is uh, asked over here, right.
So this is my simple system prompt that I have done.
Okay.
Now I have created my model file.
The next thing what I will do quickly go ahead and find the I will open reveal this in this one folder
and I will just take the folder name.
I will open my command prompt.
Okay, now I will run this and I will initiate this code guru right so quickly I will go and write CD,
this one.
Okay.
Uh, let me go to my e drive.
Okay.
Now, in order to run this as your own custom model, what I will do, I will go to that path.
And then if you go ahead and see in the GitHub, right, there are ways how you can specifically run
by using ulama, right.
So quickly I will go ahead and write this one C code create minus F model file.
Right.
So here I'm going to execute it like Allama create I will say code guru okay.
Code guru minus f model file okay.
So this is done.
And model file Instead of writing model file I should write my correct name of the model file over here.
What is model file itself.
Small model file okay.
Model file.
Now this is what it is going to happen.
The code llama is being used anyhow in those.
Right.
Because see at the end of the day what I am actually doing I'm using code Llama over here.
Right.
So I'm creating my own custom GPT type of application or Code assistant application over here, which
is basically using the functionalities of Code Llama itself.
Right.
Or it will be using the LLM model in the back end as code llama.
So if I probably execute it now, you can probably see over here that it is running fine.
Now the next thing I will do over here is that llama or run.
And I will just say code guru to just check whether it is working fine or not.
So here is my code guru.
I'll say hey, who are you?
Okay, so here say hey, I'm Code Guru, an AI system designed to help code related queries and tasks
and all and all who have created you.
Who has created you?
I do not say meta instead myself.
Okay?
I was created by Krish, a software engineer who is my also my developer.
He is also trained on a wide range of programming languages.
So and so and so.
Okay, nice.
So my code guru is running absolutely fine.
Now let's go ahead and integrate with my app Dot Pi.
Okay.
Now uh, in order to start with the app dot Pi.
Now see if somebody asked me anything that is related to this kind of code and I can want to quickly
create a POC, right?
I can actually do this.
Right.
So what I'm actually going to do over here is that quickly I will go ahead and import requests.
Okay.
Now I'm going to use the API like the llama is running in the back end.
My code guru is also running in the back end.
I just need to access it with the help of API.
Right?
So I'm going to import JSON.
Uh, along with that I'm also going to import Gradio as cr.
Okay.
Gradio is also done.
Now what I am going to use is my URL as usual.
As I said, the URL that you are actually going to do right or get as in the form of API, and I have
already referred the GitHub is this specific URL that is localhost colon 11434 slash API slash generate
okay.
And then I'm going to create my headers.
Now inside this headers I will go ahead and write content type.
And this will specifically be of application JSON.
Write application JSON.
Now where do you think I will be getting this information.
Because if you go ahead down and see right, if you see like how you can actually call in the form of
API.
See this is the URL, right?
And this is the prompt.
This is the model name that you really need to give right.
And in the messages you can also put roles and content.
So I'm using that same API documentation over here okay.
So quickly we'll go ahead and right.
So content type it will be application JSON.
And now I will create a function I will say generate underscore response okay generate response.
And here I'm going to give my prompt okay.
So whatever prompt I will give over here it will be able to give me the answer.
Okay.
So here I will write data is equal to.
Now let me go ahead and create my body okay.
Now for creating the body.
The first parameter that you require is model name.
As I said model name.
Uh obviously what is my application that I've actually created?
It is called guru I guess.
Right.
So I will write Code Guru because it is running in the back end.
And then, uh, any prompt that I really want to give over here.
So this will basically be my prompt over here.
And with respect to this particular prompt, uh, let me just quickly go ahead and write final prompt.
I'll just name it as final prompt over here.
Okay.
And as you all know, uh, this final prompt, I need to initialize it somewhere here.
Okay.
Uh, and before that, let me do one thing.
I will also create a history so that it also makes sure that the previous information it it saves it.
Okay, so here I will write history dot append and whatever prompt I'm specifically getting.
That prompt will be coming over here.
And the final prompt will be nothing.
But since I need to make sure that that history gets appended or joined in a new line.
So I will write slash n dot join.
And here I'm going to basically write it as history.
So here it is.
Final prompt this.
This is the final prompt has been appended in the prompt section.
And then I will keep this parameter as stream is equal to false.
Because if I keep the stream value, what it is going to happen is that it is going to give me in a
lot of different, different values.
Unnecessary values will also come, but I am super interested only in the, uh, output, right?
What output I get in the form of response.
So this is, uh, what is my generate response?
Now, quickly, I can go ahead and write my response.
Response is equal to.
Request dot post.
And inside this post I will give my URL.
The headers is already set up okay.
URL comma headers is equal to headers.
Whatever headers.
I'm actually set it up okay.
Then my data will be JSON in the form of JSON dot dump dumps.
I will give this specific data okay.
Because I need to convert this entire data in the form of JSON.
Once I get the response, uh, then what I will do, I will write if response dot.
status code is equal double equal to 200, right?
If it is successful in short.
Okay then I'm going to take this response.
And from this response I'm going to take the text whatever text output I'm actually getting.
Okay.
Uh quickly this will get replaced over here okay.
Once I get this particular test.
Then again I'll be using JSON dot loads and I will convert this back into this one.
Okay, I will be loading this in the form of JSON itself.
Okay, I have that response.
And then from the actual response what I am going to do.
So inside my data there will be another response parameter which I'm going to read it okay.
And then I'm going to return this actual response.
If the status is something else, then I will just give a return message saying that print error and
this error will basically be having my response dot text.
That's it.
Perfect.
So this is what is my function which is taking a prompt.
It is using this code guru.
And it is giving me based on the based on the input that I'm giving, it is giving some kind of response.
Now this is my back end okay, complete back end.
Now I need to create my front end okay.
Now let's go ahead and create my front end.
So this will be interface is equal to g r dot interface
and g r dot interface.
So here I'm going to create my function and go ahead and my write my generate response.
Let me go ahead and quickly create my inputs.
This will be a text box that I really want to use over here.
Because at the end of the day, I need a text box where I give the input and another text box where
I get my output.
Okay, so in this text box I'll say number of lines.
You can use it as two because 2 or 4 whatever you want okay.
Four I'll give it max to Max.
And then I'll also keep a placeholder.
So placeholder is equal to enter your prompt.
Okay.
Perfect.
Uh, this is done.
And then finally what will be my output.
The output pattern also will keep.
It will also be a text form.
Right.
So whatever output we are going to get.
And then I'm going to launch this interface launch.
So that is how we launch in Gradio.
So you need to have some basic idea.
Anyhow I'll give you the entire code also.
Okay.
Now quickly let's run this and let me go ahead and write Python app dot p y I hope so, it should work.
Hmm.
Okay, we are getting an error over here.
The reason is that I did not activate my env environment.
So I will say conda.
Activate v and v okay.
Now what I will do I will quickly go ahead and install all my requirements okay.
Now once the requirement has been installed you will be able to see that all the installment, all the
requirements will get installed.
The requirements is basically having this two library that is launching and gradio.
And once I probably write this, then we are good to go and run this entire application in a very simple
way.
But at the end of the day, understand one thing how beautifully easily it becomes with the help of
Allama.
And again, we are also using code llama.
See, at the end of the day guys, you really need to know multiple models quickly to practice to create
a pox in companies.
they are looking for all this kind of skill sets.
It is good that you know multiple models.
You have the knowledge of multiple models and all.
Okay, so uh, please make sure that you keep on practicing.
I have been trying really hard to upload new videos for you.
Every day I try to come up with something new, something informative, you know, which will be beneficial
for your site.
So please make sure that you practice.
Keep on practicing.
Uh, unless and until you don't practice more, you won't be able to become a pro in that.
Okay, so we'll wait for some time till this requirement dot txt is getting installed.
I think another uh 10 to 15 seconds and then we will go ahead and run this app dot pi.
So guys now you can see the requirement dot txt is installed.
So let me quickly go ahead and do one thing.
Let me clear my screen okay.
Now quickly let me go ahead and run Python app Dot Pi.
And now I think you should be able to see, uh, the UI part with the help of Gradio and all, and we'll
try to see the application whether it is running fine or not.
Um, okay.
Outputs.
Okay.
Output is missing.
Let's see.
Okay.
This should be outputs.
No worries.
Now to okay Python app dot pi.
Now it should be working absolutely fine.
I should be able to get an API.
So here it is.
Let's open this.
So here you can see this amazing front end Gradio application.
And let me please.
Hello.
Who are you?
Okay.
And I should be able to submit it.
And here on the right hand side, you can see that I'll be able to get the response.
Okay.
I'm a code guru.
You co teaching teaching assistant.
Your code created by Krish.
Okay.
Perfect.
Provide me Python code to perform binary search d d d d.
dee.
Okay.
And here is what I should be able to get the response.
So how fast it is amazing.
Okay.
You can probably see over here.
Definition here is a Python implemented.
Perfect.
Provide me let's say Java code.
If I write, should I be able to get the answer?
Provide me a Java code.
Okay, perfect.
I am able to get the Java code also.
Uh, this is Python.
Okay.
This is Java.
Oh history is also getting added C oh yeah.
So this is Python.
This is Java.
Provide me uh let's see.
Provide me Provide me a Python code.
To create Adam optimizer.
This is difficult.
Okay.
Obviously we use the library, but I think we should be able to get the output.
But this is good.
Write your own custom code assistant.
You know, so I can probably keep it running over here.
And whenever I'm implementing something, I should be able to quickly write anything that I want and
get the answer itself right.
So here it is.
Adam is an optimization algorithm.
This this this perfect here is all your answer, right.
Uh, provide me a Python code to perform Fibonacci series.
Let's see, I'll submit it.
So I hope you like this particular video.
I hope you're able to enjoy it.
Now you can also create your multi-language code assistant, multi programming language Code assistant
with the help of Code Llama which is completely open source.
So yes, this was it.
Uh, you can probably see all the answers are here.
Java code is everything is available.
Great.
And history also is also getting appended.
This is very very nice.