Include keyword-only prediction inputs in validation and schemas
This commit is contained in:
parent
c7ded92201
commit
42940fd84c
2 changed files with 20 additions and 1 deletions
|
|
@ -12,7 +12,7 @@ def automatically_decorate_parameters(func: F) -> F:
|
|||
parameter_names = [
|
||||
param.name
|
||||
for param in signature.parameters.values()
|
||||
if param.kind == param.POSITIONAL_OR_KEYWORD
|
||||
if param.kind in (param.POSITIONAL_OR_KEYWORD, param.KEYWORD_ONLY)
|
||||
]
|
||||
|
||||
metadata = get_function_metadata_store(func)
|
||||
|
|
|
|||
19
tests/test_argument_regressions.py
Normal file
19
tests/test_argument_regressions.py
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from great_ai import GreatAI
|
||||
|
||||
|
||||
def test_keyword_only_inputs_are_validated_and_exposed(isolated_context: None) -> None:
|
||||
@GreatAI.create
|
||||
def predict(*, value: int) -> int:
|
||||
return value
|
||||
|
||||
trace = predict(value=7)
|
||||
assert trace.output == 7
|
||||
assert trace.logged_values["arg:value:value"] == 7
|
||||
with pytest.raises(TypeError):
|
||||
predict(value="wrong")
|
||||
with TestClient(predict.app) as client:
|
||||
assert client.post("/predict", json={"value": 8}).json()["output"] == 8
|
||||
assert client.post("/predict", json={"value": "wrong"}).status_code == 422
|
||||
Loading…
Reference in a new issue