Skip to content

Commit

Permalink
x
Browse files Browse the repository at this point in the history
  • Loading branch information
eyurtsev committed Nov 13, 2023
1 parent 9283e6a commit b49b326
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
24 changes: 13 additions & 11 deletions langserve/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def _config_from_hash(config_hash: str) -> Dict[str, Any]:

def _unpack_request_config(
*configs: Union[BaseModel, Mapping, str],
keys: Sequence[str],
config_keys: Sequence[str],
model: Type[BaseModel],
request: Request,
per_req_config_modifier: Optional[PerRequestConfigModifier],
Expand All @@ -115,12 +115,14 @@ def _unpack_request_config(
raise TypeError(f"Expected a string, dict or BaseModel got {type(config)}")
config = merge_configs(*config_dicts)
if "configurable" in config and config["configurable"]:
if "configurable" not in keys:
if "configurable" not in config_keys:
raise HTTPException(
422,
"The config field `configurable` has been disallowed by the server.",
"The config field `configurable` has been disallowed by the server. "
"This can be modified server side by adding `configurable` to the list "
"of `config_keys` argument in `add_routes`",
)
projected_config = {k: config[k] for k in keys if k in config}
projected_config = {k: config[k] for k in config_keys if k in config}
return (
per_req_config_modifier(projected_config, request)
if per_req_config_modifier
Expand Down Expand Up @@ -576,7 +578,7 @@ async def _get_config_and_input(
config = _unpack_request_config(
config_hash,
body.config,
keys=config_keys,
config_keys=config_keys,
model=ConfigPayload,
request=request,
per_req_config_modifier=per_req_config_modifier,
Expand Down Expand Up @@ -661,7 +663,7 @@ async def batch(
_unpack_request_config(
config_hash,
config,
keys=config_keys,
config_keys=config_keys,
model=ConfigPayload,
request=request,
per_req_config_modifier=per_req_config_modifier,
Expand All @@ -672,7 +674,7 @@ async def batch(
configs = _unpack_request_config(
config_hash,
config,
keys=config_keys,
config_keys=config_keys,
model=ConfigPayload,
request=request,
per_req_config_modifier=per_req_config_modifier,
Expand Down Expand Up @@ -942,7 +944,7 @@ async def input_schema(request: Request, config_hash: str = "") -> Any:
with _with_validation_error_translation():
config = _unpack_request_config(
config_hash,
keys=config_keys,
config_keys=config_keys,
model=ConfigPayload,
request=request,
per_req_config_modifier=per_req_config_modifier,
Expand All @@ -965,7 +967,7 @@ async def output_schema(request: Request, config_hash: str = "") -> Any:
with _with_validation_error_translation():
config = _unpack_request_config(
config_hash,
keys=config_keys,
config_keys=config_keys,
model=ConfigPayload,
request=request,
per_req_config_modifier=per_req_config_modifier,
Expand All @@ -985,7 +987,7 @@ async def config_schema(request: Request, config_hash: str = "") -> Any:
with _with_validation_error_translation():
config = _unpack_request_config(
config_hash,
keys=config_keys,
config_keys=config_keys,
model=ConfigPayload,
request=request,
per_req_config_modifier=per_req_config_modifier,
Expand All @@ -1004,7 +1006,7 @@ async def playground(
with _with_validation_error_translation():
config = _unpack_request_config(
config_hash,
keys=config_keys,
config_keys=config_keys,
model=ConfigPayload,
request=request,
per_req_config_modifier=per_req_config_modifier,
Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def test_invoke_request_with_runnables() -> None:
Model(
input={"name": "bob"},
).config,
keys=[],
config_keys=[],
model=config,
request=MagicMock(Request),
per_req_config_modifier=lambda x, y: x,
Expand All @@ -184,7 +184,7 @@ def test_invoke_request_with_runnables() -> None:

assert _unpack_request_config(
request.config,
keys=["configurable"],
config_keys=["configurable"],
model=config,
request=MagicMock(Request),
per_req_config_modifier=lambda x, y: x,
Expand Down

0 comments on commit b49b326

Please sign in to comment.