Meet my trip building LazyDoc from scratch, exploring Elixir ASTs and combine it with a simple AI prompt you can generate fairly accurate documentation.
Lazy Doc is a project for those who are lazy to document their code. It is designed to detect undocumented functions and pass the function to an AI provider to document it.
Do you have any examples of the output? The “documentation” produced by some previous attempts was simultaneously impressive and disappointing; impressive because it regularly summarized Java code into coherent prose, disappointing because lot of it was in the vein of getFrob: gets the Frob.
Since the library is documented by the library itself.
The quality of the documentation depends on these factors
the prompt you are using.
the model you are using.
I am using the default prompt of the library which you can find on the README,
and the model I am using is gpt-4-o-mini, which is not the best but it gave me good enough results.
In my case it gave me a really consistent result, because I have specified an output format.
Output seems reasonable overall. There’s a bug with functions that pattern-match their arguments without naming them, for instance filter_documented_functions. The bindings inside the first argument’s match become the documentation, and the second parameter is entirely ignored.
Basically this reduce the noice to the AI and probably will be more accurate, but as you know AI is not 100% accurate and the intention of the project is not to seek correctness in response, AI models want to seek them. The intention of this project is to seek documentation completion and generating the docs should be useful to use it as a reasonable starting point, you should review if the AI is doing good work. That is one of the reasons I offer custom prompts and custom models extension, because documentation is really personal thing.
I wanted to try it, but ran into the issue that you are locking the version of Req to 0.4.0, is that required?
Or could you loosen the version requirement.
And I find the repetition of Main functionality in the API Reference on hexdocs strange and unhelpful.
Could you also (maybe) add to the installation/configuration where to get the needed API key?
And which parts of the configuration I need to add, and which are default?
Hey @Hermanverschooten , thank you very much for your feedback, I think Req version can be loosen. I just did it like this because it was easier for me.
Do you want to use an older version of Req or newer ?
About of ## Main functionality issue, this is fine tuning the @moduledoc prompt which you can personally do. But I got and idea for making it compliant with ex_doc.
Basically before you click an element in ex_doc it shows a summary of the first sentence of the element doc.
So the fix is to do this format and tell it in the AI prompt.
The module ... (this is the main functionality of the module)
## Description
Blablabla
But if you want to use a different AI API , you just need to implement LazyDoc.Provider behavior and give it as the first element of the tuple in :provider config option.
About the configuration options, I stronly recommend to configure everyone, to get the best experience, but most of them have good default, I will add some comments in the README that will give you a hint.
@syepes As far as I know, In every Elixir app and library you can create
config/config.exs and config/runtime.exs files. Then just copy paste and modify as you wish what it is in the README.
Is there any reason you wont like to create this files ?
There is no other way to configure the library because the library calls the Application.get_env/3 to get the configuration it needs. Most of the config have nice defaults so you dont even need to configure them.
I think a single way to setup simplifies the way to work to library users.