Introduction
This AI tool is designed for marketing teams to analyze forum content, gain insights into user pain points and interests, and help users quickly find summarized answers to their questions.
Background
Discourse is a widely used open-source forum platform for community discussions. It provides quick access to product details and user experience. However, its built-in search feature can be inefficient, often requiring users to sift through multiple posts to find relevant information, as only basic details are visible in the initial post previews.
This is where AI can play a significant role. We can leverage AI to filter the most relevant posts and provide concise summaries, streamlining the information retrieval process. This necessitates a comprehensive tool that integrates both frontend and backend functionalities, along with an AI agent. Rather than using separate tools for these tasks, we will utilize Momen, a full-stack, no-code platform equipped with a built-in AI agent editor, to develop this AI search assistant.
Overview
Below is an overview of the project’s workflow.
Final Outcome
This is how this assistant works. When you input a question, the AI will search the relevant information based on generated keywords and show how it identifies them, then generates the answer with attached reference of the original posts.
Step-by-Step Guide to Fetching Forum Data Using the Discourse API
Instead of solely relying on the Discourse API documentation, we can directly obtain API endpoints through the console’s Network tab. By selecting a request, we can right-click to copy the cURL command and import it into Postman for debugging.
In Momen, we will create an API configuration. Open Momen’s API settings, add a new API, and utilize the debug feature to quickly import the API structure.
Filtering Data with RAG for Better AI Performance
RAG is a critical step in AI applications. RAG is the process that AI references an authoritative knowledge base outside of its training data sources before generating a response.
In our project, the raw data provided to the AI comes from the API’s returned post information, which often contains unnecessary details. The purpose of RAG is to extract only the relevant information for the AI’s processing. For instance, the data returned from the API has the following structure:
{"posts": [{"id": 123333,"name": "B J Gibson","username": "b.j.gibson","avatar_template": "https://avatars.discourse-cdn.com/v4/letter/b/7cd45c/{size}.png","created_at": "2018-05-22T00:53:34.480Z","like_count": 0,"blurb": "Hi All, have hit a bit of a hurdle in permissions when building the apk file in android studio. Has anyone been able to request multiple permissions when using @natedogg wrapping course code? the cod...","post_number": 1,"topic_id": 29850}// ... (truncated)],"topics": [{"id": 29850,"title": "Permissions when wrapping through android studio","fancy_title": "Permissions when wrapping through android studio","slug": "permissions-when-wrapping-through-android-studio","posts_count": 1,"reply_count": 0,"highest_post_number": 1,"created_at": "2018-05-22T00:53:34.390Z","last_posted_at": "2018-05-22T00:53:34.480Z","bumped": true,"bumped_at": "2018-05-22T00:53:34.480Z","archetype": "regular","unseen": false,"pinned": false,"unpinned": null,"excerpt": "Hi All, \nhave hit a bit of a hurdle in permissions when building the apk file in android studio. Has anyone been able to request multiple permissions when using @natedogg wrapping course code? \nthe code includes: \nuses-p…","visible": true,"closed": false,"archived": false,"bookmarked": null,"liked": null,"tags_descriptions": {},"category_id": 21,"has_accepted_answer": false}// ... (truncated)],"users": [],"categories": [],"groups": [],"grouped_search_result": {"more_posts": null,"more_users": null,"more_categories": null,"term": "permissions","search_log_id": 5123844,"more_full_page_results": true,"can_create_topic": false,"error": null,"extra": {},"post_ids": [123333,// ... (truncated)],"user_ids": [],"category_ids": [],"group_ids": []}}
If we provide the AI with the entire API result, it could exceed the maximum input limit, and the AI’s responses may be influenced by irrelevant information. Therefore, we will only pass the title and excerpt to AI. In Momen, we can create a JavaScript function in the Actionflow to wrap the API response:
let page = context.getArg('page');
let q = context.getArg('q');
const api_res = context.callThirdPartyApi('m2aaiw05', {q: q,page: page
});
const posts = api_res?.data?.topics || [];
const post_list = posts.map(item => ({'title': item.title,'excerpt': item.excerpt
}));
context.setReturn('post_list', post_list);
This entire Actionflow takes the search keyword and page parameters as input and outputs a list of titles and excerpts.
Input
Output
Additionally, as initially planned, we need to create another API to retrieve detailed post information from https://forum.example/t/272047.json
. Following the previous steps, we will create an API for retrieving detailed post information and extract the complete content along with all comments, packaging it into an Action flow. In the image below, content_detail
represents the entire object, which includes the main content and the list of replies.
Implementing the Final AI Search Assistant Agent
Prompt
We will first create an input that represents the user’s potential question. Then, we fill out the prompt according to three areas: role, goals, and constraints, placing this input in the appropriate sections.
Tool
Utilizing tools is a crucial part in building AI agent. We need to make the two Actionflows (get details via API and search via keywords) we created earlier available to the AI as tools. In the tool configuration area, we will select these two tools and provide descriptions to help the AI understand their purpose and usage.
At this point, we realize that the AI needs the topic_id
parameter to use the "get details" tool, which we have not yet provided. Therefore, we need to modify the first Actionflow to output the topic_id
alongside the title and excerpt.
Then, we will continue configuring the second tool.
Now, we can perform preliminary debugging to verify if the AI functions as expected.
Output
To enable AI to interact effectively with code, a JSON format is essential. In Momen, we will transform this step into a visual configuration operation. By clicking on “custom,” we allow the AI to output the desired JSON format. The description helps the AI better understand what the output should convey. With a more standardized output format, we can observe the AI’s thought process more clearly.
Frontend Configuration
Now that all previous steps are complete, we can utilize Momen’s built-in database functionality to record each question and answer, displaying them on the frontend. The button’s logic operates based on the user’s question, running the AI, saving the result in the database, and extracting the latest outcome. For details about configure frontend logic of AI, refer to https://docs.momen.app/features/ai-feature-configuration/zai-configuration
Experience the Final Effect
Let’s take a look at the final output.
Build with Momen today: momen.app