https://github.com/nicholassynovic/tool_neural-docstrings-generator
Code to write docstrings for functions and classes using LLMs
https://github.com/nicholassynovic/tool_neural-docstrings-generator
docstrings llms ollama tool
Last synced: about 1 month ago
JSON representation
Code to write docstrings for functions and classes using LLMs
- Host: GitHub
- URL: https://github.com/nicholassynovic/tool_neural-docstrings-generator
- Owner: NicholasSynovic
- License: agpl-3.0
- Created: 2024-04-19T19:33:37.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-06T01:54:58.000Z (almost 2 years ago)
- Last Synced: 2025-03-23T23:46:51.151Z (about 1 year ago)
- Topics: docstrings, llms, ollama, tool
- Language: Python
- Homepage: https://nicholassynovic.github.io/tool_neural-docstrings-generator/
- Size: 266 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Neural Docstring Generator (`ndg`)
> A small program to generate docstrings using Ollama-compatible LLMs
## Table of Contents
- [Neural Docstring Generator (`ndg`)](#neural-docstring-generator-ndg)
- [Table of Contents](#table-of-contents)
- [About](#about)
- [How to Install](#how-to-install)
- [Dependencies](#dependencies)
- [Installation Instructions](#installation-instructions)
- [How to Run](#how-to-run)
- [Default LLM](#default-llm)
- [Default System Prompt](#default-system-prompt)
## About
I don't like writing docstrings.
Large language models (LLMs) don't complain about writing docstrings.
Therefore, if I can get LLMs to write docstrings for me, then I'll be happy and
free!
This tool (neural docstring generator, or `ndg`) is meant to provide a proof of
concept on how to:
- Read in source code files
- Extract functions and their supporting code from the source file
- Inference with LLMs self-hosted via Ollama with LangChain
## How to Install
`ndg` was tested to work on x86-64 Linux computers running `Python3.10`.
It is assumed that you have a working `ollama` instance on your computer. To
learn more, see the
[Ollama GitHub repository](https://github.com/ollama/ollama).
### Dependencies
The following dependencies are required:
- `python3.10`
- `poetry`
- `langchain`
- `progress`
- `click`
- [`pyfs`](https://github.com/NicholasSynovic/python-fs-utils%22)
### Installation Instructions
To install:
1. `git clone` this repository
1. `cd` into this repository
1. Install dependencies with `pip install -r requirments && poetry install`
1. Build and install the `ndg` tool with `make`
## How to Run
```shell
Usage: ndg [OPTIONS]
Options:
-i, --input PATH Source file to generate docstrings for [required]
-m, --model TEXT LLM used to generate docstrings. NOTE: Must be
recognizable by Ollama
-s, --system TEXT The system prompt to use
-o, --output PATH File to output docstrings to [required]
--help Show this message and exit.
```
If your `input` and `output` are equivalent, then a new file will be created in
the same directory as `input`, but with the `.ndg` file extension appended to
avoid overwriting content between the two files.
## Default LLM
By default,
[Ollama's default CodeGemma model (`codegemma`)](https://ollama.com/library/codegemma)
is used for this tool.
## Default System Prompt
Here is the default system prompt.
```text
This file contains code for counting lines of code of software projects.
Generate suitable docstring for these Python functions in Google's style.
Do not explain the result.
Only return the docstring and function declaration.
Return as raw text.
```
This can be adjusted with `ndg --system`