Skip to content

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

Merged
merged 3 commits into from
Apr 26, 2024
Merged

Add vertex snippets #392

merged 3 commits into from
Apr 26, 2024

Conversation

morganchen12
Copy link
Contributor

No description provided.

Copy link
Contributor

@andrewheard andrewheard left a 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.

Comment on lines +142 to +143
guard let image1 = UIImage(named: "image1") else { fatalError() }
guard let image2 = UIImage(named: "image2") else { fatalError() }
Copy link
Contributor

@andrewheard andrewheard Apr 25, 2024

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.

Note: These are what those symbols look like.
Screenshot 2024-04-25 at 11 21 28 AM

Copy link
Contributor Author

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]
}

Copy link
Contributor

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?

Copy link
Contributor Author

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.

@morganchen12 morganchen12 merged commit 81bd5ee into master Apr 26, 2024
Copy link

@rachelsaunders rachelsaunders left a 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 {

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.

Copy link
Contributor Author

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 {

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.

Copy link
Contributor Author

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]

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]

Copy link
Contributor Author

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.

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.

Copy link
Contributor Author

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]

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]

Copy link
Contributor Author

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]

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]

Copy link
Contributor Author

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 {

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.

Copy link
Contributor Author

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]

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]

Copy link
Contributor Author

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]

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]

Copy link
Contributor Author

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

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants