Intensive Topic Research with AI and Recursive LLM Calls (Free Tool)
In this post, I want to introduce a new AI tool I’ve recently developed.
It’s designed to help you conduct intensive topic research, complete with search metrics, and create blog post drafts directly on WordPress.
Something like this:
The best part is that this tool, along with its source code, will be available to you completely free!
Topic Research Tool in Action!
Let’s Start with a simple demo of the tool:
The concept is simple: you input a topic you want to research, and the tool uses recursive LLM calls to perform in-depth research with AI, generating hundreds of related subtopics organized and interconnected in a graph structure.
But that’s not all – it comes with additional features like fetching keyword data for each generated topic and automatically creating and publishing blog post drafts on your WordPress site.
How does this tool help?
Before we dive in and run the tool, let’s explore some of its benefits.
This tool can be super valuable for:
- Conducting master’s and Ph.D. level academic surveys and research
- Generating blogging ideas and drafts
- Automating SEO processes
- Brainstorming YouTube content ideas
- Building your topic research tools on top of this tool.
- Offering freelance services based on this technology
We’ll go into more tips, ideas, and ways you can monetize this tool later in this post.
How to use this tool?
First, ensure you have Python installed on your computer. Then, click on the link below to download the project files.
Once downloaded, open the files with your preferred IDE. I use Visual Studio Code, but feel free to use whichever editor you’re comfortable with.
Get Your Environment Ready
Start by creating a virtual environment and installing the libraries. So, open a new terminal and run the following step-by-step:
1- Create the Virtual Environment:
python - m venv venv
2- Create and Activate the Virtual Environment:
venv/scripts/activate
3- Install Libraries:
pip install -r requirements.txt
Now that we have a virtual environment with the necessary libraries installed, it will help isolate the project and avoid conflicts between package versions.
Run this tool
To run the tool, enter this command:
streamlit run ui.py
Getting Keyword Search Metrics
If you only want to do topic research, you are good to go from here.
However, if you want to get keyword data and draft blog posts, bear with me a little longer 🙂
How to Get Keyword Data
To get keyword data, you need to use a trusted source, such as the Google Keyword Planner API, Semrush API, SpyFu API, or any other reliable API.
In my case, I am using my own Keyword Metrics API hosted on RapidAPI.
If you want to try it, you will need to get the API key from here:
Then, add it to the .env
file like this:
RAPIDAPI_API_KEY = "99d728b8e3msh2345tfdgdfsf1c170eb"
If you prefer using other APIs, change the following function in the helpers.py
File:
def get_keyword_metrics(keywords): rapid = RapidAPIClient() response = rapid.call_api(api_url=f"https://bulk-keyword-metrics.p.rapidapi.com/seo-tools/get-bulk-keyword-metrics?keywords_count=20&query={keywords}&countryCode=US") return response
Automatic Blog Post Drafts
If you want to create post drafts automatically, you will need to generate an application password from your WordPress dashboard.
Navigate to users, click on your admin user, create an application password, and then add it to the .env
file like this:
WORDPRESS_URL = "http://data-tools.local/" WORDPRESS_USER = "admin" WORDPRESS_APP_PASSWORD = "AaM7XsSe3x51RKLe3ccogilp"
💡 Pro tip: You can use LocalWP to run a local WordPress website on your PC for testing. It’s free.
Recursive LLM Calls 🔁
The core of this tool, topic research, is built on the concept of generating topic ideas on multiple levels.
Let me explain:
If you open ChatGPT now and ask it to generate the top child topics for “Quantum computing,” with a special prompt like this:
as an expert in keyword and topic research specialized in {topic},
generate {count} sub topics to write about in the form of SEARCHABLE keywords
for the the following parent topic: {topic}
It will respond like this:
Then, if you ask it to generate a list of child topics for one of these topics, like “Quantum Computing Algorithms,” it will respond like this:
So, you are digging deeper and discovering child topics for each topic.
I automated this process with a recursive function that keeps calling the LLM to generate topics based on the parent topic.
I used SimplerLLM to make my life easier when creating the project.
Here is the code for running these recursive calls:
def generate_subtopics_graph(graph, topic, current_level, max_level): if current_level > max_level: return print(f"Level {current_level}: Generating subtopics for '{topic}'") subtopics = get_topic_children(topic) for subtopic in subtopics: print(f" Adding edge from '{topic}' to '{subtopic}'") graph.add_edge(topic, subtopic) generate_subtopics_graph(graph, subtopic, current_level + 1, max_level)
And this is the get_topic_children
Function:
def get_topic_children(topic :str, num_results = 3): prompt = sub_topics_prompt.format(topic=topic,count = num_results) response = generate_pydantic_json_model(model_class=SubTopics, prompt=prompt,llm_instance=llm_instance, max_tokens=1024) return response.sub_topics
I used generate_pydantic_json_model
from SimplerLLM to get the list in JSON format, making it easy to loop and call each topic with my script.
Bonus Tips & Features
Let me share some advanced tips to help you get the most out of this tool and even monetize it!
First, you are not obliged to use OpenAI. You can change the provider by changing this line:
llm_instance = LLM.create(provider=LLMProvider.OPENAI,model_name="gpt-4o")
This is the power of SimplerLLM!
Second, when starting with the tool, it is better to test with 1-2 levels to make sure it works, then you can test with more sub-levels.
Third, this tool can be an excellent prototype or MVP for a SaaS.
By adding features like saving data for each user and adding an authentication system, or maybe recreating it with NextJS, you can turn it into your next online business.
You can also turn it into a simple tool on WordPress and monetize it with a points system, as I do with the tools on my website.
Remember, if you need help running this tool or have any questions, I will be available almost every day on the forum 🙂
Have fun!
Hi Hasan,
First of all thanks for posting this free super helpful tool.
I ran an online education blog and this tool is perfect for me doing more research and grow my blog.
I’ve followed the installation process as you described (except for some tweaks in the requirements.txt file, I’ve installed a lower version of the pydantic and the requests as the installation process was throwing some errors) after that, apparently everything worked fine until I started searching for any topic, that’s when after waiting some time this error came up:
Failed after 3 attempts due to: Error code: 404 – {‘error’: {‘message’: ‘The model `gpt-4o` does not exist or you do not have access to it.’, ‘type’: ‘invalid_request_error’, ‘param’: None, ‘code’: ‘model_no
t_found’}}
AttributeError: ‘str’ object has no attribute ‘sub_topics’
I got my API from OpenAI and created the .env file as you mentioned, but now I don’t know what else to do. Hopefully I can get some of your guidance.
Kind Regards,
Abel
HI Friend, please join us on the forum to follow up properly
Hi Hasan,
Can i add this tool in wordpress frontend, i need my users to can use this tool for free