Skip to content

Commit 57e4ec9

Browse files
committed
Add more devsite snippets
1 parent 40d4703 commit 57e4ec9

File tree

1 file changed

+57
-1
lines changed

1 file changed

+57
-1
lines changed

VertexAISnippets/VertexAISnippets/VertexAISnippets.swift

Lines changed: 57 additions & 1 deletion
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() }

0 commit comments

Comments
 (0)