如题,最近正在研究一个Golang项目,代码量不多但分了很多文件,我不想自己挨个看代码了,但手动复制所有代码再标上对应文件名丢给GPT分析用法还是太麻烦了些,有没有什么方法让GPT可以直接读取Github仓库或者读取本地文件夹?
(熬夜熬多了神志不清 描述可能不太准确 先给各位佬友跪了 )
46 Likes
可以试试 https://aider.chat/
7 Likes
让gpt用python写个脚本,把一个项目文件夹下的需要的文件全部按照文件位置导出到一个记事本文件里面就行,很简单,按照需要导出的文件后缀导出就可以
5 Likes
我这个是之前写的导出vue的,随便让gpt改下就行了
import os
import time
import json
import tkinter as tk
from tkinter import filedialog
import chardet
def save_file_content(folder_path, file_content, base_path):
if not os.path.exists(folder_path):
print(f"未找到文件夹:{folder_path}")
return file_content
for item in os.listdir(folder_path):
item_path = os.path.join(folder_path, item)
if os.path.isdir(item_path):
file_content = save_file_content(item_path, file_content, base_path)
elif item.endswith(('.ts', '.js')):
relative_path = os.path.relpath(item_path, base_path)
try:
with open(item_path, 'rb') as f:
content = f.read()
encodings = ['utf-8', 'gb2312', 'gbk', 'gb18030', 'big5', 'iso-8859-1', 'windows-1252', 'ascii']
decoded = False
for encoding in encodings:
try:
file_content[relative_path] = content.decode(encoding)
decoded = True
break
except UnicodeDecodeError:
continue
if not decoded:
print(f"无法解码文件 {item_path},将以二进制形式保存")
file_content[relative_path] = content.hex()
except Exception as e:
print(f"读取文件 {item_path} 发生错误: {e}")
return file_content
def main():
"""
主函数,打开文件夹选择对话框,获取用户选择的文件夹路径,保存文件内容到时间戳命名的文件中
"""
root = tk.Tk()
root.withdraw() # 隐藏 Tkinter 主窗口
folder_path = filedialog.askdirectory(title="请选择项目文件夹")
if not folder_path:
print("未选择文件夹!")
return
file_content = save_file_content(folder_path, {}, folder_path)
timestamp = str(int(time.time()))
folder_name = os.path.basename(folder_path)
output_folder = os.path.join(os.path.dirname(__file__), folder_name)
os.makedirs(output_folder, exist_ok=True) # 创建以读取项目命名的文件夹
output_file = os.path.join(output_folder, f"{timestamp}_content.json")
with open(output_file, 'w', encoding='utf-8') as f:
json.dump(file_content, f, ensure_ascii=False, indent=2)
print(f"文件内容已保存到:{output_file}")
if __name__ == "__main__":
main()
2 Likes
是个好方案 但我不怎么用vsc
我一开始也是这么想的,批量读取文件内容并附上路径,但总感觉还会有更巧妙的解决方案
直接传压缩包就行了呀
1 Like
本质上格式转换,你自己写个pyhon就行
之前看到一个佬友发的
将项目导出为文件树
6 Likes
之前看到的一个项目,可以把一个仓库下的文件输出到一个文件中,file-combination-tool
1 Like
热佬,这个直接基于项目对话,有UI或者中文吗,好像没找到
1 Like
可以用中文对话,UI 就是命令行,不过补全,高亮什么的做的挺好的,感觉用起来还算舒服
2 Likes
这个我知道,devv.ai了解一下,先把项目传到github上,然后用devvai读取这个仓库就行,pro才能用上,这个找zhiyang大佬领就行
再咨询一下佬,
用起来支持自定义端点不,用one-api来搞
能和VSCode结合用么
用 nextchat 前端塞太多文本会卡,暂时不知道有啥好的解决办法。
1 Like
一下
不错
会员还能领的吗 ?