-
Notifications
You must be signed in to change notification settings - Fork 58
Adds some snippets in devsite that were missing and fixes a snippet start tag. #394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,63 @@ class Snippets { | |
self.model = model | ||
} | ||
|
||
func templateInitializeModel() { | ||
// [START template_initialize_model] | ||
// Initialize the Vertex AI service | ||
let vertex = VertexAI.vertexAI() | ||
|
||
// Initialize the generative model with a model that supports your use case | ||
// Gemini 1.5 Pro is versatile and can accept both text-only or multimodal prompt inputs | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. // Gemini 1.5 models are versatile and can be used with all API capabilities There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
let model = vertex.generativeModel(modelName: "{{generic_model_name_initialization}}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible for includecode and the snippet registry to work with DevSite variables like this? {{generic_model_name_initialization}} If so, could we pls change the explicit insertion of a model name in the other snippets to use this variable, too? :-D There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe. It depends on which templating thing runs first in devsite. I put this here without checking, but I can try it out in staging. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It does work! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Deleted this snippet and updated all others to use the template. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried moving these into the docs today and it doesn't work. Can't remember what I did to test that made them work. |
||
// [END template_initialize_model] | ||
} | ||
|
||
func configureModel() { | ||
let vertex = VertexAI.vertexAI() | ||
|
||
// [START configure_model] | ||
let config = GenerationConfig( | ||
temperature: 0.9, | ||
topP: 0.1, | ||
topK: 16, | ||
maxOutputTokens: 200, | ||
stopSequences: ["red"] | ||
) | ||
|
||
let model = vertex.generativeModel( | ||
modelName: "{{ '<var>MODEL_NAME</var>' }}", | ||
generationConfig: config | ||
) | ||
// [END configure_model] | ||
} | ||
|
||
func safetySettings() { | ||
let vertex = VertexAI.vertexAI() | ||
|
||
// [START safety_settings] | ||
let model = vertex.generativeModel( | ||
modelName: "{{ '<var>MODEL_NAME</var>' }}", | ||
safetySettings: [ | ||
SafetySetting(harmCategory: .harassment, threshold: .blockOnlyHigh) | ||
] | ||
) | ||
// [END safety_settings] | ||
} | ||
|
||
func multiSafetySettings() { | ||
let vertex = VertexAI.vertexAI() | ||
|
||
// [START multi_safety_settings] | ||
let harassmentSafety = SafetySetting(harmCategory: .harassment, threshold: .blockOnlyHigh) | ||
let hateSpeechSafety = SafetySetting(harmCategory: .hateSpeech, threshold: .blockMediumAndAbove) | ||
|
||
let model = vertex.generativeModel( | ||
modelName: "{{ '<var>MODEL_NAME</var>' }}", | ||
safetySettings: [harassmentSafety, hateSpeechSafety] | ||
) | ||
// END multi_safety_settings | ||
} | ||
|
||
func callGemini() async throws { | ||
// [START call_gemini] | ||
// Provide a prompt that contains text | ||
|
@@ -181,7 +238,6 @@ class Snippets { | |
} | ||
|
||
func textAndVideoPrompt() async throws { | ||
// AVFoundation support coming soon™ | ||
// [START text_video_prompt] | ||
guard let fileURL = Bundle.main.url(forResource: "sample", | ||
withExtension: "mp4") else { fatalError() } | ||
|
@@ -273,7 +329,7 @@ class Snippets { | |
let response = try await model.countTokens(image, "What's in this picture?") | ||
print("Total Tokens: \(response.totalTokens)") | ||
print("Total Billable Characters: \(response.totalBillableCharacters)") | ||
// [START count_tokens_text_image] | ||
// [END count_tokens_text_image] | ||
} | ||
|
||
func countTokensMultiImage() async throws { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the snippet registry... would we use this initialization snippet or the one added with #392?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved with the deletion of the other snippet and conversion of all snippets to template model name.