File tree Expand file tree Collapse file tree 3 files changed +10
-8
lines changed Expand file tree Collapse file tree 3 files changed +10
-8
lines changed Original file line number Diff line number Diff line change @@ -79,7 +79,7 @@ def __contains__(self, key: str) -> bool:
79
79
if key in self .model_fields_set :
80
80
return True
81
81
82
- if value := self .model_fields .get (key ):
82
+ if value := self .__class__ . model_fields .get (key ):
83
83
return value .default is not None
84
84
85
85
return False
@@ -313,7 +313,7 @@ class Function(SubscriptableBaseModel):
313
313
314
314
315
315
class Tool (SubscriptableBaseModel ):
316
- type : Optional [Literal [ 'function' ] ] = 'function'
316
+ type : Optional [str ] = 'function'
317
317
318
318
class Function (SubscriptableBaseModel ):
319
319
name : Optional [str ] = None
Original file line number Diff line number Diff line change @@ -79,11 +79,12 @@ def convert_function_to_tool(func: Callable) -> Tool:
79
79
}
80
80
81
81
tool = Tool (
82
+ type = 'function' ,
82
83
function = Tool .Function (
83
84
name = func .__name__ ,
84
85
description = schema .get ('description' , '' ),
85
86
parameters = Tool .Function .Parameters (** schema ),
86
- )
87
+ ),
87
88
)
88
89
89
90
return Tool .model_validate (tool )
Original file line number Diff line number Diff line change 8
8
9
9
import pytest
10
10
from httpx import Response as httpxResponse
11
- from pydantic import BaseModel , ValidationError
11
+ from pydantic import BaseModel
12
12
from pytest_httpserver import HTTPServer , URIPattern
13
13
from werkzeug .wrappers import Request , Response
14
14
@@ -1136,10 +1136,11 @@ def func2(y: str) -> int:
1136
1136
1137
1137
1138
1138
def test_tool_validation ():
1139
- # Raises ValidationError when used as it is a generator
1140
- with pytest .raises (ValidationError ):
1141
- invalid_tool = {'type' : 'invalid_type' , 'function' : {'name' : 'test' }}
1142
- list (_copy_tools ([invalid_tool ]))
1139
+ arbitrary_tool = {'type' : 'custom_type' , 'function' : {'name' : 'test' }}
1140
+ tools = list (_copy_tools ([arbitrary_tool ]))
1141
+ assert len (tools ) == 1
1142
+ assert tools [0 ].type == 'custom_type'
1143
+ assert tools [0 ].function .name == 'test'
1143
1144
1144
1145
1145
1146
def test_client_connection_error ():
You can’t perform that action at this time.
0 commit comments