What is Dify AI?
Hey there, welcome back to AI Code King. Recently I found out about this open-source project called Dify. I've been seeing that it's trending on GitHub, so I thought I should cover it. So let's talk about what Dify is and how to use it.
When you see Dify's GitHub page, you might get misguided by the terms they use like apps, software, and whatnot. Many people may start thinking that it's something that can make apps for them. Well, that's not true at all. Dify is basically like LangChain with an interactive IDE, a better interface to interact with the workflows you create, and it doesn't require coding; it's all graphical.
If you don't know what LangChain is, let me explain it to you quickly. When a user gives a prompt to the LLM, it gives an output. But what if you needed to provide some context to the LLM for a RAG application? Or what if you needed to connect it to an internet search? Well, that can be done via some tools like LangChain or Dify. They make creating such workflows easy by letting you connect tools to your LLMs to create specific chatbots or specific LLM applications.
Dify AI's Core Features
Okay, now that you've understood the basics, let me tell you about its other features. You can get a very great-looking Studio through which you can create applications, workflows, chatbots, and agents all in one place. You can also create RAG pipelines with it. There's also the LLMOps feature through which you can check logs, fine-tune models, and multiple other things. You can also create automated agents with this.
You also have the backend as a service option, which basically means whatever workflow or chatbot you create can be connected to your own applications via API. You also get the workflow option, which is a relatively new feature. Through it, you can create your specific workflow applications. It has support for almost all of the LLM providers. This is an open-source project and it can be self-hosted.
Cloud Plans vs. Local Setup with Docker
But they also have a website where you can use it without self-hosting. To use their website, you have three plans. The first one is the free plan, through which you can send up to 200 messages for free to GPT-4, but you also have other limitations in this plan like storage and whatnot. So I'll be getting it set up locally.
Okay, so let's start the setup process. First, open their GitHub repo, then clone it on your computer. Once cloned, cd into the cloned folder. Then go back to the GitHub page, scroll down, and you'll see this quick start section. Go ahead and copy the first command, then run the second command. Remember, this requires you to have Docker installed, so make sure you have that. Anyway, run this command and it will start getting installed. After it gets installed, go ahead and open Local Host on your browser. Once you open it, you'll see this screen. You'll be asked to sign in, but we don't have credentials yet. So go ahead and click on this link and create an account. Once done, go ahead and sign in.
Using a Pre-Built App with a Local LLM (Ollama)
After you're signed in, you'll see the screen. Here you can see the options it has. You have the chatbot, agent, and workflow options. You also have the explore option here, where you can find community-created workflows and apps. You can just use any of them which suits you, or you can also create one from scratch.
Let's first try running a pre-existing app. I'll be choosing this SEO article generator here. Click on it and then click the create button. Now go back to the studio page, and here you'll find the app we just created. Now click on it. As you can see, it's asking us to set up the LLM provider here. Go ahead and click on the 'go to settings' option. Here you have multiple options of LLM providers. Let's set it up with Ollama for 100% local access. If you don't have Ollama installed, go to Ollama's website and get it installed from there.
Now here we are asked to enter the model we want to use. I'll be using Llama 3, so I'll enter that. Then it'll ask you for the API base URL. I'm using it on Local Host, and Ollama generally works on Port 11434, so I'll enter this URL. Now it will ask for the max context. Llama 3 allows 8K context, so I'll enter that here. Once done, click on the save button. Now the model will be added. Now close this and select the new model over here. Okay, now enter the keywords you want to generate the article about and hit run.
Okay, it works. So this is how you can get the pre-made template working.
Creating a Custom Workflow from Scratch
Now let's try creating our own workflow. To create our own workflow, click on the studio option, then click on the 'create from blank' option. Now you have four options here. The first one is chatbot, the second one is text generator, the third one is agent, and the final fourth one is workflow. I'll be using the workflow option here. Now enter the app name and description and hit the create button. I'll be creating an SEO article generator, so I'll enter that.
Now you'll see a drag-and-drop flow-like interface. Here you can see our start node. Now in the start, we need to take a custom input from the user. So go over here and add a new input variable and enter its label and max length. Once done, come back and click on the plus button here. Now you can add multiple nodes over here. If you want to connect it to an LLM, you can do that, or maybe if you want to do a Google search, you can do that. Or you can connect this node to anything you like. It has multiple options. You can even add a custom code option here to run your Python scripts. Pretty cool.
I'll be making a simple SEO generator, so I'll add an LLM here. Now select the model here, and in the context, choose the variable we just created in the start node. In my case, it's the title variable. Now enter the system prompt here about what needs to be prompted to the system. I have prompted it to write an SEO friendly article about the topic variable. Here to add a variable, use curly braces and add the variable here. Now that's done, add an end node here and in the output select the LLM text message output. Now let's run it. Enter the variable data here and hit enter.
Okay, it's getting generated. Pretty cool. So that's how you can create a workflow for your specific use case in Dify.
Publishing, API Integration, and Advanced Options
You can also publish the app from here, which can be used by anyone with the link through their interface. You can also use it with an API, which is really great if you want to connect it to your custom applications. You also have some other tabs here, like Knowledge. In this tab, you can add your custom knowledge here which can be referenced in your workflows and chatbots. You can also use the Tools option to integrate your custom tools and whatnot. I think it is a really great option to create your own AI workflows, apps, and just custom tools to integrate into your applications across the board. You can easily configure, test, and check your workflows. Pretty cool. I really like this one.
Conclusion and Final Thoughts
Let me know if you'll be using it too in the comments. Also, if you liked this video, consider donating to the channel by using the Super Thanks button below this video. Also give this video a thumbs up and subscribe to my channel. I'll see you in the next video. Till then, bye.