mirror of
https://github.com/encounter/adk-python.git
synced 2026-07-09 18:19:28 -07:00
feat: Added support for enums as arguments for function tools (#3088)
* feat: Added support for enums as arguments for function tools * feat: Add default value support for function tools fix: Add more test cases inside `test_build_function_declaration.py` for passing Enums as arguments * fix: format code with pyink --------- Co-authored-by: Wei Sun (Jack) <weisun@google.com> Co-authored-by: Yvonne Yu <150068659+yyyu-google@users.noreply.github.com>
This commit is contained in:
co-authored by
Wei Sun
Yvonne Yu
parent
b17c8f19e5
commit
240ef5beea
@@ -12,6 +12,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from enum import Enum
|
||||
from typing import Dict
|
||||
from typing import List
|
||||
|
||||
@@ -22,6 +23,7 @@ from google.genai import types
|
||||
# TODO: crewai requires python 3.10 as minimum
|
||||
# from crewai_tools import FileReadTool
|
||||
from pydantic import BaseModel
|
||||
import pytest
|
||||
|
||||
|
||||
def test_string_input():
|
||||
@@ -220,6 +222,34 @@ def test_list():
|
||||
assert function_decl.parameters.properties['input_dir'].items.type == 'OBJECT'
|
||||
|
||||
|
||||
def test_enums():
|
||||
|
||||
class InputEnum(Enum):
|
||||
AGENT = 'agent'
|
||||
TOOL = 'tool'
|
||||
|
||||
def simple_function(input: InputEnum = InputEnum.AGENT):
|
||||
return input.value
|
||||
|
||||
function_decl = _automatic_function_calling_util.build_function_declaration(
|
||||
func=simple_function
|
||||
)
|
||||
|
||||
assert function_decl.name == 'simple_function'
|
||||
assert function_decl.parameters.type == 'OBJECT'
|
||||
assert function_decl.parameters.properties['input'].type == 'STRING'
|
||||
assert function_decl.parameters.properties['input'].default == 'agent'
|
||||
assert function_decl.parameters.properties['input'].enum == ['agent', 'tool']
|
||||
|
||||
def simple_function_with_wrong_enum(input: InputEnum = 'WRONG_ENUM'):
|
||||
return input.value
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
_automatic_function_calling_util.build_function_declaration(
|
||||
func=simple_function_with_wrong_enum
|
||||
)
|
||||
|
||||
|
||||
def test_basemodel_list():
|
||||
class ChildInput(BaseModel):
|
||||
input_str: str
|
||||
|
||||
Reference in New Issue
Block a user