Skip to content

Commit

Permalink
Merge pull request #818 from PrefectHQ/call-routing
Browse files Browse the repository at this point in the history
Add call routing example
  • Loading branch information
zzstoatzz authored Jan 30, 2024
2 parents 1ce41f6 + 3356ecf commit d5fafdc
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
42 changes: 42 additions & 0 deletions docs/examples/call_routing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Customer call routing

Automatically route customer calls to the right department.

!!! example "Call routing"
```python
import marvin
from enum import Enum


class Department(Enum):
SALES = "sales"
SUPPORT = "support"
BILLING = "billing"


# define a convenience function
def route_call(transcript: str) -> Department:
return marvin.classify(
transcript,
labels=Department,
instructions="Select the best department for the customer request",
)
```

!!! success "💳 Update payment method"
```python
department = route_call("I need to update my payment method")
assert department == Department.BILLING
```

!!! success "💵 Price matching"
```python
department = route_call("Well FooCo offered me a better deal")
assert department == Department.SALES
```

!!! success "🤬 Angry noises"
```python
department = route_call("*angry noises*")
assert department == Department.SUPPORT
```
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ nav:
- examples/xkcd_bird.md
- examples/michael_scott_business/michael_scott_business.md
- examples/hogwarts_sorting_hat/hogwarts_sorting_hat.md
- examples/call_routing.md


- Community:
Expand Down
24 changes: 24 additions & 0 deletions tests/ai/test_classify.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Literal

import marvin
import pytest

Sentiment = Literal["Positive", "Negative"]

Expand Down Expand Up @@ -82,3 +83,26 @@ async def test_hogwarts_sorting_hat(self):
)

assert house == "Gryffindor"

@pytest.mark.parametrize(
"user_input, expected_selection",
[
("I need to update my payment method", "billing"),
("Well FooCo offered me a better deal", "sales"),
("*angry noises*", "support"),
],
)
async def test_call_routing(self, user_input, expected_selection):
class Department(Enum):
SALES = "sales"
SUPPORT = "support"
BILLING = "billing"

def router(transcript: str) -> Department:
return marvin.classify(
transcript,
labels=Department,
instructions="Select the best department for the customer request",
)

assert router(user_input).value == expected_selection

0 comments on commit d5fafdc

Please sign in to comment.