Subprocess.run not seeing api_key variable, throwing 'No API key provided

I am trying to fine tune a model using the subprocess.run command because I do not have administrator access to the machine I am working off of, so I do not have access to the terminal or otherwise.

import openai
import subprocess

openai.api_key = “■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■x9eESt83”

Start fine-tuning

subprocess.run(“openai api fine_tunes.create -t training_data_ai -m curie”.split())

throwing the “Error: No API key provided. You can set your API key in code using ‘openai.api_key = ’, or you can set the environment variable OPENAI_API_KEY=). If your API key is stored in a file, you can point the openai module at it with ‘openai.api_key_path = ’. You can generate API keys in the OpenAI web interface. See https://onboard.openai.com for details, or email support@openai.com if you have any questions.” Error…

I am running off of pycharm on windows and am not exactly sure how I would run this in the CLI as I am not able to access the terminal, only the virtual environment terminal through pycharm and that does not have access to PATH.

Welcome to the community @kaedanbuckler

No need to worry about not having cli access.

You can fine-tune models on the API with the python library using the following code from API reference:

import os
import openai
openai.api_key = os.getenv("OPENAI_API_KEY")
openai.FineTune.create(training_file="file-XGinujblHPwGLSztz8cPS8XY")

Sorry, I know how to find the file id using the terminal, but is there another way? i tried git bash using the ls -i command, but the code still couldnt find it

Nevermind, I found it by printing the

print(openai.File.create(file=open(“training_data.jsonl”, “rb”),purpose=‘fine-tune’))

thank you so much

1 Like