Skip to content

Commit 185f9a8

Browse files
committed
Add video snippets
1 parent 948f54e commit 185f9a8

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

VertexAISnippets/VertexAISnippets/VertexAISnippets.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,38 @@ class Snippets {
182182

183183
func textAndVideoPrompt() async throws {
184184
// 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]
185217
}
186218

187219
func chatStreaming() async throws {

0 commit comments

Comments
 (0)