Surprisingly, I am finding more difficulty working with the front-end stuff than with the actual AI generation stuff.
Tweaking the UI still takes me a couple of hours, while creating full-on LLM chains takes me no more than a couple of minutes.
And I think there are two reasons for this:
1. Unlike JS, I already knew how to code in Python.
2.
@langchain makes everything so simple and easy that it's not even funny.
For example, take a look at the first feature I am working on.
The entire backend code was done in 5 minutes or less.
Here's how I did it step by step.
As you'll see, the code is indeed very simple, so feel free to bookmark this and it revisit later when you start building your own AI apps.
1. Imports
First things first, let's start with the basic imports.
Since we will be using the chat model, I will use the templates that include the system message and the human message.
The new models from Open AI now have increased the steerability of the system message, and so I want to make sure that I take advantage of this.
But you could simply import the standard PromptTemplate if you wanted to use fewer lines of code.
2. LLM
Since we will be using ChatGPT 3.5 model with a 16k context window, let's make sure to create it.
The good thing with Langchain is that you can do this with only two lines of code.
3. Prompt pt. I
Now let's create a variable to store the prompt we have created for our feature.
This prompt will be called as a system message anytime we use the feature in the app front-end.
This particular prompt is quite long and detailed, as you can probably tell already. But this is only because we are trying to do something very specific.
Simpler tasks will require simpler prompts, so adjust yours accordingly.
PS: This is the exact same prompt as my last breakdown by the way.
4. Prompt pt. II
Next up, let's finish the entire prompt.
We do so by creating the human msg prompt (which will be simply a basic one) and stringing together the system message and the human message templates to create the complete chat prompt.
5. Create the chain. (code in the comments due to twitter image limit)
And now that all of the hard work infrastructure work is already handled, let's create the LLM Chain.
Simply follow the code above to create the LLM chain and call it with whatever text you want to run through this specific prompt.
Now, my next step is to connect this backend code seamlessly with the UI.
The FastAPI connection is already up with this particular endpoint. So hopefully with can hit the
Stay tuned for the next updates.