import traceback
import openai
import osopenai.api_key = ""conversation=[{"role": "system", "content": "You are a helpful assistant."}]
max_history_len = 20
first_message = Nonedir = r'J:\ai\input' #要改写的文档所在目录
#获取目录列表
list_dir = os.listdir(dir)
#打印目录列表
print(list_dir)
#遍历目录列表
for i in range(len(list_dir)):try:title = list_dir[i] #要改写的文档文件名称,新建一个intput目录,文档放在intput目录下print(title) #打印文档名称#这里要读取两次,第一次是计算循坏所需要的次数,第二次读取原文f = open("input/{}".format(title),'r',encoding= 'utf-8') #s = len(f.read()) // 400f.close()f = open("input/{}".format(title),'r',encoding= 'utf-8')for i in range(s+1):content = f.read(400)print('这是原文:', content + "\n")conversation =