Skip to content

Commit

Permalink
Merge pull request #85 from aurelio-labs/james/v0.0.15
Browse files Browse the repository at this point in the history
fix: James/v0.0.15
  • Loading branch information
jamescalam authored Jan 7, 2024
2 parents 99ce319 + 1595d64 commit b8f4a00
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 60 deletions.
24 changes: 12 additions & 12 deletions docs/00-introduction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"metadata": {},
"outputs": [],
"source": [
"!pip install -qU semantic-router==0.0.14"
"!pip install -qU semantic-router==0.0.15"
]
},
{
Expand All @@ -60,7 +60,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -88,7 +88,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -115,7 +115,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -143,14 +143,14 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[32m2023-12-28 19:14:34 INFO semantic_router.utils.logger Initializing RouteLayer\u001b[0m\n"
"\u001b[32m2024-01-07 18:08:29 INFO semantic_router.utils.logger Initializing RouteLayer\u001b[0m\n"
]
}
],
Expand All @@ -169,7 +169,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 5,
"metadata": {},
"outputs": [
{
Expand All @@ -178,7 +178,7 @@
"RouteChoice(name='politics', function_call=None)"
]
},
"execution_count": 7,
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -189,7 +189,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 6,
"metadata": {},
"outputs": [
{
Expand All @@ -198,7 +198,7 @@
"RouteChoice(name='chitchat', function_call=None)"
]
},
"execution_count": 8,
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -216,7 +216,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 7,
"metadata": {},
"outputs": [
{
Expand All @@ -225,7 +225,7 @@
"RouteChoice(name=None, function_call=None)"
]
},
"execution_count": 9,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
Expand Down
47 changes: 20 additions & 27 deletions docs/01-save-load-from-file.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"metadata": {},
"outputs": [],
"source": [
"!pip install -qU semantic-router==0.0.14"
"!pip install -qU semantic-router==0.0.15"
]
},
{
Expand Down Expand Up @@ -64,17 +64,7 @@
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/jamesbriggs/opt/anaconda3/envs/decision-layer/lib/python3.11/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
" from .autonotebook import tqdm as notebook_tqdm\n",
"None of PyTorch, TensorFlow >= 2.0, or Flax have been found. Models won't be available and only tokenizers, configuration and file/data utilities can be used.\n"
]
}
],
"outputs": [],
"source": [
"from semantic_router import Route\n",
"\n",
Expand Down Expand Up @@ -106,33 +96,36 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"We define a route layer using these routes and using the default Cohere encoder."
"We define a route layer using these routes and using the Cohere encoder."
]
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[32m2023-12-28 19:16:54 INFO semantic_router.utils.logger Initializing RouteLayer\u001b[0m\n"
"\u001b[32m2024-01-07 18:10:03 INFO semantic_router.utils.logger Initializing RouteLayer\u001b[0m\n"
]
}
],
"source": [
"import os\n",
"from getpass import getpass\n",
"from semantic_router import RouteLayer\n",
"from semantic_router.encoders import CohereEncoder\n",
"\n",
"# dashboard.cohere.ai\n",
"os.environ[\"COHERE_API_KEY\"] = os.getenv(\"COHERE_API_KEY\") or getpass(\n",
" \"Enter Cohere API Key: \"\n",
")\n",
"\n",
"rl = RouteLayer(routes=routes)"
"encoder = CohereEncoder()\n",
"\n",
"rl = RouteLayer(encoder=encoder, routes=routes)"
]
},
{
Expand All @@ -144,14 +137,14 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[32m2023-12-28 19:17:03 INFO semantic_router.utils.logger Saving route config to layer.json\u001b[0m\n"
"\u001b[32m2024-01-07 18:10:05 INFO semantic_router.utils.logger Saving route config to layer.json\u001b[0m\n"
]
}
],
Expand All @@ -175,14 +168,14 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'encoder_type': 'cohere', 'encoder_name': 'embed-english-v3.0', 'routes': [{'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 presidentdon't you just hate the president\", \"they're going to destroy this country!\", 'they will save the country!'], 'description': None, 'function_schema': None}, {'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\"], 'description': None, 'function_schema': None}]}\n"
"{'encoder_type': 'cohere', 'encoder_name': 'embed-english-v3.0', 'routes': [{'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 presidentdon't you just hate the president\", \"they're going to destroy this country!\", 'they will save the country!'], 'description': None, 'function_schema': None, 'llm': None}, {'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\"], 'description': None, 'function_schema': None, 'llm': None}]}\n"
]
}
],
Expand All @@ -204,15 +197,15 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[32m2023-12-28 19:17:08 INFO semantic_router.utils.logger Loading route config from layer.json\u001b[0m\n",
"\u001b[32m2023-12-28 19:17:08 INFO semantic_router.utils.logger Initializing RouteLayer\u001b[0m\n"
"\u001b[32m2024-01-07 18:10:14 INFO semantic_router.utils.logger Loading route config from layer.json\u001b[0m\n",
"\u001b[32m2024-01-07 18:10:14 INFO semantic_router.utils.logger Initializing RouteLayer\u001b[0m\n"
]
}
],
Expand All @@ -229,16 +222,16 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"layer.encoder.type='cohere'\n",
"layer.encoder.name='embed-english-v3.0'\n",
"layer.routes=[Route(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 presidentdon't you just hate the president\", \"they're going to destroy this country!\", 'they will save the country!'], description=None, function_schema=None), Route(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\"], description=None, function_schema=None)]\n"
"rl.encoder.type='cohere'\n",
"rl.encoder.name='embed-english-v3.0'\n",
"rl.routes=[Route(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 presidentdon't you just hate the president\", \"they're going to destroy this country!\", 'they will save the country!'], description=None, function_schema=None, llm=None), Route(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\"], description=None, function_schema=None, llm=None)]\n"
]
}
],
Expand Down
17 changes: 12 additions & 5 deletions docs/02-dynamic-routes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[32m2024-01-07 15:23:12 INFO semantic_router.utils.logger Initializing RouteLayer\u001b[0m\n"
"\u001b[32m2024-01-07 18:11:05 INFO semantic_router.utils.logger Initializing RouteLayer\u001b[0m\n"
]
}
],
Expand Down Expand Up @@ -204,7 +204,7 @@
{
"data": {
"text/plain": [
"'09:23'"
"'12:11'"
]
},
"execution_count": 5,
Expand Down Expand Up @@ -289,7 +289,7 @@
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[32m2024-01-07 15:23:16 INFO semantic_router.utils.logger Adding `get_time` route\u001b[0m\n"
"\u001b[32m2024-01-07 18:11:20 INFO semantic_router.utils.logger Adding `get_time` route\u001b[0m\n"
]
}
],
Expand All @@ -313,8 +313,8 @@
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[33m2024-01-07 15:23:17 WARNING semantic_router.utils.logger No LLM provided for dynamic route, will use OpenAI LLM default. Ensure API key is set in OPENAI_API_KEY environment variable.\u001b[0m\n",
"\u001b[32m2024-01-07 15:23:17 INFO semantic_router.utils.logger Extracting function input...\u001b[0m\n"
"\u001b[33m2024-01-07 18:11:23 WARNING semantic_router.utils.logger No LLM provided for dynamic route, will use OpenAI LLM default. Ensure API key is set in OPENAI_API_KEY environment variable.\u001b[0m\n",
"\u001b[32m2024-01-07 18:11:23 INFO semantic_router.utils.logger Extracting function input...\u001b[0m\n"
]
},
{
Expand All @@ -337,6 +337,13 @@
"rl(\"what is the time in new york city?\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Our dynamic route provides both the route itself _and_ the input parameters required to use the route."
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down
4 changes: 2 additions & 2 deletions docs/03-basic-langchain-agent.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
],
"source": [
"!pip install -qU \\\n",
" semantic-router==0.0.14 \\\n",
" semantic-router==0.0.15 \\\n",
" langchain==0.0.352 \\\n",
" openai==1.6.1"
]
Expand Down Expand Up @@ -458,7 +458,7 @@
"from langchain.chat_models import ChatOpenAI\n",
"from langchain.memory import ConversationBufferWindowMemory\n",
"\n",
"llm = ChatOpenAI(openai_api_key=\"\", model=\"gpt-3.5-turbo-1106\")\n",
"llm = ChatOpenAI(model=\"gpt-3.5-turbo-1106\")\n",
"\n",
"memory1 = ConversationBufferWindowMemory(\n",
" memory_key=\"chat_history\", k=5, return_messages=True, output_key=\"output\"\n",
Expand Down
22 changes: 10 additions & 12 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ authors = [
"Siraj Aizlewood <[email protected]>",
"Simonas Jakubonis <[email protected]>",
"Luca Mannini <[email protected]>",
"Bogdan Buduroiu <[email protected]>"
"Bogdan Buduroiu <[email protected]>",
"Ismail Ashraq <[email protected]>"
]
readme = "README.md"
packages = [{include = "semantic_router"}]

[tool.poetry.dependencies]
python = ">=3.9,<3.12"
python = ">=3.10,<3.12"
pydantic = "^1.8.2"
openai = "^1.3.9"
cohere = "^4.32"
Expand Down

0 comments on commit b8f4a00

Please sign in to comment.