Skip to content

Commit 559b7e9

Browse files
committed
🚀 feat(config.ts api.ts): add support for OCO_OPENAI_VERSION environment variable to specify the API version
The OCO_OPENAI_VERSION config key has been added to allow specifying the version of the OpenAI API to use. A validation function has been added to ensure that the value of OCO_OPENAI_VERSION is a string in the format of YYYY-MM-DD. This ensures that the value is a valid date and can be used to specify the version of the OpenAI API to use. 🚀 新機能(config.ts api.ts): OCO_OPENAI_VERSION設定キーを追加して、OpenAI APIバージョンを指定できるようにしました OCO_OPENAI_VERSION設定キーを追加して、使用するOpenAI APIのバージョンを指定できるようにしました。OCO_OPENAI_VERSIONの値がYYYY-MM-DD形式の文字列であることを確認するバリデーション関数を追加しました。これにより、値が有効な日付であり、OpenAI APIのバージョンを指定するために使用できることが保証されます。
1 parent 496d524 commit 559b7e9

4 files changed

Lines changed: 57 additions & 25 deletions

File tree

out/cli.cjs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3478,7 +3478,7 @@ var require_http = __commonJS({
34783478
var httpsFollow2 = require_follow_redirects().https;
34793479
var url3 = require("url");
34803480
var zlib2 = require("zlib");
3481-
var VERSION3 = require_data().version;
3481+
var VERSION4 = require_data().version;
34823482
var createError = require_createError();
34833483
var enhanceError = require_enhanceError();
34843484
var transitionalDefaults = require_transitional();
@@ -3530,7 +3530,7 @@ var require_http = __commonJS({
35303530
delete headers[headerNames["user-agent"]];
35313531
}
35323532
} else {
3533-
headers["User-Agent"] = "axios/" + VERSION3;
3533+
headers["User-Agent"] = "axios/" + VERSION4;
35343534
}
35353535
if (data && !utils.isStream(data)) {
35363536
if (Buffer.isBuffer(data)) {
@@ -4068,7 +4068,7 @@ var require_mergeConfig = __commonJS({
40684068
var require_validator = __commonJS({
40694069
"node_modules/openai/node_modules/axios/lib/helpers/validator.js"(exports, module2) {
40704070
"use strict";
4071-
var VERSION3 = require_data().version;
4071+
var VERSION4 = require_data().version;
40724072
var validators3 = {};
40734073
["object", "boolean", "number", "function", "string", "symbol"].forEach(function(type, i2) {
40744074
validators3[type] = function validator(thing) {
@@ -4078,7 +4078,7 @@ var require_validator = __commonJS({
40784078
var deprecatedWarnings2 = {};
40794079
validators3.transitional = function transitional2(validator, version, message) {
40804080
function formatMessage(opt, desc) {
4081-
return "[Axios v" + VERSION3 + "] Transitional option '" + opt + "'" + desc + (message ? ". " + message : "");
4081+
return "[Axios v" + VERSION4 + "] Transitional option '" + opt + "'" + desc + (message ? ". " + message : "");
40824082
}
40834083
return function(value, opt, opts) {
40844084
if (validator === false) {
@@ -17691,6 +17691,14 @@ var configValidators = {
1769117691
);
1769217692
return value;
1769317693
},
17694+
["OCO_OPENAI_VERSION" /* OCO_OPENAI_VERSION */](value) {
17695+
validateConfig(
17696+
"OCO_OPENAI_VERSION" /* OCO_OPENAI_VERSION */,
17697+
typeof value === "string" && value.match(/^[1-9][0-9]{3}-[01][0-9]-[0-3][0-9]/),
17698+
"Must be start with YYYY-MM-DD string"
17699+
);
17700+
return value;
17701+
},
1769417702
["OCO_MODEL" /* OCO_MODEL */](value) {
1769517703
validateConfig(
1769617704
"OCO_MODEL" /* OCO_MODEL */,
@@ -17717,6 +17725,7 @@ var getConfig = () => {
1771717725
OCO_OPENAI_MAX_TOKENS: process.env.OCO_OPENAI_MAX_TOKENS ? Number(process.env.OCO_OPENAI_MAX_TOKENS) : void 0,
1771817726
OCO_OPENAI_BASE_PATH: process.env.OCO_OPENAI_BASE_PATH,
1771917727
OCO_OPENAI_API_TYPE: process.env.OCO_OPENAI_API_TYPE,
17728+
OCO_OPENAI_VERSION: process.env.OCO_OPENAI_VERSION || "2023-05-15",
1772017729
OCO_DESCRIPTION: process.env.OCO_DESCRIPTION === "true" ? true : false,
1772117730
OCO_EMOJI: process.env.OCO_EMOJI === "true" ? true : false,
1772217731
OCO_MODEL: process.env.OCO_MODEL || "gpt-3.5-turbo",
@@ -21758,6 +21767,7 @@ if (!apiKey && command !== "config" && mode !== "set" /* set */) {
2175821767
process.exit(1);
2175921768
}
2176021769
var MODEL = config2?.OCO_MODEL || "gpt-3.5-turbo";
21770+
var VERSION3 = config2?.OCO_OPENAI_VERSION || "2023-05-15";
2176121771
var OpenAi = class {
2176221772
openAiApiConfiguration = new import_openai.Configuration({
2176321773
apiKey
@@ -21771,7 +21781,7 @@ var OpenAi = class {
2177121781
"api-key": apiKey
2177221782
},
2177321783
params: {
21774-
"api-version": "2023-03-15-preview"
21784+
"api-version": VERSION3
2177521785
}
2177621786
};
2177721787
if (basePath) {

out/github-action.cjs

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2768,8 +2768,8 @@ var require_dist_node2 = __commonJS({
27682768
parse
27692769
});
27702770
}
2771-
var VERSION3 = "6.0.12";
2772-
var userAgent = `octokit-endpoint.js/${VERSION3} ${universalUserAgent.getUserAgent()}`;
2771+
var VERSION4 = "6.0.12";
2772+
var userAgent = `octokit-endpoint.js/${VERSION4} ${universalUserAgent.getUserAgent()}`;
27732773
var DEFAULTS = {
27742774
method: "GET",
27752775
baseUrl: "https://api.github.com",
@@ -5857,7 +5857,7 @@ var require_dist_node5 = __commonJS({
58575857
var isPlainObject2 = require_is_plain_object();
58585858
var nodeFetch = _interopDefault(require_lib3());
58595859
var requestError = require_dist_node4();
5860-
var VERSION3 = "5.6.3";
5860+
var VERSION4 = "5.6.3";
58615861
function getBufferResponse(response) {
58625862
return response.arrayBuffer();
58635863
}
@@ -5990,7 +5990,7 @@ var require_dist_node5 = __commonJS({
59905990
}
59915991
var request = withDefaults(endpoint.endpoint, {
59925992
headers: {
5993-
"user-agent": `octokit-request.js/${VERSION3} ${universalUserAgent.getUserAgent()}`
5993+
"user-agent": `octokit-request.js/${VERSION4} ${universalUserAgent.getUserAgent()}`
59945994
}
59955995
});
59965996
exports.request = request;
@@ -6004,7 +6004,7 @@ var require_dist_node6 = __commonJS({
60046004
Object.defineProperty(exports, "__esModule", { value: true });
60056005
var request = require_dist_node5();
60066006
var universalUserAgent = require_dist_node();
6007-
var VERSION3 = "4.8.0";
6007+
var VERSION4 = "4.8.0";
60086008
function _buildMessageForResponseErrors(data) {
60096009
return `Request failed due to following response errors:
60106010
` + data.errors.map((e2) => ` - ${e2.message}`).join("\n");
@@ -6078,7 +6078,7 @@ var require_dist_node6 = __commonJS({
60786078
}
60796079
var graphql$1 = withDefaults(request.request, {
60806080
headers: {
6081-
"user-agent": `octokit-graphql.js/${VERSION3} ${universalUserAgent.getUserAgent()}`
6081+
"user-agent": `octokit-graphql.js/${VERSION4} ${universalUserAgent.getUserAgent()}`
60826082
},
60836083
method: "POST",
60846084
url: "/graphql"
@@ -6183,7 +6183,7 @@ var require_dist_node8 = __commonJS({
61836183
}
61846184
return target;
61856185
}
6186-
var VERSION3 = "3.6.0";
6186+
var VERSION4 = "3.6.0";
61876187
var _excluded = ["authStrategy"];
61886188
var Octokit = class {
61896189
constructor(options = {}) {
@@ -6199,7 +6199,7 @@ var require_dist_node8 = __commonJS({
61996199
format: ""
62006200
}
62016201
};
6202-
requestDefaults.headers["user-agent"] = [options.userAgent, `octokit-core.js/${VERSION3} ${universalUserAgent.getUserAgent()}`].filter(Boolean).join(" ");
6202+
requestDefaults.headers["user-agent"] = [options.userAgent, `octokit-core.js/${VERSION4} ${universalUserAgent.getUserAgent()}`].filter(Boolean).join(" ");
62036203
if (options.baseUrl) {
62046204
requestDefaults.baseUrl = options.baseUrl;
62056205
}
@@ -6271,7 +6271,7 @@ var require_dist_node8 = __commonJS({
62716271
return NewOctokit;
62726272
}
62736273
};
6274-
Octokit.VERSION = VERSION3;
6274+
Octokit.VERSION = VERSION4;
62756275
Octokit.plugins = [];
62766276
exports.Octokit = Octokit;
62776277
}
@@ -7273,7 +7273,7 @@ var require_dist_node9 = __commonJS({
72737273
updateAuthenticated: ["PATCH /user"]
72747274
}
72757275
};
7276-
var VERSION3 = "5.16.2";
7276+
var VERSION4 = "5.16.2";
72777277
function endpointsToMethods(octokit2, endpointsMap) {
72787278
const newMethods = {};
72797279
for (const [scope, endpoints] of Object.entries(endpointsMap)) {
@@ -7338,14 +7338,14 @@ var require_dist_node9 = __commonJS({
73387338
rest: api2
73397339
};
73407340
}
7341-
restEndpointMethods.VERSION = VERSION3;
7341+
restEndpointMethods.VERSION = VERSION4;
73427342
function legacyRestEndpointMethods(octokit2) {
73437343
const api2 = endpointsToMethods(octokit2, Endpoints);
73447344
return _objectSpread2(_objectSpread2({}, api2), {}, {
73457345
rest: api2
73467346
});
73477347
}
7348-
legacyRestEndpointMethods.VERSION = VERSION3;
7348+
legacyRestEndpointMethods.VERSION = VERSION4;
73497349
exports.legacyRestEndpointMethods = legacyRestEndpointMethods;
73507350
exports.restEndpointMethods = restEndpointMethods;
73517351
}
@@ -7356,7 +7356,7 @@ var require_dist_node10 = __commonJS({
73567356
"node_modules/@octokit/plugin-paginate-rest/dist-node/index.js"(exports) {
73577357
"use strict";
73587358
Object.defineProperty(exports, "__esModule", { value: true });
7359-
var VERSION3 = "2.21.3";
7359+
var VERSION4 = "2.21.3";
73607360
function ownKeys(object, enumerableOnly) {
73617361
var keys = Object.keys(object);
73627362
if (Object.getOwnPropertySymbols) {
@@ -7499,7 +7499,7 @@ var require_dist_node10 = __commonJS({
74997499
})
75007500
};
75017501
}
7502-
paginateRest.VERSION = VERSION3;
7502+
paginateRest.VERSION = VERSION4;
75037503
exports.composePaginateRest = composePaginateRest;
75047504
exports.isPaginatingEndpoint = isPaginatingEndpoint;
75057505
exports.paginateRest = paginateRest;
@@ -10655,7 +10655,7 @@ var require_http = __commonJS({
1065510655
var httpsFollow2 = require_follow_redirects().https;
1065610656
var url2 = require("url");
1065710657
var zlib2 = require("zlib");
10658-
var VERSION3 = require_data().version;
10658+
var VERSION4 = require_data().version;
1065910659
var createError = require_createError();
1066010660
var enhanceError = require_enhanceError();
1066110661
var transitionalDefaults = require_transitional();
@@ -10707,7 +10707,7 @@ var require_http = __commonJS({
1070710707
delete headers[headerNames["user-agent"]];
1070810708
}
1070910709
} else {
10710-
headers["User-Agent"] = "axios/" + VERSION3;
10710+
headers["User-Agent"] = "axios/" + VERSION4;
1071110711
}
1071210712
if (data && !utils.isStream(data)) {
1071310713
if (Buffer.isBuffer(data)) {
@@ -11245,7 +11245,7 @@ var require_mergeConfig = __commonJS({
1124511245
var require_validator = __commonJS({
1124611246
"node_modules/openai/node_modules/axios/lib/helpers/validator.js"(exports, module2) {
1124711247
"use strict";
11248-
var VERSION3 = require_data().version;
11248+
var VERSION4 = require_data().version;
1124911249
var validators3 = {};
1125011250
["object", "boolean", "number", "function", "string", "symbol"].forEach(function(type, i2) {
1125111251
validators3[type] = function validator(thing) {
@@ -11255,7 +11255,7 @@ var require_validator = __commonJS({
1125511255
var deprecatedWarnings2 = {};
1125611256
validators3.transitional = function transitional2(validator, version, message) {
1125711257
function formatMessage(opt, desc) {
11258-
return "[Axios v" + VERSION3 + "] Transitional option '" + opt + "'" + desc + (message ? ". " + message : "");
11258+
return "[Axios v" + VERSION4 + "] Transitional option '" + opt + "'" + desc + (message ? ". " + message : "");
1125911259
}
1126011260
return function(value, opt, opts) {
1126111261
if (validator === false) {
@@ -27713,6 +27713,14 @@ var configValidators = {
2771327713
);
2771427714
return value;
2771527715
},
27716+
["OCO_OPENAI_VERSION" /* OCO_OPENAI_VERSION */](value) {
27717+
validateConfig(
27718+
"OCO_OPENAI_VERSION" /* OCO_OPENAI_VERSION */,
27719+
typeof value === "string" && value.match(/^[1-9][0-9]{3}-[01][0-9]-[0-3][0-9]/),
27720+
"Must be start with YYYY-MM-DD string"
27721+
);
27722+
return value;
27723+
},
2771627724
["OCO_MODEL" /* OCO_MODEL */](value) {
2771727725
validateConfig(
2771827726
"OCO_MODEL" /* OCO_MODEL */,
@@ -27739,6 +27747,7 @@ var getConfig = () => {
2773927747
OCO_OPENAI_MAX_TOKENS: process.env.OCO_OPENAI_MAX_TOKENS ? Number(process.env.OCO_OPENAI_MAX_TOKENS) : void 0,
2774027748
OCO_OPENAI_BASE_PATH: process.env.OCO_OPENAI_BASE_PATH,
2774127749
OCO_OPENAI_API_TYPE: process.env.OCO_OPENAI_API_TYPE,
27750+
OCO_OPENAI_VERSION: process.env.OCO_OPENAI_VERSION || "2023-05-15",
2774227751
OCO_DESCRIPTION: process.env.OCO_DESCRIPTION === "true" ? true : false,
2774327752
OCO_EMOJI: process.env.OCO_EMOJI === "true" ? true : false,
2774427753
OCO_MODEL: process.env.OCO_MODEL || "gpt-3.5-turbo",
@@ -27958,6 +27967,7 @@ if (!apiKey && command !== "config" && mode !== "set" /* set */) {
2795827967
process.exit(1);
2795927968
}
2796027969
var MODEL = config2?.OCO_MODEL || "gpt-3.5-turbo";
27970+
var VERSION3 = config2?.OCO_OPENAI_VERSION || "2023-05-15";
2796127971
var OpenAi = class {
2796227972
openAiApiConfiguration = new import_openai.Configuration({
2796327973
apiKey
@@ -27971,7 +27981,7 @@ var OpenAi = class {
2797127981
"api-key": apiKey
2797227982
},
2797327983
params: {
27974-
"api-version": "2023-03-15-preview"
27984+
"api-version": VERSION3
2797527985
}
2797627986
};
2797727987
if (basePath) {

src/api.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ if (!apiKey && command !== 'config' && mode !== CONFIG_MODES.set) {
3939
}
4040

4141
const MODEL = config?.OCO_MODEL || 'gpt-3.5-turbo';
42+
const VERSION = config?.OCO_OPENAI_VERSION || '2023-05-15';
4243

4344
class OpenAi {
4445
private openAiApiConfiguration = new OpenAiApiConfiguration({
@@ -54,7 +55,7 @@ class OpenAi {
5455
"api-key": apiKey,
5556
},
5657
params: {
57-
'api-version': '2023-03-15-preview',
58+
'api-version': VERSION,
5859
}
5960
};
6061
if (basePath) {

src/commands/config.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export enum CONFIG_KEYS {
1818
OCO_OPENAI_MAX_TOKENS = 'OCO_OPENAI_MAX_TOKENS',
1919
OCO_OPENAI_BASE_PATH = 'OCO_OPENAI_BASE_PATH',
2020
OCO_OPENAI_API_TYPE = 'OCO_OPENAI_API_TYPE',
21+
OCO_OPENAI_VERSION = 'OCO_OPENAI_VERSION',
2122
OCO_DESCRIPTION = 'OCO_DESCRIPTION',
2223
OCO_EMOJI = 'OCO_EMOJI',
2324
OCO_MODEL = 'OCO_MODEL',
@@ -142,6 +143,15 @@ export const configValidators = {
142143
return value;
143144
},
144145

146+
[CONFIG_KEYS.OCO_OPENAI_VERSION](value: any) {
147+
validateConfig(
148+
CONFIG_KEYS.OCO_OPENAI_VERSION,
149+
typeof value === 'string' && value.match(/^[1-9][0-9]{3}-[01][0-9]-[0-3][0-9]/),
150+
'Must be start with YYYY-MM-DD string'
151+
);
152+
return value;
153+
},
154+
145155
[CONFIG_KEYS.OCO_MODEL](value: any) {
146156
validateConfig(
147157
CONFIG_KEYS.OCO_MODEL,
@@ -178,6 +188,7 @@ export const getConfig = (): ConfigType | null => {
178188
OCO_OPENAI_MAX_TOKENS: process.env.OCO_OPENAI_MAX_TOKENS ? Number(process.env.OCO_OPENAI_MAX_TOKENS) : undefined,
179189
OCO_OPENAI_BASE_PATH: process.env.OCO_OPENAI_BASE_PATH,
180190
OCO_OPENAI_API_TYPE: process.env.OCO_OPENAI_API_TYPE,
191+
OCO_OPENAI_VERSION: process.env.OCO_OPENAI_VERSION || '2023-05-15',
181192
OCO_DESCRIPTION: process.env.OCO_DESCRIPTION === 'true' ? true : false,
182193
OCO_EMOJI: process.env.OCO_EMOJI === 'true' ? true : false,
183194
OCO_MODEL: process.env.OCO_MODEL || 'gpt-3.5-turbo',

0 commit comments

Comments
 (0)