Skip to content
Snippets Groups Projects
Unverified Commit d582bc70 authored by James Briggs's avatar James Briggs
Browse files

tweaks

parent 73e1996f
No related branches found
No related tags found
No related merge requests found
......@@ -104,4 +104,4 @@ In this case, no decision could be made as we had no matches — so our decision
| | |
| --- | --- |
| 🏃 Walkthrough | Quickstart Python notebook |
\ No newline at end of file
| 🏃 [Walkthrough](https://colab.research.google.com/github/aurelio-labs/semantic-router/blob/main/walkthrough.ipynb) | Quickstart Python notebook |
\ No newline at end of file
%% Cell type:markdown id: tags:
# Semantic Router Walkthrough
%% Cell type:markdown id: tags:
The Semantic Router library can be used as a super fast decision making layer on top of LLMs. That means rather than waiting on a slow agent to decide what to do, we can use the magic of semantic vector space to make decisions. Cutting decision making time down from seconds to milliseconds.
%% Cell type:markdown id: tags:
## Getting Started
%% Cell type:markdown id: tags:
We start by installing the library:
%% Cell type:code id: tags:
``` python
!pip install -qU semantic-router==0.0.1
```
%% Cell type:markdown id: tags:
We start by defining a dictionary mapping decisions to example phrases that should trigger those decisions.
%% Cell type:code id: tags:
``` python
from semantic_router.schema import Decision
politics = Decision(
name="politics",
utterances=[
"isn't politics the best thing ever",
"why don't you tell me about your political opinions",
"don't you just love the president"
"don't you just hate the president",
"they're going to destroy this country!",
"they will save the country!"
]
)
```
%% Cell type:markdown id: tags:
Let's define another for good measure:
%% Cell type:code id: tags:
``` python
chitchat = Decision(
name="chitchat",
utterances=[
"how's the weather today?",
"how are things going?",
"lovely weather today",
"the weather is horrendous",
"let's go to the chippy"
]
)
decisions = [politics, chitchat]
```
%% Cell type:markdown id: tags:
Now we initialize our embedding model:
%% Cell type:code id: tags:
``` python
from semantic_router.encoders import CohereEncoder
from getpass import getpass
import os
# os.environ["COHERE_API_KEY"] = getpass("Enter Cohere API Key: ")
os.environ["COHERE_API_KEY"]
os.environ["COHERE_API_KEY"] = os.environ["COHERE_API_KEY"] or \
getpass("Enter Cohere API Key: ")
encoder = CohereEncoder()
```
%% Cell type:markdown id: tags:
Now we define the `DecisionLayer`. When called, the decision layer will consume text (a query) and output the category (`Decision`) it belongs to — to initialize a `DecisionLayer` we need our `encoder` model and a list of `decisions`.
%% Cell type:code id: tags:
``` python
from semantic_router import DecisionLayer
dl = DecisionLayer(encoder=encoder, decisions=decisions)
```
%% Cell type:markdown id: tags:
Now we can test it:
%% Cell type:code id: tags:
``` python
dl("don't you love politics?")
```
%% Cell type:code id: tags:
``` python
dl("how's the weather today?")
```
%% Cell type:markdown id: tags:
Both are classified accurately, what if we send a query that is unrelated to our existing `Decision` objects?
%% Cell type:code id: tags:
``` python
dl("I'm interested in learning about llama 2")
```
%% Cell type:markdown id: tags:
In this case, we return `None` because no matches were identified.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment