Code Monkey home page Code Monkey logo

commentgen's Introduction

Code Comment Generator

简介

Code Comment Generator用于自动为Python代码文件添加中文注释。使用simpleaichat库与LLM交互,以生成注释。

特点

  • 自动生成中文注释和文档注释。
  • 支持处理大型代码文件,通过分块处理。
  • 将注释后的代码保存为Markdown和Python文件。

安装

在开始使用之前,请确保您的系统上安装了以下依赖项:

  • Python 3.x
  • tree_sitter_python
  • semantic_text_splitter
  • simpleaichat

您可以通过以下命令安装所需的Python包:

pip install tree_sitter tree_sitter_python semantic_text_splitter simpleaichat

使用方法

  1. 克隆本项目或下载压缩包并解压。
  2. 使用命令行工具,导航到项目目录。
  3. 运行脚本并提供输入和输出目录,以及其他可选参数。

以下是运行脚本的命令行示例:

python comment_gen.py <input_directory> <output_directory> --temperature <value> --max_tokens <value> --model <model_name> --base_url <base_url> --skip_dirs <dir1> <dir2> ...
  • <input_directory>: 包含Python文件的目录。
  • <output_directory>: 保存处理后文件的目录。
  • --temperature: AI模型的温度参数,默认为0.4。
  • --max_tokens: AI模型的最大令牌数参数,默认为2000。
  • --model: 使用的AI模型名称,默认为"qwen-turbo"。
  • --base_url: AI服务的基础URL,默认为"https://dashscope.aliyuncs.com/compatible-mode/v1"。
  • --skip_dirs: 要跳过的目录列表,可以是空格分隔的多个目录,默认为<output_directory>/.env

输出

处理完成后,脚本将在指定的输出目录中生成以下文件:

  • Markdown文件:包含注释的代码。
  • Python文件:仅包含处理后的Python代码块。

注意事项

  • 确保输入的Python代码文件使用UTF-8编码。
  • 脚本不会修改原始代码,只会添加注释。

TODO

  • 目前使用的分词器效果不尽人意, 需要改善。

贡献

如果您有任何建议或想要贡献代码,请提交Pull Request或创建Issue。

许可

本项目采用MIT许可

commentgen's People

Contributors

toukaya avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.