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自述文件