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

1.8k views Asked by At

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

There are 1 answers

1
Shane Powell On

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.