Code-Narrator: Streamline Your Documentation Process with GPT-4
Tags: documentation, chatgpt, productivity
Published: 2023-04-28 18:28:48

As a solo developer working on a large project, I found myself struggling with the documentation process. While it is a necessary task, it's certainly not my favorite. Fortunately, ChatGPT came to the rescue. After experimenting with it for a while, I discovered that it generated high-quality documentation for code files, even better than what I could have written. This inspired me to create a tool called Code-Narrator.

Code-Narrator (https://github.com/ingig/code-narrator) is a language-agnostic tool that leverages GPT-4 to automatically generate documentation for your code files. I've tested it with TypeScript, GraphQL, Solidity, C#, and Kotlin, among others, and it has performed exceptionally well.

The primary goal of Code-Narrator is to simplify the documentation process for developers, essentially turning them into editors rather than authors. While developers still need to validate the accuracy of the generated documentation, this tool significantly reduces the time and effort required.

In cases where GPT-4 generates incorrect documentation, it is typically due to unclear code. Developers can resolve this issue by either improving the code or providing brief comments to clarify the intended documentation. As a rule of thumb, if GPT-4 doesn't understand the code, it's likely too complicated for other developers as well.

Code-Narrator is subject to GPT-4's 8192-token limit, which may pose challenges for large code files. However, those with access to GPT-4-32K should expect even better results, as the documentation quality depends heavily on the length of the input (question + file content).

On its first run, Code-Narrator generates a configuration file by analyzing your project, and prompts you to review and modify it as needed. The key configurations include "include," "config_files," and "source_path." Running Code-Narrator for the second time generates the documentation. For code narrator it took around 45 minutes.

Some notable features of Code-Narrator include:
- Flexibility to create custom pages such as How-To guides, Tutorials, FAQ, README, or other custom types
- Support for generating documentation in 25+ languages (based on GPT's capabilities)
- Capability to generate documentation in various formats (LaTeX, HTML, with the default being Markdown)

For a demonstration on writing a How-To guide, refer to this video: https://www.youtube.com/watch?v=uJtVCUOTkvw. 

The cover image is the How-To guide to run the CLI, this is the result https://github.com/ingig/code-narrator/blob/master/docs/howto/HowTo%20run%20CLI.md 

There is also support for writing custom plugins, with tutorials available at https://github.com/ingig/code-narrator/tree/master/docs/tutorial.

Code-Narrator consists of approximately 45 files and 1712 lines of code. Generating documentation for an entire project costs roughly $2.5, which represents a significant time and cost-saving compared to manual documentation.

Some observations from my experience with Code-Narrator include:
- Improved code quality through enhanced function naming
- The challenge of minimizing the question file size
- The enjoyment of experimenting with ChatGPT to achieve better results
- The surprising ease of creating How-To guides and tutorials
- The limitation of the 8K token constraint

Although Code-Narrator is a prototype and proof of concept, there is room for improvement. Future enhancements could include documenting file diffs, building static websites, adding unit tests, generating documentation for unit tests, and integrating mermaid charts.

I'm excited about the potential of Code-Narrator and greatly appreciate any feedback you can provide. Thank you for taking the time to explore this tool!