mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-20 03:21:33 +00:00
Automatically add configurable key to config_schema if config_specs i… (#12798)
…s present <!-- Thank you for contributing to LangChain! Replace this entire comment with: - **Description:** a description of the change, - **Issue:** the issue # it fixes (if applicable), - **Dependencies:** any dependencies required for this change, - **Tag maintainer:** for a quicker response, tag the relevant maintainer (see below), - **Twitter handle:** we announce bigger features on Twitter. If your PR gets announced, and you'd like a mention, we'll gladly shout you out! Please make sure your PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` to check this locally. See contribution guidelines for more information on how to write/run tests, lint, etc: https://github.com/langchain-ai/langchain/blob/master/.github/CONTRIBUTING.md If you're adding a new integration, please include: 1. a test for the integration, preferably unit tests that do not rely on network access, 2. an example notebook showing its use. It lives in `docs/extras` directory. If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17. -->
This commit is contained in:
parent
21eeba075c
commit
f66a9d2adf
@ -202,7 +202,9 @@ class Runnable(Generic[Input, Output], ABC):
|
|||||||
"""List configurable fields for this runnable."""
|
"""List configurable fields for this runnable."""
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def config_schema(self, *, include: Sequence[str]) -> Type[BaseModel]:
|
def config_schema(
|
||||||
|
self, *, include: Optional[Sequence[str]] = None
|
||||||
|
) -> Type[BaseModel]:
|
||||||
"""The type of config this runnable accepts specified as a pydantic model.
|
"""The type of config this runnable accepts specified as a pydantic model.
|
||||||
|
|
||||||
To mark a field as configurable, see the `configurable_fields`
|
To mark a field as configurable, see the `configurable_fields`
|
||||||
@ -233,7 +235,7 @@ class Runnable(Generic[Input, Output], ABC):
|
|||||||
for spec in config_specs
|
for spec in config_specs
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
if config_specs and "configurable" in include
|
if config_specs
|
||||||
else None
|
else None
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -2354,7 +2356,9 @@ class RunnableEach(RunnableSerializable[List[Input], List[Output]]):
|
|||||||
def config_specs(self) -> Sequence[ConfigurableFieldSpec]:
|
def config_specs(self) -> Sequence[ConfigurableFieldSpec]:
|
||||||
return self.bound.config_specs
|
return self.bound.config_specs
|
||||||
|
|
||||||
def config_schema(self, *, include: Sequence[str]) -> Type[BaseModel]:
|
def config_schema(
|
||||||
|
self, *, include: Optional[Sequence[str]] = None
|
||||||
|
) -> Type[BaseModel]:
|
||||||
return self.bound.config_schema(include=include)
|
return self.bound.config_schema(include=include)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -2516,7 +2520,9 @@ class RunnableBinding(RunnableSerializable[Input, Output]):
|
|||||||
def config_specs(self) -> Sequence[ConfigurableFieldSpec]:
|
def config_specs(self) -> Sequence[ConfigurableFieldSpec]:
|
||||||
return self.bound.config_specs
|
return self.bound.config_specs
|
||||||
|
|
||||||
def config_schema(self, *, include: Sequence[str]) -> Type[BaseModel]:
|
def config_schema(
|
||||||
|
self, *, include: Optional[Sequence[str]] = None
|
||||||
|
) -> Type[BaseModel]:
|
||||||
return self.bound.config_schema(include=include)
|
return self.bound.config_schema(include=include)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -71,7 +71,9 @@ class RunnableWithFallbacks(RunnableSerializable[Input, Output]):
|
|||||||
for spec in step.config_specs
|
for spec in step.config_specs
|
||||||
)
|
)
|
||||||
|
|
||||||
def config_schema(self, *, include: Sequence[str]) -> Type[BaseModel]:
|
def config_schema(
|
||||||
|
self, *, include: Optional[Sequence[str]] = None
|
||||||
|
) -> Type[BaseModel]:
|
||||||
return self.runnable.config_schema(include=include)
|
return self.runnable.config_schema(include=include)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -869,7 +869,7 @@ def test_configurable_fields() -> None:
|
|||||||
|
|
||||||
assert fake_llm_configurable.invoke("...") == "a"
|
assert fake_llm_configurable.invoke("...") == "a"
|
||||||
|
|
||||||
assert fake_llm_configurable.config_schema(include=["configurable"]).schema() == {
|
assert fake_llm_configurable.config_schema().schema() == {
|
||||||
"title": "RunnableConfigurableFieldsConfig",
|
"title": "RunnableConfigurableFieldsConfig",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {"configurable": {"$ref": "#/definitions/Configurable"}},
|
"properties": {"configurable": {"$ref": "#/definitions/Configurable"}},
|
||||||
@ -912,7 +912,7 @@ def test_configurable_fields() -> None:
|
|||||||
text="Hello, John!"
|
text="Hello, John!"
|
||||||
)
|
)
|
||||||
|
|
||||||
assert prompt_configurable.config_schema(include=["configurable"]).schema() == {
|
assert prompt_configurable.config_schema().schema() == {
|
||||||
"title": "RunnableConfigurableFieldsConfig",
|
"title": "RunnableConfigurableFieldsConfig",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {"configurable": {"$ref": "#/definitions/Configurable"}},
|
"properties": {"configurable": {"$ref": "#/definitions/Configurable"}},
|
||||||
@ -955,7 +955,7 @@ def test_configurable_fields() -> None:
|
|||||||
|
|
||||||
assert chain_configurable.invoke({"name": "John"}) == "a"
|
assert chain_configurable.invoke({"name": "John"}) == "a"
|
||||||
|
|
||||||
assert chain_configurable.config_schema(include=["configurable"]).schema() == {
|
assert chain_configurable.config_schema().schema() == {
|
||||||
"title": "RunnableSequenceConfig",
|
"title": "RunnableSequenceConfig",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {"configurable": {"$ref": "#/definitions/Configurable"}},
|
"properties": {"configurable": {"$ref": "#/definitions/Configurable"}},
|
||||||
@ -1021,9 +1021,7 @@ def test_configurable_fields() -> None:
|
|||||||
"llm3": "a",
|
"llm3": "a",
|
||||||
}
|
}
|
||||||
|
|
||||||
assert chain_with_map_configurable.config_schema(
|
assert chain_with_map_configurable.config_schema().schema() == {
|
||||||
include=["configurable"]
|
|
||||||
).schema() == {
|
|
||||||
"title": "RunnableSequenceConfig",
|
"title": "RunnableSequenceConfig",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {"configurable": {"$ref": "#/definitions/Configurable"}},
|
"properties": {"configurable": {"$ref": "#/definitions/Configurable"}},
|
||||||
@ -1122,7 +1120,7 @@ def test_configurable_fields_example() -> None:
|
|||||||
|
|
||||||
assert chain_configurable.invoke({"name": "John"}) == "a"
|
assert chain_configurable.invoke({"name": "John"}) == "a"
|
||||||
|
|
||||||
assert chain_configurable.config_schema(include=["configurable"]).schema() == {
|
assert chain_configurable.config_schema().schema() == {
|
||||||
"title": "RunnableSequenceConfig",
|
"title": "RunnableSequenceConfig",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {"configurable": {"$ref": "#/definitions/Configurable"}},
|
"properties": {"configurable": {"$ref": "#/definitions/Configurable"}},
|
||||||
|
Loading…
Reference in New Issue
Block a user