mirror of
https://github.com/EvolutionAPI/adk-python.git
synced 2025-07-13 15:14:50 -06:00
set param required tag to False by default
PiperOrigin-RevId: 754382785
This commit is contained in:
parent
24024f7fc4
commit
5846b24b71
@ -27,7 +27,7 @@
|
||||
### ⚠ BREAKING CHANGES
|
||||
|
||||
* Auth: expose `access_token` and `refresh_token` at top level of auth
|
||||
credentials, instead of a `dict`
|
||||
credentails, instead of a `dict`
|
||||
([commit](https://github.com/google/adk-python/commit/956fb912e8851b139668b1ccb8db10fd252a6990)).
|
||||
|
||||
### Features
|
||||
@ -50,7 +50,7 @@
|
||||
|
||||
### Miscellaneous Chores
|
||||
|
||||
* README.md improvements.
|
||||
* README.md impprovements.
|
||||
* Various code improvements.
|
||||
* Various typo fixes.
|
||||
* Bump min version of google-genai to 1.11.0.
|
||||
@ -108,4 +108,4 @@
|
||||
* Built-in evaluation support
|
||||
* Development UI that makes local development easy
|
||||
* Deploy to Google Cloud Run, Agent Engine
|
||||
* (Experimental) Live(Bidi) audio/video agent support and Compositional Function Calling(CFC) support
|
||||
* (Experimental) Live(Bidi) auido/video agent support and Compositional Function Calling(CFC) support
|
||||
|
@ -484,11 +484,9 @@ class DatabaseSessionService(BaseSessionService):
|
||||
|
||||
if storage_session.update_time.timestamp() > session.last_update_time:
|
||||
raise ValueError(
|
||||
f"Session last_update_time "
|
||||
f"{datetime.fromtimestamp(session.last_update_time):%Y-%m-%d %H:%M:%S} "
|
||||
f"is later than the update_time in storage "
|
||||
f"{storage_session.update_time:%Y-%m-%d %H:%M:%S}"
|
||||
)
|
||||
f"Session last_update_time {session.last_update_time} is later than"
|
||||
f" the upate_time in storage {storage_session.update_time}"
|
||||
)
|
||||
|
||||
# Fetch states from storage
|
||||
storage_app_state = sessionFactory.get(
|
||||
|
@ -14,11 +14,7 @@
|
||||
|
||||
import keyword
|
||||
import re
|
||||
from typing import Any
|
||||
from typing import Dict
|
||||
from typing import List
|
||||
from typing import Optional
|
||||
from typing import Union
|
||||
from typing import Any, Dict, List, Optional, Union
|
||||
|
||||
from fastapi.openapi.models import Response
|
||||
from fastapi.openapi.models import Schema
|
||||
@ -100,7 +96,7 @@ class ApiParameter(BaseModel):
|
||||
py_name: Optional[str] = ''
|
||||
type_value: type[Any] = Field(default=None, init_var=False)
|
||||
type_hint: str = Field(default=None, init_var=False)
|
||||
required: Optional[bool] = None
|
||||
required: bool = False
|
||||
|
||||
def model_post_init(self, _: Any):
|
||||
self.py_name = (
|
||||
|
@ -17,9 +17,13 @@ from textwrap import dedent
|
||||
from typing import Any, Dict, List, Optional, Union
|
||||
|
||||
from fastapi.encoders import jsonable_encoder
|
||||
from fastapi.openapi.models import Operation, Parameter, Schema
|
||||
from fastapi.openapi.models import Operation
|
||||
from fastapi.openapi.models import Parameter
|
||||
from fastapi.openapi.models import Schema
|
||||
|
||||
from ..common.common import ApiParameter, PydocHelper, to_snake_case
|
||||
from ..common.common import ApiParameter
|
||||
from ..common.common import PydocHelper
|
||||
from ..common.common import to_snake_case
|
||||
|
||||
|
||||
class OperationParser:
|
||||
@ -76,7 +80,9 @@ class OperationParser:
|
||||
description = param.description or ''
|
||||
location = param.in_ or ''
|
||||
schema = param.schema_ or {} # Use schema_ instead of .schema
|
||||
schema.description = description if schema.description is None and description != '' else schema.description
|
||||
schema.description = (
|
||||
description if not schema.description else schema.description
|
||||
)
|
||||
required = param.required
|
||||
|
||||
self.params.append(
|
||||
@ -85,7 +91,7 @@ class OperationParser:
|
||||
param_location=location,
|
||||
param_schema=schema,
|
||||
description=description,
|
||||
required=required
|
||||
required=required,
|
||||
)
|
||||
)
|
||||
|
||||
@ -233,7 +239,7 @@ class OperationParser:
|
||||
}
|
||||
return {
|
||||
'properties': properties,
|
||||
'required': [p.py_name for p in self.params if p.required is not False],
|
||||
'required': [p.py_name for p in self.params if p.required],
|
||||
'title': f"{self.operation.operationId or 'unnamed'}_Arguments",
|
||||
'type': 'object',
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ class TestRestApiTool:
|
||||
return mock_parser
|
||||
|
||||
@pytest.fixture
|
||||
def sample_endpoint(self):
|
||||
def sample_endpiont(self):
|
||||
return OperationEndpoint(
|
||||
base_url="https://example.com", path="/test", method="GET"
|
||||
)
|
||||
@ -131,7 +131,7 @@ class TestRestApiTool:
|
||||
|
||||
def test_init(
|
||||
self,
|
||||
sample_endpoint,
|
||||
sample_endpiont,
|
||||
sample_operation,
|
||||
sample_auth_scheme,
|
||||
sample_auth_credential,
|
||||
@ -139,14 +139,14 @@ class TestRestApiTool:
|
||||
tool = RestApiTool(
|
||||
name="test_tool",
|
||||
description="Test Tool",
|
||||
endpoint=sample_endpoint,
|
||||
endpoint=sample_endpiont,
|
||||
operation=sample_operation,
|
||||
auth_scheme=sample_auth_scheme,
|
||||
auth_credential=sample_auth_credential,
|
||||
)
|
||||
assert tool.name == "test_tool"
|
||||
assert tool.description == "Test Tool"
|
||||
assert tool.endpoint == sample_endpoint
|
||||
assert tool.endpoint == sample_endpiont
|
||||
assert tool.operation == sample_operation
|
||||
assert tool.auth_credential == sample_auth_credential
|
||||
assert tool.auth_scheme == sample_auth_scheme
|
||||
@ -154,7 +154,7 @@ class TestRestApiTool:
|
||||
|
||||
def test_from_parsed_operation_str(
|
||||
self,
|
||||
sample_endpoint,
|
||||
sample_endpiont,
|
||||
sample_api_parameters,
|
||||
sample_return_parameter,
|
||||
sample_operation,
|
||||
@ -162,7 +162,7 @@ class TestRestApiTool:
|
||||
parsed_operation_str = json.dumps({
|
||||
"name": "test_operation",
|
||||
"description": "Test Description",
|
||||
"endpoint": sample_endpoint.model_dump(),
|
||||
"endpoint": sample_endpiont.model_dump(),
|
||||
"operation": sample_operation.model_dump(),
|
||||
"auth_scheme": None,
|
||||
"auth_credential": None,
|
||||
@ -174,12 +174,12 @@ class TestRestApiTool:
|
||||
assert tool.name == "test_operation"
|
||||
|
||||
def test_get_declaration(
|
||||
self, sample_endpoint, sample_operation, mock_operation_parser
|
||||
self, sample_endpiont, sample_operation, mock_operation_parser
|
||||
):
|
||||
tool = RestApiTool(
|
||||
name="test_tool",
|
||||
description="Test description",
|
||||
endpoint=sample_endpoint,
|
||||
endpoint=sample_endpiont,
|
||||
operation=sample_operation,
|
||||
should_parse_operation=False,
|
||||
)
|
||||
@ -198,7 +198,7 @@ class TestRestApiTool:
|
||||
self,
|
||||
mock_request,
|
||||
mock_tool_context,
|
||||
sample_endpoint,
|
||||
sample_endpiont,
|
||||
sample_operation,
|
||||
sample_auth_scheme,
|
||||
sample_auth_credential,
|
||||
@ -210,7 +210,7 @@ class TestRestApiTool:
|
||||
tool = RestApiTool(
|
||||
name="test_tool",
|
||||
description="Test Tool",
|
||||
endpoint=sample_endpoint,
|
||||
endpoint=sample_endpiont,
|
||||
operation=sample_operation,
|
||||
auth_scheme=sample_auth_scheme,
|
||||
auth_credential=sample_auth_credential,
|
||||
@ -228,7 +228,7 @@ class TestRestApiTool:
|
||||
def test_call_auth_pending(
|
||||
self,
|
||||
mock_request,
|
||||
sample_endpoint,
|
||||
sample_endpiont,
|
||||
sample_operation,
|
||||
sample_auth_scheme,
|
||||
sample_auth_credential,
|
||||
@ -237,7 +237,7 @@ class TestRestApiTool:
|
||||
tool = RestApiTool(
|
||||
name="test_tool",
|
||||
description="Test Tool",
|
||||
endpoint=sample_endpoint,
|
||||
endpoint=sample_endpiont,
|
||||
operation=sample_operation,
|
||||
auth_scheme=sample_auth_scheme,
|
||||
auth_credential=sample_auth_credential,
|
||||
@ -258,7 +258,7 @@ class TestRestApiTool:
|
||||
}
|
||||
|
||||
def test_prepare_request_params_query_body(
|
||||
self, sample_endpoint, sample_auth_credential, sample_auth_scheme
|
||||
self, sample_endpiont, sample_auth_credential, sample_auth_scheme
|
||||
):
|
||||
# Create a mock Operation object
|
||||
mock_operation = Operation(
|
||||
@ -288,7 +288,7 @@ class TestRestApiTool:
|
||||
tool = RestApiTool(
|
||||
name="test_tool",
|
||||
description="test",
|
||||
endpoint=sample_endpoint,
|
||||
endpoint=sample_endpiont,
|
||||
operation=mock_operation,
|
||||
auth_credential=sample_auth_credential,
|
||||
auth_scheme=sample_auth_scheme,
|
||||
@ -327,7 +327,7 @@ class TestRestApiTool:
|
||||
assert request_params["params"] == {"testQueryParam": "query_value"}
|
||||
|
||||
def test_prepare_request_params_array(
|
||||
self, sample_endpoint, sample_auth_scheme, sample_auth_credential
|
||||
self, sample_endpiont, sample_auth_scheme, sample_auth_credential
|
||||
):
|
||||
mock_operation = Operation(
|
||||
operationId="test_op",
|
||||
@ -345,7 +345,7 @@ class TestRestApiTool:
|
||||
tool = RestApiTool(
|
||||
name="test_tool",
|
||||
description="test",
|
||||
endpoint=sample_endpoint,
|
||||
endpoint=sample_endpiont,
|
||||
operation=mock_operation,
|
||||
auth_credential=sample_auth_credential,
|
||||
auth_scheme=sample_auth_scheme,
|
||||
@ -367,7 +367,7 @@ class TestRestApiTool:
|
||||
assert request_params["json"] == ["item1", "item2"]
|
||||
|
||||
def test_prepare_request_params_string(
|
||||
self, sample_endpoint, sample_auth_credential, sample_auth_scheme
|
||||
self, sample_endpiont, sample_auth_credential, sample_auth_scheme
|
||||
):
|
||||
mock_operation = Operation(
|
||||
operationId="test_op",
|
||||
@ -380,7 +380,7 @@ class TestRestApiTool:
|
||||
tool = RestApiTool(
|
||||
name="test_tool",
|
||||
description="Test Tool",
|
||||
endpoint=sample_endpoint,
|
||||
endpoint=sample_endpiont,
|
||||
operation=mock_operation,
|
||||
auth_credential=sample_auth_credential,
|
||||
auth_scheme=sample_auth_scheme,
|
||||
@ -401,7 +401,7 @@ class TestRestApiTool:
|
||||
assert request_params["headers"]["Content-Type"] == "text/plain"
|
||||
|
||||
def test_prepare_request_params_form_data(
|
||||
self, sample_endpoint, sample_auth_scheme, sample_auth_credential
|
||||
self, sample_endpiont, sample_auth_scheme, sample_auth_credential
|
||||
):
|
||||
mock_operation = Operation(
|
||||
operationId="test_op",
|
||||
@ -419,7 +419,7 @@ class TestRestApiTool:
|
||||
tool = RestApiTool(
|
||||
name="test_tool",
|
||||
description="test",
|
||||
endpoint=sample_endpoint,
|
||||
endpoint=sample_endpiont,
|
||||
operation=mock_operation,
|
||||
auth_credential=sample_auth_credential,
|
||||
auth_scheme=sample_auth_scheme,
|
||||
@ -443,7 +443,7 @@ class TestRestApiTool:
|
||||
)
|
||||
|
||||
def test_prepare_request_params_multipart(
|
||||
self, sample_endpoint, sample_auth_credential, sample_auth_scheme
|
||||
self, sample_endpiont, sample_auth_credential, sample_auth_scheme
|
||||
):
|
||||
mock_operation = Operation(
|
||||
operationId="test_op",
|
||||
@ -465,7 +465,7 @@ class TestRestApiTool:
|
||||
tool = RestApiTool(
|
||||
name="test_tool",
|
||||
description="test",
|
||||
endpoint=sample_endpoint,
|
||||
endpoint=sample_endpiont,
|
||||
operation=mock_operation,
|
||||
auth_credential=sample_auth_credential,
|
||||
auth_scheme=sample_auth_scheme,
|
||||
@ -486,7 +486,7 @@ class TestRestApiTool:
|
||||
assert request_params["headers"]["Content-Type"] == "multipart/form-data"
|
||||
|
||||
def test_prepare_request_params_octet_stream(
|
||||
self, sample_endpoint, sample_auth_scheme, sample_auth_credential
|
||||
self, sample_endpiont, sample_auth_scheme, sample_auth_credential
|
||||
):
|
||||
mock_operation = Operation(
|
||||
operationId="test_op",
|
||||
@ -501,7 +501,7 @@ class TestRestApiTool:
|
||||
tool = RestApiTool(
|
||||
name="test_tool",
|
||||
description="test",
|
||||
endpoint=sample_endpoint,
|
||||
endpoint=sample_endpiont,
|
||||
operation=mock_operation,
|
||||
auth_credential=sample_auth_credential,
|
||||
auth_scheme=sample_auth_scheme,
|
||||
@ -524,13 +524,13 @@ class TestRestApiTool:
|
||||
)
|
||||
|
||||
def test_prepare_request_params_path_param(
|
||||
self, sample_endpoint, sample_auth_credential, sample_auth_scheme
|
||||
self, sample_endpiont, sample_auth_credential, sample_auth_scheme
|
||||
):
|
||||
mock_operation = Operation(operationId="test_op")
|
||||
tool = RestApiTool(
|
||||
name="test_tool",
|
||||
description="Test Tool",
|
||||
endpoint=sample_endpoint,
|
||||
endpoint=sample_endpiont,
|
||||
operation=mock_operation,
|
||||
auth_credential=sample_auth_credential,
|
||||
auth_scheme=sample_auth_scheme,
|
||||
@ -557,7 +557,7 @@ class TestRestApiTool:
|
||||
|
||||
def test_prepare_request_params_header_param(
|
||||
self,
|
||||
sample_endpoint,
|
||||
sample_endpiont,
|
||||
sample_auth_credential,
|
||||
sample_auth_scheme,
|
||||
sample_operation,
|
||||
@ -565,7 +565,7 @@ class TestRestApiTool:
|
||||
tool = RestApiTool(
|
||||
name="test_tool",
|
||||
description="Test Tool",
|
||||
endpoint=sample_endpoint,
|
||||
endpoint=sample_endpiont,
|
||||
operation=sample_operation,
|
||||
auth_credential=sample_auth_credential,
|
||||
auth_scheme=sample_auth_scheme,
|
||||
@ -586,7 +586,7 @@ class TestRestApiTool:
|
||||
|
||||
def test_prepare_request_params_cookie_param(
|
||||
self,
|
||||
sample_endpoint,
|
||||
sample_endpiont,
|
||||
sample_auth_credential,
|
||||
sample_auth_scheme,
|
||||
sample_operation,
|
||||
@ -594,7 +594,7 @@ class TestRestApiTool:
|
||||
tool = RestApiTool(
|
||||
name="test_tool",
|
||||
description="Test Tool",
|
||||
endpoint=sample_endpoint,
|
||||
endpoint=sample_endpiont,
|
||||
operation=sample_operation,
|
||||
auth_credential=sample_auth_credential,
|
||||
auth_scheme=sample_auth_scheme,
|
||||
@ -614,7 +614,7 @@ class TestRestApiTool:
|
||||
assert request_params["cookies"]["session_id"] == "cookie_value"
|
||||
|
||||
def test_prepare_request_params_multiple_mime_types(
|
||||
self, sample_endpoint, sample_auth_credential, sample_auth_scheme
|
||||
self, sample_endpiont, sample_auth_credential, sample_auth_scheme
|
||||
):
|
||||
# Test what happens when multiple mime types are specified. It should take
|
||||
# the first one.
|
||||
@ -632,7 +632,7 @@ class TestRestApiTool:
|
||||
tool = RestApiTool(
|
||||
name="test_tool",
|
||||
description="Test Tool",
|
||||
endpoint=sample_endpoint,
|
||||
endpoint=sample_endpiont,
|
||||
operation=mock_operation,
|
||||
auth_credential=sample_auth_credential,
|
||||
auth_scheme=sample_auth_scheme,
|
||||
@ -653,7 +653,7 @@ class TestRestApiTool:
|
||||
|
||||
def test_prepare_request_params_unknown_parameter(
|
||||
self,
|
||||
sample_endpoint,
|
||||
sample_endpiont,
|
||||
sample_auth_credential,
|
||||
sample_auth_scheme,
|
||||
sample_operation,
|
||||
@ -661,7 +661,7 @@ class TestRestApiTool:
|
||||
tool = RestApiTool(
|
||||
name="test_tool",
|
||||
description="Test Tool",
|
||||
endpoint=sample_endpoint,
|
||||
endpoint=sample_endpiont,
|
||||
operation=sample_operation,
|
||||
auth_credential=sample_auth_credential,
|
||||
auth_scheme=sample_auth_scheme,
|
||||
@ -719,7 +719,7 @@ class TestRestApiTool:
|
||||
|
||||
def test_prepare_request_params_no_unrecognized_query_parameter(
|
||||
self,
|
||||
sample_endpoint,
|
||||
sample_endpiont,
|
||||
sample_auth_credential,
|
||||
sample_auth_scheme,
|
||||
sample_operation,
|
||||
@ -727,7 +727,7 @@ class TestRestApiTool:
|
||||
tool = RestApiTool(
|
||||
name="test_tool",
|
||||
description="Test Tool",
|
||||
endpoint=sample_endpoint,
|
||||
endpoint=sample_endpiont,
|
||||
operation=sample_operation,
|
||||
auth_credential=sample_auth_credential,
|
||||
auth_scheme=sample_auth_scheme,
|
||||
@ -748,13 +748,13 @@ class TestRestApiTool:
|
||||
|
||||
def test_prepare_request_params_no_credential(
|
||||
self,
|
||||
sample_endpoint,
|
||||
sample_endpiont,
|
||||
sample_operation,
|
||||
):
|
||||
tool = RestApiTool(
|
||||
name="test_tool",
|
||||
description="Test Tool",
|
||||
endpoint=sample_endpoint,
|
||||
endpoint=sample_endpiont,
|
||||
operation=sample_operation,
|
||||
auth_credential=None,
|
||||
auth_scheme=None,
|
||||
|
Loading…
Reference in New Issue
Block a user