File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -76,7 +76,7 @@ def _raise_if_schema_unsupported(
7676):
7777 if variant == GoogleLLMVariant .GEMINI_API :
7878 _raise_for_any_of_if_mldev (schema )
79- _update_for_default_if_mldev (schema )
79+ # _update_for_default_if_mldev(schema) # No need of this since GEMINI now supports default value
8080
8181
8282def _is_default_value_compatible (
@@ -150,9 +150,10 @@ def _parse_schema_from_parameter(
150150 schema .type = types .Type .STRING
151151 schema .enum = [e .value for e in param .annotation ]
152152 if param .default is not inspect .Parameter .empty :
153- if not _is_default_value_compatible (param .default , param .annotation ):
153+ default_value = param .default .value if isinstance (param .default , Enum ) else param .default
154+ if default_value not in schema .enum :
154155 raise ValueError (default_value_error_msg )
155- schema .default = param . default
156+ schema .default = default_value
156157 _raise_if_schema_unsupported (variant , schema )
157158 return schema
158159 if (
Original file line number Diff line number Diff line change 2323# from crewai_tools import FileReadTool
2424from pydantic import BaseModel
2525from enum import Enum
26+ import pytest
2627
2728def test_string_input ():
2829 def simple_function (input_str : str ) -> str :
@@ -225,7 +226,7 @@ class InputEnum(Enum):
225226 AGENT = "agent"
226227 TOOL = "tool"
227228
228- def simple_function (input :InputEnum ):
229+ def simple_function (input :InputEnum = InputEnum . AGENT ):
229230 return input .value
230231
231232 function_decl = _automatic_function_calling_util .build_function_declaration (
@@ -235,8 +236,16 @@ def simple_function(input:InputEnum):
235236 assert function_decl .name == 'simple_function'
236237 assert function_decl .parameters .type == 'OBJECT'
237238 assert function_decl .parameters .properties ['input' ].type == 'STRING'
239+ assert function_decl .parameters .properties ['input' ].default == 'agent'
238240 assert function_decl .parameters .properties ['input' ].enum == ['agent' , 'tool' ]
239241
242+ def simple_function_with_wrong_enum (input :InputEnum = "WRONG_ENUM" ):
243+ return input .value
244+
245+ with pytest .raises (ValueError ):
246+ _automatic_function_calling_util .build_function_declaration (
247+ func = simple_function_with_wrong_enum
248+ )
240249
241250def test_basemodel_list ():
242251 class ChildInput (BaseModel ):
You can’t perform that action at this time.
0 commit comments