-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcontextGenerators.ts
203 lines (178 loc) · 5.67 KB
/
contextGenerators.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
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
import { getRandomEmoji } from "./utils/emoji";
function generateSegmentBoundaries(
transcript: StoryTranscript[],
storyComponents: StoryComponent[]
): string {
const segments: string[] = [];
let currentComponentOrder = transcript[0]?.componentOrder;
let startIndex = 0;
for (let i = 0; i < transcript.length; i++) {
const entry = transcript[i];
if (entry.componentOrder !== currentComponentOrder) {
const component = storyComponents.find(
(c) => c.order === currentComponentOrder
);
segments.push(`${startIndex}: {
title: "${getRandomEmoji()} ${component?.title || ""}",
location: \`${component?.location?.name || "Unknown Location"}\`,
description: \`${component?.description || ""}\`,
endIndex: ${i - 1},
}`);
currentComponentOrder = entry.componentOrder;
startIndex = i;
}
}
// Last segment
if (startIndex < transcript.length) {
const component = storyComponents.find(
(c) => c.order === currentComponentOrder
);
segments.push(`${startIndex}: {
title: "${getRandomEmoji()} ${component?.title || "Unknown Scene"}",
location: \`${component?.location?.name || "Unknown Location"}\`,
description: \`${component?.description || ""}\`,
endIndex: ${transcript.length - 1},
}`);
}
return segments.join(",\n ");
}
function invariantContext(context: string) {
if (!context.includes("initialAgentName")) {
throw new Error("initialAgentName is required in context");
}
if (!context.includes("subtitlesFileName")) {
throw new Error("subtitlesFileName is required in context");
}
if (
context.includes("storyName") &&
!context.includes("segmentBoundaries")
) {
throw new Error("segmentBoundaries is required for story contexts");
}
// Optional fields with defaults
let updatedContext = context;
if (!context.includes("fps")) {
updatedContext += "\nexport const fps = 60;";
}
// Meme-specific fields
if (!context.includes("ticker")) {
updatedContext += '\nexport const ticker = "";';
}
if (!context.includes("tradingViewSymbol")) {
updatedContext += '\nexport const tradingViewSymbol = "";';
}
if (!context.includes("currentPrice")) {
updatedContext += "\nexport const currentPrice = 0;";
}
if (!context.includes("marketCap")) {
updatedContext += "\nexport const marketCap = 0;";
}
if (!context.includes("percentageChange")) {
updatedContext += "\nexport const percentageChange = 0;";
}
// Story-specific fields
if (!context.includes("seasonNumber")) {
updatedContext += "\nexport const seasonNumber = 1;";
}
if (!context.includes("storyName")) {
updatedContext += '\nexport const storyName = "";';
}
if (!context.includes("seasonName")) {
updatedContext += '\nexport const seasonName = "";';
}
if (!context.includes("episodeNumber")) {
updatedContext += "\nexport const episodeNumber = 1;";
}
if (!context.includes("segmentBoundaries")) {
updatedContext += `\nexport const segmentBoundaries = {
0: {
title: "🎬 Default Scene",
location: "Unknown Location",
description: "Default scene description",
endIndex: 0
}
};`;
}
return updatedContext;
}
export function generateStoryContextContent(
audios: {
agentId: string;
audio: string;
index: number;
}[],
transcript: StoryTranscript[],
season: Season,
story: Story,
storyComponents: StoryComponent[]
): string {
const context = `
import { staticFile } from 'remotion';
export const music: string = 'none';
export const fps = 60;
export const seasonNumber = 1;
export const seasonName = '${season.title}';
export const episodeNumber = ${story.episode_number};
export const storyName = '${story.title}';
export const segmentBoundaries = {
${generateSegmentBoundaries(transcript, storyComponents)}
};
export const initialAgentName = '${audios[0].agentId}';
export const subtitlesFileName = [
${audios
.map(
(entry) => `{
name: '${entry.agentId}',
file: staticFile('srt/${entry.agentId}-${entry.index}.srt'),
}`
)
.join(",\n ")}
];`;
return invariantContext(context);
}
export function generateMemeContextContent(
audios: {
agentId: string;
audio: string;
index: number;
tweet_id?: string;
}[],
agentA: AgentId,
agentB: AgentId,
duration: number,
fps: number = 60,
music: Music = "none",
ticker: string,
tradingViewSymbol: string,
currentPrice: number,
marketCap: number,
percentageChange: number
): string {
const context = `
import { staticFile } from 'remotion';
export const music: string = ${
music === "none" ? `'none'` : `'/music/${music}.mp3'`
};
export const fps = ${fps};
export const duration = ${duration * 60};
export const agentA = '${agentA}';
export const agentB = '${agentB}';
export const initialAgentName = '${audios[0].agentId}';
export const ticker = '${ticker}';
export const tradingViewSymbol = '${tradingViewSymbol}';
export const currentPrice = ${currentPrice};
export const marketCap = ${marketCap};
export const percentageChange = ${percentageChange};
export const subtitlesFileName = [
${audios
.map(
(entry) => `{
name: '${entry.agentId}',
file: staticFile('srt/${entry.agentId}-${entry.index}.srt'),
${entry.tweet_id ? `tweet_id: '${entry.tweet_id}',` : ""}
}`
)
.join(",\n ")}
];`;
return invariantContext(context);
}