@@ -39,6 +39,63 @@ class Snippets {
39
39
self . model = model
40
40
}
41
41
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
+
42
99
func callGemini( ) async throws {
43
100
// [START call_gemini]
44
101
// Provide a prompt that contains text
@@ -181,7 +238,6 @@ class Snippets {
181
238
}
182
239
183
240
func textAndVideoPrompt( ) async throws {
184
- // AVFoundation support coming soon™
185
241
// [START text_video_prompt]
186
242
guard let fileURL = Bundle . main. url ( forResource: " sample " ,
187
243
withExtension: " mp4 " ) else { fatalError ( ) }
@@ -273,7 +329,7 @@ class Snippets {
273
329
let response = try await model. countTokens ( image, " What's in this picture? " )
274
330
print ( " Total Tokens: \( response. totalTokens) " )
275
331
print ( " Total Billable Characters: \( response. totalBillableCharacters) " )
276
- // [START count_tokens_text_image]
332
+ // [END count_tokens_text_image]
277
333
}
278
334
279
335
func countTokensMultiImage( ) async throws {
0 commit comments