"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."
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Getting Started"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"\n",
"[notice] A new release of pip is available: 23.1.2 -> 23.3.1\n",
"[notice] To update, run: python.exe -m pip install --upgrade pip\n"
]
}
],
"source": [
"!pip install -qU \\\n",
" decision-layer"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"We start by defining a dictionary mapping decisions to example phrases that should trigger those decisions."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"from decision_layer.schema import Decision\n",
"\n",
"politics = Decision(\n",
" name=\"politics\",\n",
" utterances=[\n",
" \"isn't politics the best thing ever\",\n",
" \"why don't you tell me about your political opinions\",\n",
" \"don't you just love the president\"\n",
" \"don't you just hate the president\",\n",
" \"they're going to destroy this country!\",\n",
" \"they will save the country!\",\n",
" \"did you hear about the new goverment proposal regarding the ownership of cats and dogs\",\n",
" ]\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"other_brands = Decision(\n",
" name=\"other_brands\",\n",
" utterances=[\n",
" \"How can I use Binance?\"\n",
" \"How should I deposit to eToro?\"\n",
" \"How to withdraw from Interactive Brokers\"\n",
" \"How to copy text on Microsoft Word\"\n",
" \"Can I enlarge images on Adobe Photoshop?\"\n",
" \"Help me withdraw funds from HSBC.\"\n",
" ]\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"discount = Decision(\n",
" name=\"discount\",\n",
" utterances=[\n",
" \"User asks for or about coupons, discounts, freebies, free stuff, offers, promotions or incentives\"\n",
"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`."
"\u001b[1;32mc:\\Users\\Siraj\\Documents\\Personal\\Work\\Aurelio\\20231106 Semantic Layer\\Repo\\semantic-layer\\00_walkthrough.ipynb Cell 20\u001b[0m line \u001b[0;36m1\n\u001b[1;32m----> <a href='vscode-notebook-cell:/c%3A/Users/Siraj/Documents/Personal/Work/Aurelio/20231106%20Semantic%20Layer/Repo/semantic-layer/00_walkthrough.ipynb#X26sZmlsZQ%3D%3D?line=0'>1</a>\u001b[0m out \u001b[39m=\u001b[39m dl(\u001b[39m\"\u001b[39m\u001b[39mHow do I bake a cake?\u001b[39m\u001b[39m\"\u001b[39m, _tan\u001b[39m=\u001b[39m\u001b[39mTrue\u001b[39;00m, _threshold\u001b[39m=\u001b[39m\u001b[39m0.5\u001b[39m)\n\u001b[0;32m <a href='vscode-notebook-cell:/c%3A/Users/Siraj/Documents/Personal/Work/Aurelio/20231106%20Semantic%20Layer/Repo/semantic-layer/00_walkthrough.ipynb#X26sZmlsZQ%3D%3D?line=1'>2</a>\u001b[0m \u001b[39mprint\u001b[39m(out)\n",
"\u001b[1;31mNameError\u001b[0m: name 'dl' is not defined"
]
}
],
"source": [
"out = dl(\"How do I bake a cake?\", _tan=True, _threshold=0.5)\n",
"print(out)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "decision-layer",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.4"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
%% 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
!pipinstall-qU \
decision-layer
```
%% Output
[notice] A new release of pip is available: 23.1.2 -> 23.3.1
[notice] To update, run: python.exe -m pip install --upgrade pip
%% 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
fromdecision_layer.schemaimportDecision
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!",
"did you hear about the new goverment proposal regarding the ownership of cats and dogs",
]
)
```
%% Cell type:code id: tags:
``` python
other_brands=Decision(
name="other_brands",
utterances=[
"How can I use Binance?"
"How should I deposit to eToro?"
"How to withdraw from Interactive Brokers"
"How to copy text on Microsoft Word"
"Can I enlarge images on Adobe Photoshop?"
"Help me withdraw funds from HSBC."
]
)
```
%% Cell type:code id: tags:
``` python
discount=Decision(
name="discount",
utterances=[
"User asks for or about coupons, discounts, freebies, free stuff, offers, promotions or incentives"
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`.
c:\Users\Siraj\Documents\Personal\Work\Aurelio\20231106 Semantic Layer\Repo\semantic-layer\00_walkthrough.ipynb Cell 20 line 1
----> <a href='vscode-notebook-cell:/c%3A/Users/Siraj/Documents/Personal/Work/Aurelio/20231106%20Semantic%20Layer/Repo/semantic-layer/00_walkthrough.ipynb#X26sZmlsZQ%3D%3D?line=0'>1</a> out = dl("How do I bake a cake?", _tan=True, _threshold=0.5)