RAHB-REALTORS-Association / chat2gpt

Chat²GPT is a ChatGPT (and DALL·E 2/3, and ElevenLabs) chat bot for Google Chat. 🤖💬
https://chat2gpt.oncornerstone.app
MIT License
11 stars 1 forks source link

[Feature Request] Add /help command to print docs/usage.md #58

Closed justinh-rahb closed 1 year ago

justinh-rahb commented 1 year ago

🚀 Feature Request

Description: Add a new /help command to the chatbot that provides users with guidance on how to interact with it. This command will display content from the docs/usage.md file, allowing users to understand the bot's functionalities without having to refer to external documentation.

Problem Statement: Users often require guidance on how to use chatbots effectively, especially when they encounter the bot for the first time. Providing them with a /help command directly within the chat interface can improve their experience by offering immediate access to helpful information.

Proposed Solution: Implement a new /help command in the bot's message handling logic. Upon invocation, the bot should read the docs/usage.md file, extract the content below the --- header, and return it as its response. Here's a code snippet illustrating the proposed implementation:

# Check if the user input starts with /help
elif user_message.strip().lower() == '/help':
    try:
        # Read the docs/usage.md file
        with open('docs/usage.md', 'r') as file:
            content = file.read()

        # Split the content at the "---" header line and get the second part
        help_content = content.split("---", 2)[-1].strip()

        # Return the extracted content as the bot's response
        return jsonify({'text': help_content})

    except Exception as e:
        print(f"Error reading help content: {str(e)}")
        return jsonify({'text': 'Sorry, I encountered an error retrieving the help content.'})

Benefits:

Additional Context: The proposed solution assumes that the docs/usage.md file exists and is structured with a --- header. If the file structure changes in the future, the implementation may require adjustments.

Screenshots / Mockups (Optional): N/A

justinh-rahb commented 1 year ago

Here's how we can create a get_docs function that takes a document name as an argument and returns the relevant content:

def get_docs(doc_name: str) -> str:
    """Fetches content from a specified markdown document."""
    try:
        # Construct the file path based on the doc_name
        file_path = f'docs/{doc_name}.md'

        # Read the specified markdown file
        with open(file_path, 'r') as file:
            content = file.read()

        # Split the content at the "---" header line and get the second part
        doc_content = content.split("---", 2)[-1].strip()

        return doc_content

    except Exception as e:
        print(f"Error reading {doc_name} content: {str(e)}")
        return f'Sorry, I encountered an error retrieving the {doc_name} content.'

# Usage example:
# doc_content = get_docs("usage")

Then, in the main handle_message function, we can use it as follows:

# Check if the user input starts with /help
elif user_message.strip().lower() == '/help':
    help_content = get_docs("usage")
    return jsonify({'text': help_content})

With this approach, if we decide to add more commands that read docs in the future, we can easily fetch their content using the get_docs function without duplicating the file reading and splitting logic.

sweep-ai[bot] commented 1 year ago

Here's the PR! https://github.com/RAHB-REALTORS-Association/chat2gpt/pull/60.

⚡ Sweep Free Trial: I used GPT-3.5 to create this ticket. You have 0 GPT-4 tickets left for the month and 0 for the day. For more GPT-4 tickets, visit our payment portal.To get Sweep to recreate this ticket, leave a comment prefixed with "sweep:" or edit the issue.


Step 1: 🔍 Code Search

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I looked at (click to expand). If some file is missing from here, you can mention the path in the ticket description. https://github.com/RAHB-REALTORS-Association/chat2gpt/blob/09e87a026b363c52ab991cd4d6b83aa8373c5109/docs/usage.md#L1-L23 https://github.com/RAHB-REALTORS-Association/chat2gpt/blob/09e87a026b363c52ab991cd4d6b83aa8373c5109/main.py#L202-L412

Step 2: 🧐 Snippet Analysis

From looking through the relevant snippets, I decided to make the following modifications:

File Path Proposed Changes
main.py - In the handle_message function, add the following code snippet after the elif condition for /tts command (around line 114):

```python
elif user_message.strip().lower() == '/help':
try:
# Read the docs/usage.md file
with open('docs/usage.md', 'r') as file:
content = file.read()

# Split the content at the "---" header line and get the second part
help_content = content.split("---", 2)[-1].strip()

# Return the extracted content as the bot's response
return jsonify({'text': help_content})

except Exception as e:
print(f"Error reading help content: {str(e)}")
return jsonify({'text': 'Sorry, I encountered an error retrieving the help content.'})
```

Step 3: 📝 Planning

I have created a plan for writing the pull request. I am now working my plan and coding the required changes to address this issue. Here is the planned pull request:

[Feature Request] Add /help command to print docs/usage.md sweep/add-help-command

Description

This PR adds a new /help command to the chatbot's message handling logic. When users invoke the /help command, the bot will read the docs/usage.md file, extract the content below the --- header, and return it as its response. This provides users with immediate access to helpful information on how to interact with the chatbot without having to refer to external documentation.

Changes Made

  • Added a new elif condition in the handle_message function to check if the user input starts with /help.
  • Read the content of the docs/usage.md file and extracted the relevant content below the --- header.
  • Returned the extracted content as the bot's response.

Benefits

  • Enhances user experience by providing immediate access to helpful guidance.
  • Reduces the need for users to search for external documentation.
  • Utilizes existing documentation, ensuring that the bot's guidance is consistent with other resources.

Additional Context

The proposed solution assumes that the docs/usage.md file exists and is structured with a --- header. If the file structure changes in the future, the implementation may require adjustments.


Step 4: ⌨️ Coding

File Instructions Progress
main.py - In the handle_message function, add the following code snippet after the elif condition for /tts command (around line 114):

python<br/>elif user_message.strip().lower() == '/help':<br/> try:<br/> # Read the docs/usage.md file<br/> with open('docs/usage.md', 'r') as file:<br/> content = file.read()<br/><br/> # Split the content at the "---" header line and get the second part<br/> help_content = content.split("---", 2)[-1].strip()<br/><br/> # Return the extracted content as the bot's response<br/> return jsonify({'text': help_content})<br/><br/> except Exception as e:<br/> print(f"Error reading help content: {str(e)}")<br/> return jsonify({'text': 'Sorry, I encountered an error retrieving the help content.'})<br/> | ✅ Commit 192d789
I have finished coding the issue. I am now reviewing it for completeness.

Step 5: 🔁 Code Review

Here are my self-reviews of my changes at sweep/add-help-command.

Here is the 1st review

No changes required. The code changes in main.py seem to handle the "/tts" and "/help" commands correctly without any apparent errors or unimplemented sections. Well done!

I finished incorporating these changes.


To recreate the pull request, or edit the issue title or description. Join Our Discord