-
Notifications
You must be signed in to change notification settings - Fork 6.6k
feat(vertex-ai): function calling: convert markdown 'samples' to python #12811
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
Open
Valeriy-Burlaka
wants to merge
14
commits into
main
Choose a base branch
from
vburlaka-vertexai-markdown-samples
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+300
−1
Open
Changes from 3 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
ac8aaaa
feat: convert markdown sample for function calling to python
Valeriy-Burlaka 9134412
fix region tag name
Valeriy-Burlaka b0788f5
fix? basic example is no longer working with gemini-flash
Valeriy-Burlaka 693f914
mark broken openai samples as skip
Valeriy-Burlaka ade95c7
fix test name
Valeriy-Burlaka d7f744b
fix test name
Valeriy-Burlaka 5b9e49b
fix checks; add experimental 2-tag sample
Valeriy-Burlaka 2772747
fix import order
Valeriy-Burlaka 1f8c008
fix import order
Valeriy-Burlaka 6e34636
fix typo in region tag
Valeriy-Burlaka 9e73443
Merge branch 'main' into vburlaka-vertexai-markdown-samples
Valeriy-Burlaka 98df51c
wip: re-work markdown 'how to create...' section into python
Valeriy-Burlaka 87aa2a4
update test prompt to execute the 'sales' func declaration
Valeriy-Burlaka 26f725a
feat(vertex-ai): function-calling api: 'example syntax'
Valeriy-Burlaka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
generative_ai/function_calling/declare_function_from_function.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# Copyright 2024 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import os | ||
|
||
from typing import List | ||
|
||
from vertexai.generative_models import FunctionDeclaration | ||
|
||
|
||
PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") | ||
|
||
|
||
def prototype(): | ||
# [START generativeaionvertexai_gemini_function_calling_declare_from_function] | ||
# Define a function. Could be a local function or you can import the requests library to call an API | ||
def multiply_numbers(numbers: List[int]) -> int: | ||
""" | ||
Calculates the product of all numbers in an array. | ||
|
||
Args: | ||
numbers: An array of numbers to be multiplied. | ||
|
||
Returns: | ||
The product of all the numbers. If the array is empty, returns 1. | ||
""" | ||
|
||
if not numbers: # Handle empty array | ||
return 1 | ||
|
||
product = 1 | ||
for num in numbers: | ||
product *= num | ||
|
||
return product | ||
|
||
multiply_number_func = FunctionDeclaration.from_func(multiply_numbers) | ||
|
||
''' | ||
multiply_number_func contains the following schema: | ||
|
||
name: "multiply_numbers" | ||
description: "Calculates the product of all numbers in an array." | ||
parameters { | ||
type_: OBJECT | ||
properties { | ||
key: "numbers" | ||
value { | ||
description: "An array of numbers to be multiplied." | ||
title: "Numbers" | ||
} | ||
} | ||
required: "numbers" | ||
description: "Calculates the product of all numbers in an array." | ||
title: "multiply_numbers" | ||
} | ||
''' | ||
# [END generativeaionvertexai_gemini_function_calling_declare_from_function] | ||
return multiply_number_func | ||
|
||
|
||
if __name__ == "__main__": | ||
prototype() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this 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.
Gemini Flash is not working anymore with this code sample (see the log):
The actual response from the model is now:
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.
Created a general issue to initiate the discussion about current CI process.
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 for reporting this, Valeriy-Burlaka. The Gemini Flash model appears to have been deprecated. The change to
gemini-1.5-pro-002
in the pull request reflects the current, supported model. Your created issue is the appropriate place to track the broader CI implications.