我知道chatgpt无法访问计算机上的文件系统,并且需要插件或API来执行此操作,并且我在他们的等待名单上。但我现在想实现它。例如,我可以将一个文件放在谷歌云上并创建一个共享链接并将其提供给 chatgpt 供阅读,但这并不实用。
例如,我可以使用 API 并像这样从计算机上运行它并且工作正常。
import openai
import os
# Initialize the OpenAI API with your key
openai.api_key = ''
# Specify the paths to the question and answer files
question_file_path = os.path.join('c:/Users/kehsa/', 'gpt-projects/chatgpt/', 'questions/', 'questions.txt')
answer_file_path = os.path.join('c:/Users/kehsa/', 'gpt-projects/chatgpt/', 'answers/', 'answers.txt')
# Read the question from the file with
with open(question_file_path, 'r') as question_file:
question = question_file.read()
# Send the question to the GPT-3 model. Increase max_tokens for more complex question / responses
response = openai.Completion.create(engine="text-davinci-003", prompt=question, max_tokens=60)
# Write the model's response to the answer file with error handling
if os.path.exists(answer_file_path):
with open(answer_file_path, 'w') as answer_file:
answer_file.write(response.choices[0].text.strip())
else:
with open(answer_file_path, 'x') as answer_file:
answer_file.write(response.choices[0].text.strip())
但是我想在chatgpt中输入“python/filepath/filename.py”或“load/filepath/filename”,就像一个codelet演示一样,我看到它加载了一个panda df文件并通过简单地对其运行数据可视化键入:
“加载文件.csv”
“在 file.csv 上运行数据可视化”
最佳答案
ChatGPT 没有能力做到这一点。 只有两种方法可以满足您的要求。
- 开发一个 ChatGPT 插件,该插件将在公共(public)网络服务器上运行并以某种方式访问您的计算机以执行文件操作。
- 使用 OpenAI API 并在您的计算机上创建一个应用程序,该应用程序可以使用 OpenAI API 来帮助确定和运行工具来帮助完成所需的工作。可以执行此操作的库的示例是 LangChain设置使用 File System Tools支持文件系统操作的代理。
关于openai-api - 如何使用 chatgpt 读取和写入计算机上的文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76222270/