Repository navigation
Expand file tree
/
Copy pathindex.ts
More file actions
177 lines (153 loc) ยท 5.02 KB
/
Copy pathindex.ts
File metadata and controls
177 lines (153 loc) ยท 5.02 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import { countConfig } from '../input.js'
import { userRequest } from '../input.js'
import { logger } from '../utils/logger.js'
import { findIsGoodToGo, findWhatIdo } from '../utils/match.js'
import { speak } from '../utils/speak.js'
import { doArchitectAntithese } from './antithese.js'
import { doArchitectSelection } from './selection.js'
import { doArchitectSynthese } from './synthese.js'
import { doArchitectThese } from './these.js'
import fs from 'node:fs'
export const doArchitect = async () => {
logger(
`์์ฒญ์ฌํญ์ ๋ฐ๋ฅธ ${countConfig.architect.draftCount}๊ฐ์ง ๊ฐ๊ธฐ ๋ค๋ฅธ ๊ธฐํ ์์์ ์์ฑ ์ค์
๋๋ค.\n`
)
speak(
`์์ฒญ์ฌํญ์ ๋ฐ๋ฅธ ${countConfig.architect.draftCount}๊ฐ์ง ๊ฐ๊ธฐ ๋ค๋ฅธ ๊ธฐํ ์์์ ์์ฑ ์ค์
๋๋ค.`
)
const drafts: string[] = []
for (let i = 1; i <= countConfig.architect.draftCount; i++) {
const draft = await doArchitectThese(userRequest)
drafts.push(draft)
const whatTheseDo = findWhatIdo(draft)
console.log(draft)
if (whatTheseDo) {
logger(`์์ ${i} ์์ฝ: ${whatTheseDo}`)
speak(`์์ ${i} ์์ฝ: ${whatTheseDo}`)
} else {
logger(`๊ฐ๋ฐ ๊ธฐํ์ ์ธ์ฐ๋ ์ค์
๋๋ค...`)
}
fs.writeFileSync(`./result/architect-draft-${i}.txt`, draft)
}
let bestDraftNumber = 1
if (countConfig.architect.draftCount !== 1) {
const bestDraftSelection = await doArchitectSelection(drafts)
console.log(bestDraftSelection)
try {
const json = '{' + bestDraftSelection?.split('{')?.[1]?.split('```')[0]
const parsed = JSON.parse(json)
bestDraftNumber = parsed.bestDraftNumber
logger(`${parsed.bestDraftNumber}๋ฒ ์์์ด ์ ํ๋์์ต๋๋ค.`)
speak(`${parsed.bestDraftNumber}๋ฒ ์์์ด ์ ํ๋์์ต๋๋ค.`)
bestDraftNumber = parsed.bestDraftNumber - 1
} catch (e) {}
}
let reviewCount = 1
let isGoodToGo = false
let synthese = drafts[bestDraftNumber]
while (true) {
const dialect = await doDialectic({
isGoodToGo,
synthese,
reviewCount,
userRequest
})
isGoodToGo = dialect.isGoodToGo
synthese = `${dialect.synthese}`
reviewCount += 1
if (isGoodToGo) {
logger(`๊ฐ๋ฐ ๊ธฐํ์ด ์๋ฃ๋์์ต๋๋ค. (${reviewCount} ๋ฒ์งธ ๊ฒํ ๋ง์ ์๋ฃ)`)
speak(
`๊ฐ๋ฐ ๊ธฐํ์ด ์๋ฃ๋์์ต๋๋ค. ${reviewCount} ๋ฒ์งธ ๊ฒํ ๋ง์ ์๋ฃ๋์์ต๋๋ค.`
)
fs.writeFileSync(`./result/architect-ver-${reviewCount}.txt`, synthese)
return synthese
}
}
}
export const doDialectic = async ({
isGoodToGo,
synthese: these,
reviewCount,
userRequest
}: {
isGoodToGo: boolean
synthese: string
reviewCount?: number
userRequest?: string
}) => {
if (isGoodToGo) {
return { isGoodToGo, synthese: these }
} else {
logger(`๊ฐ๋ฐ ๊ธฐํ์ ์ถ๊ฐ๋ก ๋ณด์ํ๊ณ ์์ต๋๋ค... (${reviewCount} ๋ฒ์งธ ๊ฒํ )`)
speak(`๊ฐ๋ฐ ๊ธฐํ์ ์ถ๊ฐ๋ก ๋ณด์ํ๊ณ ์์ต๋๋ค... (${reviewCount} ๋ฒ์งธ ๊ฒํ )`)
fs.writeFileSync(`./result/architect-ver-${reviewCount}.txt`, these)
const antithese = await doArchitectAntithese(these)
console.log(antithese)
const whatAntitheseDo = findWhatIdo(antithese)
if (whatAntitheseDo) {
logger(whatAntitheseDo)
speak(whatAntitheseDo)
} else {
logger('๊ฐ๋ฐ ๊ธฐํ์ ๋ณด์ํ๋ ์ค์
๋๋ค...')
}
// * Synthese ๊ตฌํ๊ธฐ
const synthese = await doArchitectSynthese(`${these}\n${antithese}`)
console.log(synthese)
const whatSyntheseDo = findWhatIdo(synthese)
if (whatSyntheseDo) {
logger(whatSyntheseDo)
speak(whatSyntheseDo)
} else {
logger('๊ฐ๋ฐ ๊ธฐํ์ ๊ฒํ ํ๋ ์ค์
๋๋ค...')
}
const isGoodToGo = findIsGoodToGo(synthese)
return {
isGoodToGo,
synthese: `----USER REQUEST\n${userRequest}\n${synthese}`
}
}
}
export const doDialecticSynthese = async (
userRequest: string,
onThese: (these: string) => unknown
) => {
// * These ๊ตฌํ๊ธฐ
const these = await doArchitectThese(userRequest)
console.log(these)
onThese(these)
const whatTheseDo = findWhatIdo(these)
if (whatTheseDo) {
logger(whatTheseDo)
speak(whatTheseDo)
} else {
logger('๊ฐ๋ฐ ๊ธฐํ์ ์ธ์ฐ๋ ์ค์
๋๋ค...')
}
// * Antithese ๊ตฌํ๊ธฐ
const antithese = await doArchitectAntithese(
`----USER REQUEST\n${userRequest}\n${these}`
)
console.log(antithese)
const whatAntitheseDo = findWhatIdo(antithese)
if (whatAntitheseDo) {
logger(whatAntitheseDo)
speak(whatAntitheseDo)
} else {
logger('๊ฐ๋ฐ ๊ธฐํ์ ๋ณด์ํ๋ ์ค์
๋๋ค...')
}
// * Synthese ๊ตฌํ๊ธฐ
const synthese = await doArchitectSynthese(`${these}\n${antithese}`)
console.log(synthese)
const whatSyntheseDo = findWhatIdo(synthese)
if (whatSyntheseDo) {
logger(whatSyntheseDo)
speak(whatSyntheseDo)
} else {
logger('๊ฐ๋ฐ ๊ธฐํ์ ๊ฒํ ํ๋ ์ค์
๋๋ค...')
}
const isGoodToGo = findIsGoodToGo(synthese)
return {
isGoodToGo,
synthese: `----USER REQUEST\n${userRequest}\n${synthese}`
}
}