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

tweak

parent 4d537b87
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id: tags:
# Decision Layer Walkthrough
%% Cell type:markdown id: tags:
The decision layer library can be used as a super fast decision making layer on top of LLMs. That means that 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:code id: tags:
``` python
!pip install -qU \
decision-layer
```
%% 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 decision_layer.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 (we will add support for Hugging Face):
%% Cell type:code id: tags:
``` python
from decision_layer.encoders import OpenAIEncoder
import os
os.environ["OPENAI_API_KEY"] = "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"
os.environ["OPENAI_API_KEY"] = "sk-..."
encoder = OpenAIEncoder(name="text-embedding-ada-002")
```
%% 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 — for now we can only `_query` and get the most similar `Decision` `utterances`.
%% Cell type:code id: tags:
``` python
from decision_layer import DecisionLayer
dl = DecisionLayer(encoder=encoder, decisions=decisions)
```
%% Cell type:code id: tags:
``` python
out = dl._query("don't you love politics?")
out
```
%% Output
[{'decision': 'politics', 'score': 0.24968127755063652},
{'decision': 'politics', 'score': 0.2536216026530966},
{'decision': 'politics', 'score': 0.27568433588684954},
{'decision': 'politics', 'score': 0.27732789989574913},
{'decision': 'politics', 'score': 0.28110307885950714}]
%% Cell type:markdown id: tags:
---
......
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