Skip to content

Commit 3511cb8

Browse files
authored
Merge pull request #394 from firebase/mc/vertex
Adds some snippets in devsite that were missing and fixes a snippet start tag.
2 parents 4a331a9 + 9279006 commit 3511cb8

File tree

1 file changed

+58
-2
lines changed

1 file changed

+58
-2
lines changed

VertexAISnippets/VertexAISnippets/VertexAISnippets.swift

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,63 @@ class Snippets {
3939
self.model = model
4040
}
4141

42+
func templateInitializeModel() {
43+
// [START template_initialize_model]
44+
// Initialize the Vertex AI service
45+
let vertex = VertexAI.vertexAI()
46+
47+
// Initialize the generative model with a model that supports your use case
48+
// Gemini 1.5 Pro is versatile and can accept both text-only or multimodal prompt inputs
49+
let model = vertex.generativeModel(modelName: "{{generic_model_name_initialization}}")
50+
// [END template_initialize_model]
51+
}
52+
53+
func configureModel() {
54+
let vertex = VertexAI.vertexAI()
55+
56+
// [START configure_model]
57+
let config = GenerationConfig(
58+
temperature: 0.9,
59+
topP: 0.1,
60+
topK: 16,
61+
maxOutputTokens: 200,
62+
stopSequences: ["red"]
63+
)
64+
65+
let model = vertex.generativeModel(
66+
modelName: "{{ '<var>MODEL_NAME</var>' }}",
67+
generationConfig: config
68+
)
69+
// [END configure_model]
70+
}
71+
72+
func safetySettings() {
73+
let vertex = VertexAI.vertexAI()
74+
75+
// [START safety_settings]
76+
let model = vertex.generativeModel(
77+
modelName: "{{ '<var>MODEL_NAME</var>' }}",
78+
safetySettings: [
79+
SafetySetting(harmCategory: .harassment, threshold: .blockOnlyHigh)
80+
]
81+
)
82+
// [END safety_settings]
83+
}
84+
85+
func multiSafetySettings() {
86+
let vertex = VertexAI.vertexAI()
87+
88+
// [START multi_safety_settings]
89+
let harassmentSafety = SafetySetting(harmCategory: .harassment, threshold: .blockOnlyHigh)
90+
let hateSpeechSafety = SafetySetting(harmCategory: .hateSpeech, threshold: .blockMediumAndAbove)
91+
92+
let model = vertex.generativeModel(
93+
modelName: "{{ '<var>MODEL_NAME</var>' }}",
94+
safetySettings: [harassmentSafety, hateSpeechSafety]
95+
)
96+
// END multi_safety_settings
97+
}
98+
4299
func callGemini() async throws {
43100
// [START call_gemini]
44101
// Provide a prompt that contains text
@@ -181,7 +238,6 @@ class Snippets {
181238
}
182239

183240
func textAndVideoPrompt() async throws {
184-
// AVFoundation support coming soon™
185241
// [START text_video_prompt]
186242
guard let fileURL = Bundle.main.url(forResource: "sample",
187243
withExtension: "mp4") else { fatalError() }
@@ -273,7 +329,7 @@ class Snippets {
273329
let response = try await model.countTokens(image, "What's in this picture?")
274330
print("Total Tokens: \(response.totalTokens)")
275331
print("Total Billable Characters: \(response.totalBillableCharacters)")
276-
// [START count_tokens_text_image]
332+
// [END count_tokens_text_image]
277333
}
278334

279335
func countTokensMultiImage() async throws {

0 commit comments

Comments
 (0)