MCPcopy
hub / github.com/CapSoftware/Cap / startAiGeneration

Function startAiGeneration

apps/web/lib/generate-ai.ts:15–107  ·  view source on GitHub ↗
(
	videoId: Video.VideoId,
	userId: string,
)

Source from the content-addressed store, hash-verified

13};
14
15export async function startAiGeneration(
16 videoId: Video.VideoId,
17 userId: string,
18): Promise<GenerateAiResult> {
19 if (!serverEnv().GROQ_API_KEY && !serverEnv().OPENAI_API_KEY) {
20 return {
21 success: false,
22 message: "Missing AI API keys (Groq or OpenAI)",
23 };
24 }
25
26 if (!userId || !videoId) {
27 return {
28 success: false,
29 message: "userId or videoId not supplied",
30 };
31 }
32
33 const query = await db()
34 .select({ video: videos })
35 .from(videos)
36 .where(eq(videos.id, videoId));
37
38 if (query.length === 0 || !query[0]?.video) {
39 return { success: false, message: "Video does not exist" };
40 }
41
42 const { video } = query[0];
43
44 if (video.transcriptionStatus !== "COMPLETE") {
45 return {
46 success: false,
47 message: "Transcription not complete",
48 };
49 }
50
51 const metadata = (video.metadata as VideoMetadata) || {};
52
53 if (
54 metadata.aiGenerationStatus === "PROCESSING" ||
55 metadata.aiGenerationStatus === "QUEUED"
56 ) {
57 return {
58 success: true,
59 message: "AI generation already in progress",
60 };
61 }
62
63 if (
64 metadata.aiGenerationStatus === "COMPLETE" &&
65 metadata.summary &&
66 metadata.chapters
67 ) {
68 return {
69 success: true,
70 message: "AI metadata already generated",
71 };
72 }

Callers 4

getVideoStatusFunction · 0.90
queueAiGenerationFunction · 0.90
POSTFunction · 0.90
GETFunction · 0.90

Calls 4

serverEnvFunction · 0.90
dbFunction · 0.90
startFunction · 0.90
updateMethod · 0.80

Tested by

no test coverage detected