Feature description:
Add a key to the object returned by the Discourse AI tool API discourse.getUser function that provides the number of topics created by the user.
Current behavior:
Additional capabilities can be provided to Discourse AI personas by creating custom “tools” for the LLM to utilize. Discourse provides an API that can be used in the tool code.
Data about a user account can be obtained via the discourse.getUser function.
The object returned by the function has a post_count key. It turns out that, in the context of user stats, “post” actually means “reply”. Thus, the value of this key does not include the number of original posts of topics created by the user.
It would make sense to provide the data for these two distinct types of activity via two separate keys, but inexplicably the function does not return topic count data even though this is one of the primary user stats.
A complete picture of user activity can not be obtained via the discourse.getUser function. It will be inconvenient or infeasible to obtain this information via other means.
Reproducible steps:
- Log into a forum where you have admin privileges.
- Navigate to the Admin > Plugins > AI > Tools page (
/admin/plugins/discourse-ai/ai-tools). - Click the “+ New tool” button.
A menu will open. - Select “Start from blank…” from the menu.
The page for configuration of a new tool will open. - Enter any values into the following fields on the page:
- Name
- Tool Name
- Description
- Summary
- Enter the following code into the “Script” field:
ⓘ User IDfunction invoke() { return discourse.getUser(-1); }-1was selected arbitrarily as likely to be present on any forum. Any other user ID or username can be passed todiscourse.getUserif you prefer. - Click the “Save” button at the bottom of the page.
- Click the “Run test” button at the bottom of the page.
The “Test AI tool” dialog will open. - Click the “Run test” button in the dialog.
The test result does not provide the number of topics created by the user.
Discourse version:
f8f53ac5e8e4348ae308fcddc078766463d5e5f3
Additional context:
I am aware that I can get this information from the /user-badges/{username}/summary.json endpoint of the Discourse API, and that API requests can be made via the http.get function of the tool API. It is not feasible to do this because the hide_new_user_profiles site setting is enabled on the forum I manage, and thus the endpoint for new users is only accessible for authenticated requests. So it would be necessary to store an API key in the tool code in order to utilize the API. I will not do that.