AI读书原始版2023.5.9

2023-08-16 20:39:44 浏览数 (1)

代码语言:javascript复制
import requests
import pandas as pd

url = 'https://api.zhishuyun.com/chatgpt?token=8f1b59cd66c30e1ae5a0d'

headers = {
    'accept': 'application/json',
    'content-type': 'application/json'
}

result_list = []  # 存放结果的列表

# 遍历 txt 文件
for i in range(1, 6):
    with open(f'file{i}.txt', 'r', encoding='utf-8') as f:
        file_content = f.read()
        print(f"File {i} content: {file_content}")  # 打印文件内容

    # 添加三个字符串到文件内容中
    file_content  = "归纳文本概要:."
    file_content  = "提取文本中提到的人名."
    file_content  = "提取文本的案例."
    print(f"File {i} content after adding strings: {file_content}")  # 打印添加字符串后的文件内容

    payload = {
        'question': file_content,
        'retry_times': 2
    }

    response = requests.post(url, json=payload, headers=headers)
    result_list.append(response.text)  # 将结果添加到列表中
    print(f"Response for file {i}: {response.text}")  # 打印响应结果

# 将结果保存到 excel 文件中
df = pd.DataFrame({'result': result_list})
df.to_excel('result.xlsx', index=False)
print("Results saved to result.xlsx")  # 打印保存结果的消息

0 人点赞