AI Cog Documentation
AI query tools powered by GROQ's API, with optional DDGS web search grounding.
Command group name: ai
/ai ask
Ask a free AI model a question, with an optional web search for grounding.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| prompt | string | yes | The question or prompt to send to the AI model. |
| search | boolean | no | Whether to ground the response with web search context. Defaults to false. |
Rate limit Users using this cog get 10 requests to the API every hour. This is to prevent abuse, and ensure that the cog is accessible to absolutely everyone. There is no paywall here, that users can use to gain higher access to this cog.
Behavior The command defers its response, since generation can take a few seconds.
If search is true, the prompt is first run through a DuckDuckGo web search (via DDGS), pulling up to 5 results. Each result's title, URL, and snippet are formatted into a block of search context. This context is passed to the model through GROQ's API alongside the prompt, and the model is instructed to ground its answer using that context relative to the current date. This pretty much allows the AI model to reach information outside of its context window.
If search is false, the prompt is sent to the model as is, with no search context attached.
In both cases, the system prompt tells the model the current date, and asks it to keep responses short and tidy to fit Discord's 4000 character limit, to write in brief paragraphs rather than tables or graphs, and to avoid emojis unless asked for because emoji's look weird.
The model used is openai/gpt-oss-20b, with temperature set to 0.7.
Once a response comes back, it is split into pages of up to 2000 characters, breaking between words. The final reply is built as a Discord CV2 message, containing: - A title showing the original prompt (with backticks removed), with a link button to the model on hugging face. - The AI response, one page at a time, with buttons to move between pages when there is more than one. - A small note showing how long the request took, how many requests the user has left this hour, whether the response was grounded with DDGS web search, and which model was used.
Error handling If GROQ's API returns an empty response, or if the API call fails for any reason, the command replies with an errorUI class message.
If the command is used more than twice within 60 seconds, the command replies with a rate limit message instead of running.
If the user has already used all 10 requests this hour, the command replies with roughly how many minutes are left until they can ask again.
Any other unexpected error during the command is logged, and the user is shown a generic error message saying it was likely an API error.