如何使用ChatGPT在我的计算机上读写文件夹。

huangapple go评论77阅读模式
英文:

how to read and write to a folder on my computer using chatgpt

问题

我明白你的需求,你想要在ChatGPT中执行代码片段,其中包括加载文件和运行数据可视化等操作。以下是你可以使用的示例代码:

# 加载文件
def load_file(file_path):
    # 在这里编写加载文件的代码
    pass

# 运行数据可视化
def run_data_visualization(file_name):
    # 在这里编写运行数据可视化的代码
    pass

# 示例用法
command = "load file.csv"
if command.startswith("load "):
    file_path = command[len("load "):]
    load_file(file_path)
elif command.startswith("run data visualization on "):
    file_name = command[len("run data visualization on "):]
    run_data_visualization(file_name)

你可以根据需要扩展这些函数以执行特定的文件加载和数据可视化操作。请确保在ChatGPT环境中使用这些函数时具备相应的权限和设置。

英文:

I know chatgpt can not access the file system on a computer and needs a plugin or API to do that, and I am on the waiting list for them. But I want to implement it now. I can for example put a file on google cloud and create a shared link and give it to chatgpt for reading but that is not practical.

For example I can use API and run it from computer like this and works fine.

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())

But I want to type "python /filepath/filename.py" or "load /filepath/filename" inside chatgpt like a codelet demo that I saw where it loaded up a panda df file and ran data vizualization on it by simply typing:

"load file.csv"

"run data visualiztion on file.csv"

答案1

得分: 1

ChatGPT无法做到这一点。
你要求的只有两种方法。

  1. 开发一个ChatGPT插件,该插件将运行在公共Web服务器上,并以某种方式访问你的计算机以执行文件操作。
  2. 使用OpenAI API,在你的计算机上创建一个可以使用OpenAI API来帮助确定并运行工具以完成所要求工作的应用程序。一个可以实现这一功能的库的示例是LangChain,它设置为使用文件系统工具代理以支持文件系统操作。
英文:

ChatGPT does not have the ability to do that.
There are only two ways to do what you ask.

  1. Develop a ChatGPT plugin that will run on a public web server and somehow access your machine to do file operations.
  2. Use the OpenAI API and create a application on your machine that can use the OpenAI API to help determine and run tools to help do the work asked for. An example of a library that can do this is LangChain setup to use the File System Tools agent to support file system operations.

huangapple
  • 本文由 发表于 2023年5月11日 04:18:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76222270.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定