2

I asked ChatGPT about my CSV data, and ChatGPT answered:

"Here is an example of how you can read a CSV file using pandas, and then use the data to train or fine-tune GPT-3 using the OpenAI API:"

import pandas as pd
import openai_secret_manager

# Read the CSV file
df = pd.read_csv("example.csv")

# Get the OpenAI API key
secrets = openai_secret_manager.get_secrets("openai")
openai_api_key = secrets["api_key"]

# Use the data from the CSV file to train or fine-tune GPT-3
# (Assuming you have the OpenAI API key and the OpenAI Python library installed)
import openai
openai.api_key = openai_api_key
response = openai.Completion.create(
    engine="text-davinci-002",
    prompt=(f"train on data from example.csv{df}"),
    max_tokens=2048,
    n = 1,
    stop=None,
    temperature=0.5,
)
print(response["choices"][0]["text"])

But, I got this error:

ModuleNotFoundError: No module named 'openai_secret_manager'

Rubén
  • 34,714
  • 9
  • 70
  • 166
mostafa
  • 188
  • 2
  • 10
  • 1
    Have you installed the openai package? https://github.com/openai/openai-python – nofinator Jan 13 '23 at 17:54
  • 1
    Yes, I've installed openai packages, I've also tried to install "openai_secret_manager" using pip, but there isn't @nofinator – mostafa Jan 13 '23 at 18:03
  • 2
    GPT chat sometimes generate wrong code. Try to replace second line by import openai. And delete line started with secrets = . And here openai_api_key = past your API key as hardcode (if you don't know how to do it with environment variables). – cheerful_weasel Jan 15 '23 at 10:14
  • 1
    Among other things, you can ask these questions to GPT chat. For example, if you write "openai_secret_manager is wrong package" he will apologize and say that it is not an official package created by the openAi community and optional. – cheerful_weasel Jan 15 '23 at 10:17
  • *"GPT chat sometimes generate wrong code"* Ha! That's an understatement. ChatGPT is a chatbot. He knows nothing about programming and cannot handle complex algorithms. All he can do is generate sequences of words that look plausible. Of course ChatGPT cannot solve your problem. I suggest reading this blog post: [What is ChatGPT doing and why does it work?](https://writings.stephenwolfram.com/2023/02/what-is-chatgpt-doing-and-why-does-it-work/). – Stef Mar 27 '23 at 20:09

2 Answers2

4

No need to use openai_secret_manager. I faced the same problem and deleted it and you need to generate & place an API from your account on OpenAI directly to the code.

import pandas as pd
import openai_secret_manager

# Read the CSV file
df = pd.read_csv("example.csv")

# Use the data from the CSV file to train or fine-tune GPT-3
# (Assuming you have the OpenAI API key and the OpenAI Python library installed)
import openai
openai.api_key = openai_api_key
response = openai.Completion.create(
    engine="text-davinci-002",
    prompt=(f"train on data from example.csv{df}"),
    max_tokens=2048,
    n = 1,
    stop=None,
    temperature=0.5,
)
print(response["choices"][0]["text"])

enter image description here

Copy and paste the API and replace openai_api_key here

openai.api_key = "PLACE_YOUR_API_IN_HERE"
  • can you explain what does this line does? `f"train on data from example.csv{df}"` i consufed on `train on data from example.` and what is inside the csv file and format. thanks in advance – XO56 Jan 26 '23 at 13:52
  • 1
    `example.csv` should have data that you have if you want to `fine-tune` `ChatGPT`. so basically, it is a way to make `ChatGPT` able to respond to people's questions based on the learning of the data that you would provide. For more info, you need to read from this [fine-tuning](https://beta.openai.com/docs/guides/fine-tuning) – Mohamad Ghaith Alzin Jan 27 '23 at 14:01
  • It seems that the answer's sample code still has the problematic import of "openai_secret_manager". I deleted that and just pasted in the literal string, and it worked: openai.api_key = "my api key pasted from openai account page" – Blisterpeanuts Mar 04 '23 at 18:27
  • this answer is actually answering the question – Nilesh K Mar 14 '23 at 13:02
1

There's no open_secret_manager library. There is an openai-manager library that helps using openAI API keys, especially if you are a team with many keys (https://pypi.org/project/openai-manager/).

It's not a good practice to use your personal API Key directly in the code, especially if you plan to commit the code in GIT. This would make your key visible to anyone that can exploit your paid access to openAI models.

The best practice is either store the key in a secret yml file and have it read in the code (and put the file in .gitignore to prevent it from commit) or store the key in a system environment variable and read it using: openai.api_key = os.environ['OPENAI_API_KEY'] There's explanation about how you do it in openai documentation here: https://help.openai.com/en/articles/5112595-best-practices-for-api-key-safety

Donna
  • 1,390
  • 1
  • 14
  • 30
Amir Sher
  • 11
  • 2