-
Notifications
You must be signed in to change notification settings - Fork 58
Add vertex snippets #392
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
Add vertex snippets #392
Conversation
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.
Thanks, Morgan! These all LGTM and I tested them against the latest commit to the vertex-ai branch with no issues.
guard let image1 = UIImage(named: "image1") else { fatalError() } | ||
guard let image2 = UIImage(named: "image2") else { fatalError() } |
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.
Feel free to ignore this idea, not sure if it'll be confusing or not. We could use SF Symbols like:
guard let image1 = UIImage(systemName: "photo") else { fatalError() }
guard let image2 = UIImage(systemName: "photo.fill") else { fatalError() }
The first picture has a black background, while the second picture has a white background.
It would mean someone could copy/paste the snippet into their code directly and try it without any additional set up. Devs would need to remember to switch to UIImage.init(named:)
, or another constructor, when using their own images though.
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.
These snippets are just compiling, not running. So I'm ok with leaving them as-is despite the fact that when run they'll immediately encounter the fatalError
.
) | ||
// [END set_safety_settings] | ||
} | ||
|
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.
Do you plan to add any function calling snippets in a follow-up PR or will we wait to document that feature?
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.
I'll do function calling snippets in a follow-up.
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.
thank you SO much for getting these into the snippet registry so quickly :-D
self.model = model | ||
} | ||
|
||
func callGemini() 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.
I think this is just a dup of the text-gen-from-text snippet, right? If so, I don't think we need this. On the getting started page, we'll just use the text-gen-from-text snippet.
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.
Removed.
// [END call_gemini] | ||
} | ||
|
||
func callGeminiStreaming() 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.
I think this is just a dup of the text-gen-from-text-streaming snippet, right? If so, I don't think we need this. On the getting started page, we'll just use the text-gen-from-text-streaming snippet.
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.
Removed.
} | ||
|
||
func sendTextOnlyPromptStreaming() async throws { | ||
// [START text_only_prompt_streaming] |
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.
[START text_only_prompt_streaming] => [START text_gen_text_only_prompt_streaming]
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.
Done.
// [END text_only_prompt_streaming] | ||
} | ||
|
||
// Note: This is the same as the call gemini prompt, but may change in the future. |
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.
I think this is the one that we want to keep and remove the "call gemini" one above.
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.
Ack
|
||
// Note: This is the same as the call gemini prompt, but may change in the future. | ||
func sendTextOnlyPromt() async throws { | ||
// [START text_only_prompt] |
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.
[START text_only_prompt] => [START text_gen_text_only_prompt]
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.
Done.
} | ||
|
||
func textAndVideoPromptStreaming() async throws { | ||
// [START text_video_prompt_streaming] |
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.
[START text_video_prompt_streaming] => [START text_gen_multimodal_video_prompt_streaming]
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.
Done.
// [END chat] | ||
} | ||
|
||
func countTokensText() 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.
question on these count tokens and billable chars snippets... can they be embedded inside each of the main snippets above? With region tags added?
On the count tokens docs page, I'd like to be able to show count tokens in the context of the other code. And using special includecode syntax, there's a way to hide specific parts of a code snippet. So, I can hide the count tokens bit in the main pages of the guides and only expose it in the count tokens page.
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.
I don't think there's a way to nest snippets inside the exclude syntax, but you could certainly put them side by side.
} | ||
|
||
func setSafetySetting() { | ||
// [START set_safety_setting] |
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.
[START set_safety_setting] => [START set_one_safety_setting]
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.
Done.
} | ||
|
||
func setMultipleSafetySettings() { | ||
// [START set_safety_settings] |
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.
[START set_safety_settings] => [START set_multi_safety_settings]
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.
Done.
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
No description provided.