Skip to content

Commit d0270bb

Browse files
author
Zvonimir Sabljic
committed
Added api keys to be set within the command
1 parent 35346ee commit d0270bb

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/helpers/api.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const https = require('https');
22
const _ = require('lodash');
33
const axios = require('axios');
44
const {} = require('../utils/cmdPrint');
5+
const args = require('../utils/getArgs.js');
56

67
function extractGPTMessageFromStreamData(input) {
78
const regex = /data: (.*?)\n/g;
@@ -16,6 +17,8 @@ function extractGPTMessageFromStreamData(input) {
1617
}
1718

1819
function setOptions({protocol, hostname, port, path, method, headers}) {
20+
let apiKey = args.openai_api_key || args.pythagora_api_key;
21+
if (!apiKey) throw new Error('No API key provided. Please add --openai-api-key or --pythagora-api-key')
1922
let options = {
2023
protocol: protocol || 'https',
2124
hostname: hostname || 'api.pythagora.io',
@@ -24,8 +27,8 @@ function setOptions({protocol, hostname, port, path, method, headers}) {
2427
method: method || 'POST',
2528
headers: headers || {
2629
'Content-Type': 'application/json',
27-
'apikey': process.env.OPENAI_API_KEY || process.env.PYTHAGORA_API_KEY,
28-
'apikeytype': process.env.OPENAI_API_KEY ? 'openai' : 'pythagora'
30+
'apikey': apiKey,
31+
'apikeytype': args.openai_api_key ? 'openai' : 'pythagora'
2932
},
3033
};
3134

0 commit comments

Comments
 (0)