Repository navigation
Expand file tree
/
Copy pathinput.ts
More file actions
156 lines (143 loc) ยท 4.64 KB
/
Copy pathinput.ts
File metadata and controls
156 lines (143 loc) ยท 4.64 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import { cli } from 'cleye'
import { input, password, select } from '@inquirer/prompts'
import { logger } from './utils/logger.js'
import { existsSync, readFileSync, writeFileSync } from 'node:fs'
import path from 'node:path'
import { dirname } from 'path'
import { fileURLToPath } from 'url'
// * Set __dirname and __filename
const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
// * Parse CLI arguments
const argv = cli({
name: 'friday',
version: '0.0.1',
flags: {
prompt: {
type: String,
description: 'Prompt to run',
alias: 'p'
}
}
})
let userRequest = argv._.join(' ')
// * Load config file
const configPath = path.join(__dirname, '../', '.fridayconfig.json')
let isConfigFileExist = existsSync(configPath)
if (isConfigFileExist) {
try {
const config = JSON.parse(readFileSync(configPath, 'utf-8'))
if (config.OPENAI_API_KEY)
process.env.OPENAI_API_KEY = config.OPENAI_API_KEY
if (config.OPENAI_CHAT_MODEL)
process.env.OPENAI_CHAT_MODEL = config.OPENAI_CHAT_MODEL
if (config.AZURE_SPEECH_KEY)
process.env.AZURE_SPEECH_KEY = config.AZURE_SPEECH_KEY
if (config.AZURE_SPEECH_REGION)
process.env.AZURE_SPEECH_REGION = config.AZURE_SPEECH_REGION
if (config.AZURE_SPEECH_VOICE)
process.env.AZURE_SPEECH_VOICE = config.AZURE_SPEECH_VOICE
} catch (e) {}
}
// * If OPENAI_API_KEY is empty, ask for it
if (!process.env.OPENAI_API_KEY || process.env.OPENAI_API_KEY.length === 0) {
logger(`Friday GPT ๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํด์ Open A.I API ํค๋ฅผ ์
๋ ฅํด์ผํฉ๋๋ค.`)
logger(`ํค ๋ฐ๊ธ ํ์ด์ง: https://platform.openai.com/account/api-keys`)
process.env.OPENAI_API_KEY = await password({
message: 'Open A.I API ํค๋ฅผ ์
๋ ฅํด์ฃผ์ธ์:'
})
if (!process.env.OPENAI_API_KEY || process.env.OPENAI_API_KEY.length === 0) {
logger('API ํค๊ฐ ์
๋ ฅ๋์ง ์์์ต๋๋ค. ํ๋ก๊ทธ๋จ์ ์ข
๋ฃํฉ๋๋ค.')
process.exit(0)
}
}
// * If OPENAI_CHAT_MODEL is empty, ask for it
if (
!process.env.OPENAI_CHAT_MODEL ||
process.env.OPENAI_CHAT_MODEL.length === 0
) {
process.env.OPENAI_CHAT_MODEL = await input({
message: '์ฌ์ฉํ๋ ค๋ ChatGPT ๋ชจ๋ธ์ ์
๋ ฅํด์ฃผ์ธ์:',
default: 'gpt-4'
})
if (
!process.env.OPENAI_CHAT_MODEL ||
process.env.OPENAI_CHAT_MODEL.length === 0
) {
logger('๋ชจ๋ธ์ด ์
๋ ฅ๋์ง ์์์ต๋๋ค. ํ๋ก๊ทธ๋จ์ ์ข
๋ฃํฉ๋๋ค.')
process.exit(0)
}
}
// * Optional asking section
if (!isConfigFileExist) {
// * If AZURE_SPEECH_KEY is empty, ask for it
if (
process.env.AZURE_SPEECH_KEY === undefined ||
process.env.AZURE_SPEECH_KEY === ''
) {
logger(`Azure Speech API ํค๋ฅผ ์
๋ ฅํ์๋ฉด ์ธ๊ณต์ง๋ฅ์ด ์์ฑ์ผ๋ก ๋ต๋ณํฉ๋๋ค.`)
logger(
`ํค ๋ฐ๊ธ ํ์ด์ง: https://portal.azure.com/?quickstart=true#view/Microsoft_Azure_ProjectOxford/CognitiveServicesHub/~/SpeechServices`
)
const isNeedAzureSpeech = await select({
message: 'Azure Speech API ํค๋ฅผ ์
๋ ฅํ๊ณ TTS๋ฅผ ์ฌ์ฉํ์๊ฒ ์ต๋๊น?',
choices: [
{
name: '๋ค',
value: true
},
{
name: '์๋์ค',
value: false
}
]
})
if (isNeedAzureSpeech) {
process.env.AZURE_SPEECH_KEY = await password({
message: 'Azure Speech API ํค๋ฅผ ์
๋ ฅํด์ฃผ์ธ์:'
})
process.env.AZURE_SPEECH_REGION = await input({
message: 'Azure Speech API ์ง์ญ์ ์
๋ ฅํด์ฃผ์ธ์:',
default: 'koreacentral'
})
process.env.AZURE_SPEECH_VOICE = await input({
message: 'Azure Speech API ์์ฑ์ ์
๋ ฅํด์ฃผ์ธ์:',
default: 'ko-KR-SeoHyeonNeural'
})
}
}
}
// * If userRequest is empty, use the provided default value
if (userRequest === '') {
userRequest = await input({
message: 'A.I๊ฐ ์ํํ ๊ฐ๋ฐ ์
๋ฌด ์์ฒญ์ ์
๋ ฅํด์ฃผ์ธ์:'
})
if (userRequest === '') {
logger('์์ฒญ์ด ์์ต๋๋ค. ํ๋ก๊ทธ๋จ์ ์ข
๋ฃํฉ๋๋ค.')
process.exit(0)
}
}
// * Save config file
writeFileSync(
configPath,
JSON.stringify(
{
OPENAI_API_KEY: process.env.OPENAI_API_KEY,
OPENAI_CHAT_MODEL: process.env.OPENAI_CHAT_MODEL,
AZURE_SPEECH_KEY: process.env.AZURE_SPEECH_KEY,
AZURE_SPEECH_REGION: process.env.AZURE_SPEECH_REGION,
AZURE_SPEECH_VOICE: process.env.AZURE_SPEECH_VOICE
},
null,
2
)
)
export { userRequest }
export const countConfig = {
architect: {
// * ์ด๊ธฐ ๊ธฐํ์๋ฅผ ๋ช ๊ฐ๊น์ง ๋ง๋ค๊ณ ๊ณ ๋ฏผํ ์ง ์ค์ ํฉ๋๋ค.
draftCount: 3,
// * ๊ธฐํ์ ๋ณด์์ ์ํ ํ์๋ฅผ ์ต๋ ๋ช ๋ฒ๊น์ง ์งํ ํ ์ง ์ค์ ํฉ๋๋ค.
maxMeetingCount: 10
}
}