forked from erfanium/commitgpt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.ts
48 lines (40 loc) · 1021 Bytes
/
config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import enquirer from "enquirer";
import { getConfig, setGlobalConfig } from "./config_storage.js";
async function promptToken() {
try {
const answer = await enquirer.prompt<{ apikey: string }>({
type: "password",
name: "apikey",
message: "Paste your OpenAI apikey here:",
});
return answer.apikey;
} catch (e) {
console.log("Aborted.");
process.exit(1);
}
}
export async function getApiKey(clean?: boolean): Promise<string> {
let apiKey = getConfig<string | undefined>("apiKey");
if (clean) {
apiKey = undefined;
}
if (!apiKey) {
apiKey = await promptToken();
setGlobalConfig("apiKey", apiKey);
}
return apiKey;
}
export async function getPromptOptions(): Promise<{
model: string;
temperature: number;
maxTokens: number;
}> {
const model = getConfig<string>("model");
const temperature = getConfig<number>("temperature");
const maxTokens = getConfig<number>("maxTokens");
return {
model,
temperature,
maxTokens,
};
}