No module named 'openai_secret_manager'

Question:

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'

Asked By: mostafa

||

Answers:

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"

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

Answered By: Amir Sher
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.