gpt code commenter
1.0.0
通过将代码传递给 LLM (Chat-GPT) 自动记录代码。
通过简单的提示,我们要求法学硕士按照该语言的约定对给定的代码进行注释。
NOTE
- 该工具仍然需要手动监督:如果输出回同一位置,请在提交更改之前检查结果。默认情况下,该工具输出到 stdout 或新目录。
有关设置说明,请参阅下面的Setup
部分。
注意:脚本必须从顶级via-chat-gpt
文件夹中运行。
要评论单个文件:
pipenv run python via-chat-gpt [--out-dir
注释目录中的文件(不是递归):
pipenv run python via-chat-gpt [--out-dir
注意:要写回相同的文件,只需指定--out-dir
指向相同的目录。但请在提交更改之前检查结果。
生成的示例文档(通过 pdoc 发布到 S3):cornsnake 文档。
import json
def read_from_json_file(path_to_json, encoding='utf-8'):
with open(path_to_json, encoding=encoding) as f:
data = json.load(f)
return data
def write_to_json_file(dict, file_path, encoding='utf-8', indent=2):
json_object = json.dumps(dict, indent=indent)
with open(file_path, "w", encoding=encoding) as outfile:
outfile.write(json_object)
"""
This Python file contains functions for reading from and writing to a JSON file. The `read_from_json_file` function reads JSON data from a file, and the `write_to_json_file` function writes JSON data to a file.
"""
import json
def read_from_json_file(path_to_json, encoding='utf-8'):
"""
Function to read JSON data from a file.
Args:
path_to_json (str): The path to the JSON file.
encoding (str): The encoding of the file. Default is 'utf-8'.
Returns:
dict: The JSON data read from the file.
"""
with open(path_to_json, encoding=encoding) as f:
data = json.load(f) # Load JSON data from the file
return data
def write_to_json_file(dict, file_path, encoding='utf-8', indent=2):
"""
Function to write JSON data to a file.
Args:
dict (dict): The dictionary containing JSON data to be written.
file_path (str): The path to the output JSON file.
encoding (str): The encoding of the file. Default is 'utf-8'.
indent (int): The number of spaces to indent the JSON data. Default is 2.
"""
json_object = json.dumps(dict, indent=indent) # Convert dictionary to JSON string with specified indent
with open(file_path, "w", encoding=encoding) as outfile:
outfile.write(json_object) # Write JSON data to the file
cd via-chat-gpt
Unix:
pip install pipenv
export PYTHONPATH= " ${PYTHONPATH} :. "
pipenv install
视窗:
pip install pipenv
set PYTHONPATH= " %PYTHONPATH% " ; .
pipenv install
使用 OpenAI 密钥设置环境变量:
export OPENAI_API_KEY= " xxx "
将其添加到您的 shell 初始化脚本中( ~/.zprofile
或类似脚本)
在当前终端加载:
source ~ /.zprofile
(cd via-chat-gpt)
test-openai.sh
或者
pipenv run python via-chat-gpt ../test-resources/util_json.py
结果还不错(Chat-GPT 的结果要好得多)
请参阅 via-phi2-the-bloke 自述文件
TODO 修复此版本的响应处理
请参阅via-phi2自述文件