import traceback
import openai
import os
openai.api_key = ""
conversation=[{"role": "system", "content": "You are a helpful assistant."}]
max_history_len = 20
first_message = None
dir = 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()) // 400
f.close()
f = open("input/{}".format(title),'r',encoding= 'utf-8')
for i in range(s+1):
content = f.read(400)
print('这是原文:', content + "\n")
conversation =
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32