Skip to content

Commit ffb2847

Browse files
committed
Use builtins.dict instead of typing.Dict
1 parent 50e2b20 commit ffb2847

File tree

2 files changed

+22
-24
lines changed

2 files changed

+22
-24
lines changed

libs/core/langchain_core/language_models/chat_models.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
from __future__ import annotations
44

55
import asyncio
6+
import builtins
67
import inspect
78
import json
8-
import typing
99
import warnings
1010
from abc import ABC, abstractmethod
1111
from collections.abc import AsyncIterator, Iterator, Sequence
@@ -366,7 +366,7 @@ class BaseChatModel(BaseLanguageModel[AIMessage], ABC):
366366

367367
@model_validator(mode="before")
368368
@classmethod
369-
def raise_deprecation(cls, values: typing.Dict) -> Any: # noqa: UP006
369+
def raise_deprecation(cls, values: builtins.dict) -> Any:
370370
"""Raise deprecation warning if ``callback_manager`` is used.
371371
372372
Args:
@@ -393,7 +393,7 @@ def raise_deprecation(cls, values: typing.Dict) -> Any: # noqa: UP006
393393
)
394394

395395
@cached_property
396-
def _serialized(self) -> typing.Dict[str, Any]: # noqa: UP006
396+
def _serialized(self) -> builtins.dict[str, Any]:
397397
return dumpd(self)
398398

399399
# --- Runnable methods ---
@@ -743,8 +743,8 @@ async def astream(
743743

744744
def _combine_llm_outputs(
745745
self,
746-
llm_outputs: list[Optional[typing.Dict]], # noqa: ARG002, UP006
747-
) -> typing.Dict: # noqa: UP006
746+
llm_outputs: list[Optional[builtins.dict]], # noqa: ARG002
747+
) -> builtins.dict:
748748
return {}
749749

750750
def _convert_cached_generations(self, cache_val: list) -> list[ChatGeneration]:
@@ -790,7 +790,7 @@ def _get_invocation_params(
790790
self,
791791
stop: Optional[list[str]] = None,
792792
**kwargs: Any,
793-
) -> typing.Dict: # noqa: UP006
793+
) -> builtins.dict:
794794
params = self.asdict()
795795
params["stop"] = stop
796796
return {**params, **kwargs}
@@ -854,7 +854,7 @@ def generate(
854854
callbacks: Callbacks = None,
855855
*,
856856
tags: Optional[list[str]] = None,
857-
metadata: Optional[typing.Dict[str, Any]] = None, # noqa: UP006
857+
metadata: Optional[builtins.dict[str, Any]] = None,
858858
run_name: Optional[str] = None,
859859
run_id: Optional[uuid.UUID] = None,
860860
**kwargs: Any,
@@ -969,7 +969,7 @@ async def agenerate(
969969
callbacks: Callbacks = None,
970970
*,
971971
tags: Optional[list[str]] = None,
972-
metadata: Optional[typing.Dict[str, Any]] = None, # noqa: UP006
972+
metadata: Optional[builtins.dict[str, Any]] = None,
973973
run_name: Optional[str] = None,
974974
run_id: Optional[uuid.UUID] = None,
975975
**kwargs: Any,
@@ -1542,20 +1542,18 @@ def _llm_type(self) -> str:
15421542

15431543
@deprecated("0.3.61", alternative="asdict", removal="1.0")
15441544
@override
1545-
def dict(self, **kwargs: Any) -> typing.Dict[str, Any]: # noqa: UP006
1545+
def dict(self, **kwargs: Any) -> builtins.dict[str, Any]:
15461546
return self.asdict()
15471547

1548-
def asdict(self) -> typing.Dict[str, Any]: # noqa: UP006
1548+
def asdict(self) -> builtins.dict[str, Any]:
15491549
"""Return a dictionary of the LLM."""
15501550
starter_dict = dict(self._identifying_params)
15511551
starter_dict["_type"] = self._llm_type
15521552
return starter_dict
15531553

15541554
def bind_tools(
15551555
self,
1556-
tools: Sequence[
1557-
Union[typing.Dict[str, Any], type, Callable, BaseTool] # noqa: UP006
1558-
],
1556+
tools: Sequence[Union[builtins.dict[str, Any], type, Callable, BaseTool]],
15591557
*,
15601558
tool_choice: Optional[Union[str]] = None,
15611559
**kwargs: Any,
@@ -1574,11 +1572,11 @@ def bind_tools(
15741572

15751573
def with_structured_output(
15761574
self,
1577-
schema: Union[typing.Dict, type], # noqa: UP006
1575+
schema: Union[builtins.dict, type],
15781576
*,
15791577
include_raw: bool = False,
15801578
**kwargs: Any,
1581-
) -> Runnable[LanguageModelInput, Union[typing.Dict, BaseModel]]: # noqa: UP006
1579+
) -> Runnable[LanguageModelInput, Union[builtins.dict, BaseModel]]:
15821580
"""Model wrapper that returns outputs formatted to match the given schema.
15831581
15841582
Args:

libs/core/langchain_core/language_models/llms.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
from __future__ import annotations
44

55
import asyncio
6+
import builtins
67
import functools
78
import inspect
89
import json
910
import logging
10-
import typing
1111
import warnings
1212
from abc import ABC, abstractmethod
1313
from collections.abc import AsyncIterator, Iterator, Sequence
@@ -305,7 +305,7 @@ class BaseLLM(BaseLanguageModel[str], ABC):
305305

306306
@model_validator(mode="before")
307307
@classmethod
308-
def raise_deprecation(cls, values: typing.Dict[str, Any]) -> Any: # noqa: UP006
308+
def raise_deprecation(cls, values: builtins.dict[str, Any]) -> Any:
309309
"""Raise deprecation warning if callback_manager is used."""
310310
if values.get("callback_manager") is not None:
311311
warnings.warn(
@@ -317,7 +317,7 @@ def raise_deprecation(cls, values: typing.Dict[str, Any]) -> Any: # noqa: UP006
317317
return values
318318

319319
@functools.cached_property
320-
def _serialized(self) -> typing.Dict[str, Any]: # noqa: UP006
320+
def _serialized(self) -> builtins.dict[str, Any]:
321321
return dumpd(self)
322322

323323
# --- Runnable methods ---
@@ -821,7 +821,7 @@ def generate(
821821
*,
822822
tags: Optional[Union[list[str], list[list[str]]]] = None,
823823
metadata: Optional[
824-
Union[typing.Dict[str, Any], list[typing.Dict[str, Any]]] # noqa: UP006
824+
Union[builtins.dict[str, Any], list[builtins.dict[str, Any]]]
825825
] = None,
826826
run_name: Optional[Union[str, list[str]]] = None,
827827
run_id: Optional[Union[uuid.UUID, list[Optional[uuid.UUID]]]] = None,
@@ -1083,7 +1083,7 @@ async def agenerate(
10831083
*,
10841084
tags: Optional[Union[list[str], list[list[str]]]] = None,
10851085
metadata: Optional[
1086-
Union[typing.Dict[str, Any], list[typing.Dict[str, Any]]] # noqa: UP006
1086+
Union[builtins.dict[str, Any], list[builtins.dict[str, Any]]]
10871087
] = None,
10881088
run_name: Optional[Union[str, list[str]]] = None,
10891089
run_id: Optional[Union[uuid.UUID, list[Optional[uuid.UUID]]]] = None,
@@ -1285,7 +1285,7 @@ def __call__(
12851285
callbacks: Callbacks = None,
12861286
*,
12871287
tags: Optional[list[str]] = None,
1288-
metadata: Optional[typing.Dict[str, Any]] = None, # noqa: UP006
1288+
metadata: Optional[builtins.dict[str, Any]] = None,
12891289
**kwargs: Any,
12901290
) -> str:
12911291
"""Check Cache and run the LLM on the given prompt and input.
@@ -1334,7 +1334,7 @@ async def _call_async(
13341334
callbacks: Callbacks = None,
13351335
*,
13361336
tags: Optional[list[str]] = None,
1337-
metadata: Optional[typing.Dict[str, Any]] = None, # noqa: UP006
1337+
metadata: Optional[builtins.dict[str, Any]] = None,
13381338
**kwargs: Any,
13391339
) -> str:
13401340
"""Check Cache and run the LLM on the given prompt and input."""
@@ -1404,10 +1404,10 @@ def _llm_type(self) -> str:
14041404

14051405
@deprecated("0.3.61", alternative="asdict", removal="1.0")
14061406
@override
1407-
def dict(self, **kwargs: Any) -> typing.Dict[str, Any]: # noqa: UP006
1407+
def dict(self, **kwargs: Any) -> builtins.dict[str, Any]:
14081408
return self.asdict()
14091409

1410-
def asdict(self) -> typing.Dict[str, Any]: # noqa: UP006
1410+
def asdict(self) -> builtins.dict[str, Any]:
14111411
"""Return a dictionary of the LLM."""
14121412
starter_dict = dict(self._identifying_params)
14131413
starter_dict["_type"] = self._llm_type

0 commit comments

Comments
 (0)