Skip to content

Commit

Permalink
🧪 router tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shroominic committed Dec 20, 2023
1 parent 002c3fe commit f0812f3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/funcchain/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ class Route(TypedDict):
class ChatRouter(BaseModel):
routes: Routes

class Config:
arbitrary_types_allowed = True

@field_validator("routes")
def validate_routes(cls, v: Routes) -> Routes:
if "default" not in v.keys():
Expand Down
40 changes: 40 additions & 0 deletions tests/router_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from funcchain.components import ChatRouter


def handle_pdf_requests(user_query: str) -> str:
return f"Handling PDF requests with user query: {user_query}"


def handle_csv_requests(user_query: str) -> str:
return f"Handling CSV requests with user query: {user_query}"


def handle_default_requests(user_query: str) -> str:
return f"Handling DEFAULT requests with user query: {user_query}"


router = ChatRouter(
routes={
"pdf": {
"handler": handle_pdf_requests,
"description": "Call this for requests including PDF Files.",
},
"csv": {
"handler": handle_csv_requests,
"description": "Call this for requests including CSV Files.",
},
"default": handle_default_requests,
},
)


def test_router() -> None:
assert "Handling CSV" in router.invoke_route("Can you summarize this csv?")

assert "Handling PDF" in router.invoke_route("Can you summarize this pdf?")

assert "Handling DEFAULT" in router.invoke_route("Hey, whatsup?")


if __name__ == "__main__":
test_router()

0 comments on commit f0812f3

Please sign in to comment.