Compare commits

...

4 Commits

Author SHA1 Message Date
Erick Friis 3cb32e4618 Merge branch 'main' into erick/assign-input-params 2023-10-19 10:22:42 -07:00
Erick Friis 3534bfccbd nopath test 2023-10-18 19:14:07 -07:00
Erick Friis 0ec68c61f3 assign test 2023-10-18 19:12:07 -07:00
Erick Friis f0a1831956 Runnable Assign Test 2023-10-18 17:46:28 -07:00
+28 -1
View File
@@ -16,7 +16,7 @@ from langchain.prompts import PromptTemplate
from langchain.prompts.base import StringPromptValue
from langchain.schema.messages import HumanMessage, SystemMessage
from langchain.schema.runnable import RunnableConfig, RunnablePassthrough
from langchain.schema.runnable.base import RunnableLambda
from langchain.schema.runnable.base import RunnableLambda, Runnable
from langchain.schema.runnable.utils import ConfigurableField
from pytest_mock import MockerFixture
from typing_extensions import TypedDict
@@ -750,6 +750,33 @@ def test_rename_pydantic_model() -> None:
@pytest.mark.asyncio
async def test_runnable_assign(event_loop: AbstractEventLoop) -> None:
"""Test serving multiple runnables."""
app = FastAPI()
chain = RunnablePassthrough().assign(a=RunnableLambda(lambda _: "a"))
# should only need "b" as input now
add_routes(app, chain, path="/assigned")
async with get_async_client(app, path="/assigned") as runnable:
assert await runnable.ainvoke({"b": "b"}) == {"a": "a", "b": "b"}
assert runnable.invoke({"b": "b"}) == {"a": "a", "b": "b"}
@pytest.mark.asyncio
async def test_runnable_assign_nopath(event_loop: AbstractEventLoop) -> None:
"""Test serving multiple runnables."""
app = FastAPI()
chain = RunnablePassthrough().assign(a=RunnableLambda(lambda _: "a"))
# should only need "b" as input now
add_routes(app, chain)
async with get_async_client(app, path="/") as runnable:
assert await runnable.ainvoke({"b": "b"}) == {"a": "a", "b": "b"}
assert runnable.invoke({"b": "b"}) == {"a": "a", "b": "b"}
async def test_input_schema_typed_dict() -> None:
class InputType(TypedDict):
foo: str