Repository navigation
Expand file tree
/
Copy pathindex.ts
More file actions
146 lines (129 loc) ยท 4.05 KB
/
Copy pathindex.ts
File metadata and controls
146 lines (129 loc) ยท 4.05 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
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 { doArchitectSynthese } from "./synthese.js";
import { doArchitectThese } from "./these.js";
import fs from "node:fs";
export const doArchitect = async () => {
logger("์์ฒญ์ฌํญ์ ๋ฐ๋ฅธ ๊ฐ๋ฐ ๊ธฐํ์ ์งํ ์ค ์
๋๋ค...");
await speak("์์ฒญ์ฌํญ์ ๋ฐ๋ฅธ ๊ฐ๋ฐ ๊ธฐํ์ ์งํ ์ค ์
๋๋ค...");
let reviewCount = 1;
const preDialect = await doDialecticSynthese(userRequest, (these) => {
fs.writeFileSync(`./result/architect-ver-${reviewCount++}.txt`, these);
});
let isGoodToGo = preDialect.isGoodToGo;
let synthese = preDialect.synthese;
while (true) {
const dialect = await doDialectic({
isGoodToGo,
synthese,
reviewCount,
userRequest,
});
isGoodToGo = dialect.isGoodToGo;
synthese = `${dialect.synthese}`;
reviewCount += 1;
if (isGoodToGo) {
logger(
`๊ฐ๋ฐ ๊ธฐํ์ด ์๋ฃ๋์์ต๋๋ค. (${reviewCount} ๋ฒ์งธ ๊ฒํ ๋ง์ ์๋ฃ)`
);
await 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} ๋ฒ์งธ ๊ฒํ )`
);
await 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);
await speak(whatAntitheseDo);
} else {
logger("๊ฐ๋ฐ ๊ธฐํ์ ๋ณด์ํ๋ ์ค์
๋๋ค...");
}
// * Synthese ๊ตฌํ๊ธฐ
const synthese = await doArchitectSynthese(`${these}\n${antithese}`);
console.log(synthese);
const whatSyntheseDo = findWhatIdo(synthese);
if (whatSyntheseDo) {
logger(whatSyntheseDo);
await 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);
await 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);
await speak(whatAntitheseDo);
} else {
logger("๊ฐ๋ฐ ๊ธฐํ์ ๋ณด์ํ๋ ์ค์
๋๋ค...");
}
// * Synthese ๊ตฌํ๊ธฐ
const synthese = await doArchitectSynthese(`${these}\n${antithese}`);
console.log(synthese);
const whatSyntheseDo = findWhatIdo(synthese);
if (whatSyntheseDo) {
logger(whatSyntheseDo);
await speak(whatSyntheseDo);
} else {
logger("๊ฐ๋ฐ ๊ธฐํ์ ๊ฒํ ํ๋ ์ค์
๋๋ค...");
}
const isGoodToGo = findIsGoodToGo(synthese);
return {
isGoodToGo,
synthese: `----USER REQUEST\n${userRequest}\n${synthese}`,
};
};