sam

What does the ReadTool in discourse/discourse-ai

GitHub_Helper_bot
GitHub file content

Retrieved content of lib/ai_bot/tools/read.rb from discourse/discourse-ai@main

Thank you for providing the content of the ReadTool in the discourse-ai plugin. Let me explain what this tool does:

The ReadTool is a part of the AI Bot functionality in the Discourse AI plugin. Its main purpose is to read and retrieve content from topics and posts within a Discourse instance. Here’s a breakdown of its key features and functionality:

  1. Purpose: It allows the AI to read a topic or specific posts within a topic on the Discourse instance.

  2. Signature:

    • Name: “read”
    • Description: “Will read a topic or a post on this Discourse instance”
    • Parameters:
      • topic_id (required): The ID of the topic to read
      • post_numbers (optional): An array of post numbers to read within the topic
  3. Functionality:

    • It retrieves the topic based on the provided topic_id.
    • It can read either the entire topic or specific posts within the topic if post_numbers are provided.
    • It respects user permissions, using a Guardian to ensure the user has access to read the topic.
    • It collects information such as the topic title, category, and tags.
    • It assembles the content of the posts, including the author’s name and username for each post.
  4. Content Limitations:

    • It has a maximum limit of 100 posts per read operation (MAX_POSTS = 100).
    • The final content is truncated to a maximum of 20,000 characters or 30% of the original length, whichever is shorter.
  5. Output:

    • Returns a hash containing:
      • topic_id: The ID of the read topic
      • content: The truncated content of the topic or specified posts
      • post_numbers: If specific post numbers were requested (optional)
  6. Additional Features:

    • It can handle private topics if the read_private option is set and a user context is provided.
    • It includes category and tag information in the output when available.
  7. URL Generation:

    • It generates a relative URL for the topic, which can be used to reference the specific location in the discourse instance.

This tool is crucial for allowing the AI to access and process information from the Discourse forum, enabling it to provide context-aware responses and perform tasks that require knowledge of forum content.