@@ -30,18 +30,13 @@ defmodule CF.LLMs.StatementsCreator do
30
30
Create statements from a video that has captions using LLMs
31
31
"""
32
32
def process_video! ( video_id ) do
33
- DB.Schema.Video
34
- |> join ( :inner , [ v ] , vc in DB.Schema.VideoCaption , on: v . id == vc . video_id )
35
- |> where ( [ v , vc ] , v . id == ^ video_id )
36
- |> order_by ( [ v , vc ] , desc: vc . inserted_at )
37
- |> limit ( 1 )
38
- |> select ( [ v , vc ] , { v , vc } )
39
- |> DB.Repo . one ( )
40
- |> case do
33
+ video = DB.Repo . get ( DB.Schema.Video , video_id )
34
+
35
+ case fetch_or_download_captions ( video ) do
41
36
nil ->
42
- raise "Video or captions not found"
37
+ raise "Video captions not found"
43
38
44
- { video , video_caption } ->
39
+ video_caption ->
45
40
video_caption . parsed
46
41
|> chunk_captions ( )
47
42
|> Enum . map ( fn captions ->
@@ -56,6 +51,23 @@ defmodule CF.LLMs.StatementsCreator do
56
51
end
57
52
end
58
53
54
+ defp fetch_or_download_captions ( video ) do
55
+ case DB.Schema.VideoCaption
56
+ |> where ( [ vc ] , vc . video_id == ^ video . id )
57
+ |> order_by ( desc: :inserted_at )
58
+ |> limit ( 1 )
59
+ |> DB.Repo . one ( ) do
60
+ nil ->
61
+ case CF.Videos . download_captions ( video ) do
62
+ { :ok , video_caption } -> video_caption
63
+ _ -> nil
64
+ end
65
+
66
+ video_caption ->
67
+ video_caption
68
+ end
69
+ end
70
+
59
71
@ doc """
60
72
Chunk captions everytime we reach the max caption length
61
73
"""
0 commit comments