@@ -182,6 +182,38 @@ class Snippets {
182
182
183
183
func textAndVideoPrompt( ) async throws {
184
184
// AVFoundation support coming soon™
185
+ // [START text_video_prompt]
186
+ guard let fileURL = Bundle . main. url ( forResource: " sample " ,
187
+ withExtension: " mp4 " ) else { fatalError ( ) }
188
+ let video = try Data ( contentsOf: fileURL)
189
+ let prompt = " What's in this video? "
190
+ let videoContent = ModelContent . Part. data ( mimetype: " video/mp4 " , video)
191
+
192
+ // To generate text output, call generateContent and pass in the prompt
193
+ let response = try await model. generateContent ( videoContent, prompt)
194
+ if let text = response. text {
195
+ print ( text)
196
+ }
197
+ // [END text_video_prompt]
198
+ }
199
+
200
+ func textAndVideoPromptStreaming( ) async throws {
201
+ // AVFoundation support coming soon™
202
+ // [START text_video_prompt_streaming]
203
+ guard let fileURL = Bundle . main. url ( forResource: " sample " ,
204
+ withExtension: " mp4 " ) else { fatalError ( ) }
205
+ let video = try Data ( contentsOf: fileURL)
206
+ let prompt = " What's in this video? "
207
+ let videoContent = ModelContent . Part. data ( mimetype: " video/mp4 " , video)
208
+
209
+ // To stream generated text output, call generateContentStream and pass in the prompt
210
+ let contentStream = model. generateContentStream ( videoContent, prompt)
211
+ for try await chunk in contentStream {
212
+ if let text = chunk. text {
213
+ print ( text)
214
+ }
215
+ }
216
+ // [END text_video_prompt_streaming]
185
217
}
186
218
187
219
func chatStreaming( ) async throws {
0 commit comments