mirror of
https://github.com/hwchase17/langchain.git
synced 2026-03-18 11:07:36 +00:00
description by @mdrxy - Enable `test_responses_spec.py` integration tests that were previously skipped at module level - Widen `ToolStrategy.schema` type annotation from `type[SchemaT]` to `type[SchemaT] | dict[str, Any]` to match actual supported usage (JSON schema dicts were already handled at runtime) - Fix type annotations and linting issues in test file (modernize to `dict`/`list`, add return types, prefix unused `_request` param) - Improve generic typing in `load_spec` utility with bounded `TypeVar` Co-authored-by: Mason Daugherty <mason@langchain.dev>
26 lines
622 B
Python
26 lines
622 B
Python
import json
|
|
from pathlib import Path
|
|
from typing import TypeVar
|
|
|
|
from pydantic import BaseModel, ConfigDict
|
|
from pydantic.alias_generators import to_camel
|
|
|
|
|
|
class BaseSchema(BaseModel):
|
|
model_config = ConfigDict(
|
|
alias_generator=to_camel,
|
|
populate_by_name=True,
|
|
from_attributes=True,
|
|
)
|
|
|
|
|
|
_T = TypeVar("_T", bound=BaseModel)
|
|
|
|
|
|
def load_spec(spec_name: str, as_model: type[_T]) -> list[_T]:
|
|
with (Path(__file__).parent / "specifications" / f"{spec_name}.json").open(
|
|
"r", encoding="utf-8"
|
|
) as f:
|
|
data = json.load(f)
|
|
return [as_model(**item) for item in data]
|