r/pycharm • • Feb 19 '22

Plugin that generates documentation using AI

59 Upvotes

9 comments sorted by

6

u/[deleted] Feb 19 '22 edited Feb 19 '22

Before you install this plugin, be sure to read the security disclaimers.

Your code is uploaded to Mintlify's servers for analysis. That may be fine for some and the disclaimers are saying the right things about protecting that code (encryption, de-identification, right to delete, etc.), but code leaving your machine may be a non-starter for others.

Also know that more than just the lines you've highlighted are leaving your machine. It's uploading other code, likely to provide additional context to the AI.

4

u/[deleted] Feb 19 '22

Document your code. Don’t leave it to the robots. They aren’t good at it

3

u/lebrumar Feb 19 '22

From my first attempts, this robot gives at least very good first drafts!

5

u/[deleted] Feb 19 '22

I do see this tool providing some good first drafts.

For me its most useful feature is that it tells you what the robot thinks you were trying to do with a code block. That might be very different than what you intended to do. That's powerful.

1

u/[deleted] Feb 19 '22

[removed] — view removed comment

2

u/[deleted] Feb 19 '22 edited Feb 19 '22

We are all learning all the time.

And documenting your code yourself is a big part of that learning.

Just yesterday I stopped working on a script which analyzes multiple datasets bringing them together to help answer some bigger questions, to edit the documentation at the top of each function and within the code.

This took hours but will save days from the refactoring opportunities, and code reuse it helped me find. Also found a fair amount of dead code.

This tool could be helpful in that process, displaying what the robot thought I was trying to do. But it just begins the process of useful documentation.

1

u/funkym00se Feb 19 '22

Isn't it Kite Plugin, i tried installing it but at that time i guess Site was down

1

u/[deleted] Feb 19 '22 edited Feb 19 '22

Some first impressions (with the PyCharm version of the plugin), here's a function I'm working on that downloads a file from web site via a POST call. It also calls another function with that some of the parameters passed to this function, plus the newly created requests object to do the actual downloading.

AT is only as good as the context it's working in. The more clues that are there, the better it performs. Obvious right? The differences are significant though.

The first code block shows the output with some logging. This plugin makes a lot of use of things like that and any available comments, to build that context.

The second code block doesn't have any logging or comments and the results are far less rich. The differences in how the returns are documented is particularly interesting.

Both create comments with an odd indentation.

    def DownloadFileFromTheThing(self, original_file, uploaded_file_name, local_dir, parent_dir='files'):
	    """
	    Download a file from TheThing and save it to a local directory
	    
	    :param original_file: the name of the file you want to download
	    :param uploaded_file_name: The name of the file as it was uploaded to the Thing
	    :param local_dir: the directory to download the file to
	    :param parent_dir: the directory to download the file to, defaults to files (optional)
	    :return: A dictionary with the following keys:
	        'status_code'
	        'file_name'
	        'file_path'
	        'file_size'
	        'file_type'
	        'file_extension'
	        'file_url'
	        'file_content'
	        'file_content_type'
	        'file_content
	    """
        self.logger.debug(f"downloading {original_file} to {local_dir} as {original_file} from TheThing")
        headers['X-CSRF-TOKEN'] = self.csrf
        headers['Referer'] = f'{self.url_base}f/admin/filesAndForms'
        headers['X-Requested-With'] = 'XMLHttpRequest'
        url = f'{self.url_base}/admin/fileDownload'

        payload = {'_token': self.token,
                   'download_file_path': '/webroot/thething/public/assets/uploads',
                   'download_file_name': uploaded_file_name,
                   }

        rf = self.session.post(url, data=payload, headers=headers)
        if rf.status_code >= 300:
            self.logger.error(f"status code {rf.status_code} on post to {url}")
        return self.download_to_local_file_path(local_dir, original_file, parent_dir, rf)

Here are the results with logging removed

    def DownloadFileFromTheThing(self, original_file, uploaded_file_name, local_dir, parent_dir='files'):
	    """
	    Download a file from the thing and save it to a local directory
	    
	    :param original_file: the file name of the file you want to download
	    :param uploaded_file_name: The name of the file that you want to download
	    :param local_dir: The directory where the file will be downloaded to
	    :param parent_dir: The name of the directory that will contain the file, defaults to files (optional)
	    :return: A file object
	    """
        headers['X-CSRF-TOKEN'] = self.csrf
        headers['Referer'] = f'{self.url_base}f/admin/filesAndForms'
        headers['X-Requested-With'] = 'XMLHttpRequest'
        url = f'{self.url_base}/admin/fileDownload'

        payload = {'_token': self.token,
                   'download_file_path': '/webroot/thething/public/assets/uploads',
                   'download_file_name': uploaded_file_name,
                   }
        rf = self.session.post(url, data=payload, headers=headers)
        return self.download_to_local_file_path(local_dir, original_file, parent_dir, rf)