Skip to content

Commit 288731c

Browse files
authored
Merge pull request #36 from GlebkaF/jsondb-for-generations-2
Добавлена поддержка базы данных для генераций: реализован класс Gener…
2 parents 1f8a3ae + 92e7fd1 commit 288731c

File tree

14 files changed

+1333
-185
lines changed

14 files changed

+1333
-185
lines changed

data/generations.json

Lines changed: 449 additions & 0 deletions
Large diffs are not rendered by default.

lib/ai-generator/create-generator.ts

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
// import { createDefaultChain } from "lib/core/helpers/create-default-chain";
21
import { Chain } from "../core/interface";
32
import OpenAI from "openai";
43
import { createOpenAIClient } from "lib/ai-generator/helpers/create-openai-client";
54
import {
65
BlockTypesConfig,
76
createEmptyChain,
87
} from "lib/core/helpers/create-chain";
9-
import fs from "fs/promises";
10-
import path from "path";
8+
import { generationDb } from "../jsondb";
119

1210
import {
1311
createProDescriptionSystemPrompt,
@@ -33,19 +31,10 @@ interface RealRig {
3331
settings: unknown;
3432
}
3533

36-
interface GeneratorResult {
37-
timestamp: string;
38-
originalPrompt: string;
39-
proDescription: ProDescription;
40-
realRig: RealRig;
41-
42-
finalChain: Chain;
43-
}
44-
4534
class ChainGenerator {
4635
constructor(private openai: OpenAI) {}
4736

48-
async generate(prompt: string): Promise<Chain> {
37+
async generate(prompt: string): Promise<string> {
4938
const proDescription = await this.createProDescription(prompt);
5039
const realRig = await this.createRealRig(proDescription);
5140
const emptyChain = await this.createEmptyChain(realRig);
@@ -54,16 +43,16 @@ class ChainGenerator {
5443
console.log(proDescription);
5544
console.log(realRig);
5645

57-
// Сохраняем результаты в файл
58-
await this.saveResults({
46+
// Сохраняем результаты в базу данных
47+
const generationId = await this.saveToDatabase({
5948
timestamp: new Date().toISOString(),
6049
originalPrompt: prompt,
6150
proDescription,
6251
realRig,
6352
finalChain,
6453
});
6554

66-
return finalChain;
55+
return generationId;
6756
}
6857

6958
private async createProDescription(prompt: string): Promise<ProDescription> {
@@ -144,27 +133,19 @@ class ChainGenerator {
144133
return JSON.parse(responseText) as unknown;
145134
}
146135

147-
private async saveResults(result: GeneratorResult): Promise<void> {
136+
private async saveToDatabase(result: {
137+
timestamp: string;
138+
originalPrompt: string;
139+
proDescription: ProDescription;
140+
realRig: RealRig;
141+
finalChain: Chain;
142+
}): Promise<string> {
148143
try {
149-
// Создаём директорию для результатов, если её нет
150-
const resultsDir = path.join(process.cwd(), "generator-results");
151-
await fs.mkdir(resultsDir, { recursive: true });
152-
153-
// Формируем имя файла с временной меткой
154-
const timestamp = new Date()
155-
.toISOString()
156-
.replace(/[:.]/g, "-")
157-
.slice(0, -5); // Убираем миллисекунды и Z
158-
const filename = `chain-generation-${timestamp}.json`;
159-
const filepath = path.join(resultsDir, filename);
160-
161-
// Сохраняем результаты в файл
162-
await fs.writeFile(filepath, JSON.stringify(result, null, 2), "utf-8");
163-
164-
console.log(`\n✅ Результаты сохранены в: ${filepath}`);
144+
const generationId = await generationDb.addGeneration(result);
145+
return generationId;
165146
} catch (error) {
166-
console.error("❌ Ошибка при сохранении результатов:", error);
167-
// Не прерываем выполнение, если сохранение не удалось
147+
console.error("❌ Ошибка при сохранении в базу данных:", error);
148+
throw error;
168149
}
169150
}
170151
}

lib/core/__snapshots__/config.test.ts.snap

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ exports[`Config > compressor should to match snapshot 1`] = `
3535
"label": "Bright",
3636
},
3737
],
38-
"realName": "Jazz Clean",
38+
"realName": "Roland Jazz Chorus-120",
3939
},
4040
{
4141
"encodeType": 2,
@@ -1952,7 +1952,7 @@ exports[`Config > compressor should to match snapshot 1`] = `
19521952
"label": "Sustain",
19531953
},
19541954
],
1955-
"realName": "Keeley Compressor",
1955+
"realName": "Ross Compressor",
19561956
},
19571957
],
19581958
},
@@ -2095,7 +2095,7 @@ exports[`Config > compressor should to match snapshot 1`] = `
20952095
"label": "Sensitivity",
20962096
},
20972097
],
2098-
"realName": "Distortion+",
2098+
"realName": "MXR Distortion+",
20992099
},
21002100
{
21012101
"encodeType": 2,
@@ -2118,7 +2118,7 @@ exports[`Config > compressor should to match snapshot 1`] = `
21182118
"label": "Treble",
21192119
},
21202120
],
2121-
"realName": "RC Boost",
2121+
"realName": "Xotic RC Booster",
21222122
},
21232123
{
21242124
"encodeType": 3,
@@ -2141,7 +2141,7 @@ exports[`Config > compressor should to match snapshot 1`] = `
21412141
"label": "Treble",
21422142
},
21432143
],
2144-
"realName": "AC Boost",
2144+
"realName": "Xotic AC Booster",
21452145
},
21462146
{
21472147
"encodeType": 4,
@@ -2160,7 +2160,7 @@ exports[`Config > compressor should to match snapshot 1`] = `
21602160
"label": "Tone",
21612161
},
21622162
],
2163-
"realName": "Dist One",
2163+
"realName": "Boss DS-1 Distortion",
21642164
},
21652165
{
21662166
"encodeType": 5,
@@ -2179,7 +2179,7 @@ exports[`Config > compressor should to match snapshot 1`] = `
21792179
"label": "Tone",
21802180
},
21812181
],
2182-
"realName": "T Screamer",
2182+
"realName": "Ibanez Tube Screamer",
21832183
},
21842184
{
21852185
"encodeType": 6,
@@ -2198,7 +2198,7 @@ exports[`Config > compressor should to match snapshot 1`] = `
21982198
"label": "Tone",
21992199
},
22002200
],
2201-
"realName": "Blues Drive",
2201+
"realName": "Boss BD-2 Blues Driver",
22022202
},
22032203
{
22042204
"encodeType": 7,
@@ -2217,7 +2217,7 @@ exports[`Config > compressor should to match snapshot 1`] = `
22172217
"label": "Tone",
22182218
},
22192219
],
2220-
"realName": "Morning Drive",
2220+
"realName": "Marshall Blues Breaker",
22212221
},
22222222
{
22232223
"encodeType": 8,
@@ -2236,7 +2236,7 @@ exports[`Config > compressor should to match snapshot 1`] = `
22362236
"label": "Filter",
22372237
},
22382238
],
2239-
"realName": "Eat Dist",
2239+
"realName": "ProCo RAT 2",
22402240
},
22412241
{
22422242
"encodeType": 9,
@@ -2255,7 +2255,7 @@ exports[`Config > compressor should to match snapshot 1`] = `
22552255
"label": "Tone",
22562256
},
22572257
],
2258-
"realName": "Red Dirt",
2258+
"realName": "JHS Red Dirt",
22592259
},
22602260
{
22612261
"encodeType": 10,
@@ -2274,7 +2274,7 @@ exports[`Config > compressor should to match snapshot 1`] = `
22742274
"label": "Tone",
22752275
},
22762276
],
2277-
"realName": "Crunch",
2277+
"realName": "Marshall Crunch",
22782278
},
22792279
{
22802280
"encodeType": 11,
@@ -2293,7 +2293,7 @@ exports[`Config > compressor should to match snapshot 1`] = `
22932293
"label": "Tone",
22942294
},
22952295
],
2296-
"realName": "Muff Fuzz",
2296+
"realName": "Electro-Harmonix Big Muff",
22972297
},
22982298
{
22992299
"encodeType": 12,
@@ -2308,7 +2308,7 @@ exports[`Config > compressor should to match snapshot 1`] = `
23082308
"label": "Boost",
23092309
},
23102310
],
2311-
"realName": "Katana",
2311+
"realName": "Boss Katana Clean Boost",
23122312
},
23132313
{
23142314
"encodeType": 13,
@@ -2327,7 +2327,7 @@ exports[`Config > compressor should to match snapshot 1`] = `
23272327
"label": "Filter",
23282328
},
23292329
],
2330-
"realName": "ST Singer",
2330+
"realName": "Single Tube Singer",
23312331
},
23322332
{
23332333
"encodeType": 14,
@@ -2354,7 +2354,7 @@ exports[`Config > compressor should to match snapshot 1`] = `
23542354
"label": "Up/Down Switch",
23552355
},
23562356
],
2357-
"realName": "Touch Wah",
2357+
"realName": "Dunlop Crybaby Touch Wah",
23582358
},
23592359
],
23602360
},
@@ -2716,7 +2716,7 @@ exports[`Config > compressor should to match snapshot 1`] = `
27162716
"label": "Decay",
27172717
},
27182718
],
2719-
"realName": "Noise Gate",
2719+
"realName": "Boss NS-2 Noise Suppressor",
27202720
},
27212721
],
27222722
},
@@ -2740,7 +2740,7 @@ exports[`Config > compressor should to match snapshot 1`] = `
27402740
"label": "Tone",
27412741
},
27422742
],
2743-
"realName": "Room Reverb",
2743+
"realName": "Room",
27442744
},
27452745
{
27462746
"encodeType": 2,
@@ -2763,7 +2763,7 @@ exports[`Config > compressor should to match snapshot 1`] = `
27632763
"label": "Liveliness",
27642764
},
27652765
],
2766-
"realName": "Hall Reverb",
2766+
"realName": "Hall",
27672767
},
27682768
{
27692769
"encodeType": 3,
@@ -2778,7 +2778,7 @@ exports[`Config > compressor should to match snapshot 1`] = `
27782778
"label": "Decay",
27792779
},
27802780
],
2781-
"realName": "Plate Reverb",
2781+
"realName": "Plate",
27822782
},
27832783
{
27842784
"encodeType": 4,
@@ -2793,7 +2793,7 @@ exports[`Config > compressor should to match snapshot 1`] = `
27932793
"label": "Decay",
27942794
},
27952795
],
2796-
"realName": "Spring Reverb",
2796+
"realName": "Spring",
27972797
},
27982798
{
27992799
"encodeType": 5,
@@ -2812,7 +2812,7 @@ exports[`Config > compressor should to match snapshot 1`] = `
28122812
"label": "Shimmer",
28132813
},
28142814
],
2815-
"realName": "Shimmer Reverb",
2815+
"realName": "Shimmer",
28162816
},
28172817
{
28182818
"encodeType": 6,
@@ -2827,7 +2827,7 @@ exports[`Config > compressor should to match snapshot 1`] = `
28272827
"label": "Depth",
28282828
},
28292829
],
2830-
"realName": "Damp Reverb",
2830+
"realName": "Damp",
28312831
},
28322832
],
28332833
},

lib/core/blocks/noisegate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const noisegate: BlockConfig = {
1919
types: [
2020
{
2121
label: NoiseGateType.NoiseGate,
22-
realName: "Noise Gate",
22+
realName: "Boss NS-2 Noise Suppressor",
2323
encodeType: NOISE_GATE_TYPES[NoiseGateType.NoiseGate],
2424
params: [
2525
{

0 commit comments

Comments
 (0)