Skip to content

Commit 42ea28d

Browse files
committed
Add support for GPT_CMD_TOKEN var
1 parent 6e87603 commit 42ea28d

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,13 @@ Override the gpt model used by the tool.
7878

7979
**Default**: `gpt-4o`
8080

81+
### `GPT_CMD_TOKEN`
82+
83+
Provide your OpenAI token via this env var instead of storing it in a file.
84+
8185
### `GPT_CMD_TOKEN_FILE_PATH`
8286

83-
Override the file path the tool gets your OpenAI token from.
87+
Override the file path the tool gets your OpenAI token from. Alternatively, you can provide the token directly via `GPT_CMD_TOKEN`.
8488

8589
**Default**: `~/OPENAI_TOKEN`
8690

gpt_cmd.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def write_file(file_path, content):
3737
'model': os.environ.get('GPT_CMD_MODEL', 'gpt-4o'),
3838
'token_file_path': os.environ.get(
3939
'GPT_CMD_TOKEN_FILE_PATH',
40-
os.path.join(os.path.expanduser('~'), 'OPENAI_TOKEN'),
40+
os.path.join(os.path.expanduser('~'), 'OPENAI_TOKEN')
4141
),
4242
}
4343

@@ -79,7 +79,11 @@ def red(text):
7979
def call_gpt(messages):
8080
global OPENAI_CLIENT
8181
if OPENAI_CLIENT is None:
82-
OPENAI_CLIENT = OpenAI(api_key=read_file(OPTIONS['token_file_path']))
82+
token = os.environ.get(
83+
'GPT_CMD_TOKEN',
84+
read_file(OPTIONS['token_file_path'])
85+
)
86+
OPENAI_CLIENT = OpenAI(api_key=token)
8387

8488
response = OPENAI_CLIENT.chat.completions.create(
8589
model=OPTIONS['model'],

0 commit comments

Comments
 (0)