" \"\"\"Useful to get the news in a specific country\"\"\"\n",
" print(\n",
" f\"Calling `get_news` function with category: {category} and country: {country}\"\n",
" )\n",
" return \"get_news\"\n",
"\n",
"\n",
"# Registering functions to the router\n",
"route_get_time = generate_route(get_time)\n",
"route_get_news = generate_route(get_news)\n",
"\n",
"routes = [route_get_time, route_get_news]\n",
"router = create_router(routes)\n",
"\n",
"# Tools\n",
"tools = [get_time, get_news]"
]
},
{
"cell_type": "code",
"execution_count": 220,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[32m2023-12-14 17:28:22 INFO semantic_router.utils.logger Generating config...\u001b[0m\n",
"\u001b[32m2023-12-14 17:28:28 INFO semantic_router.utils.logger AI message: {\"name\": \"get_time\", \"utterances\": [\"What is the time in SF?\", \"What is the current time in London?\", \"Time in Tokyo?\", \"Tell me the time in New York\", \"What is the time now in Paris?\"]}\u001b[0m\n",
"\u001b[32m2023-12-14 17:28:28 INFO semantic_router.utils.logger Generated config: {'name': 'get_time', 'utterances': ['What is the time in SF?', 'What is the current time in London?', 'Time in Tokyo?', 'Tell me the time in New York', 'What is the time now in Paris?']}\u001b[0m\n",
"\u001b[32m2023-12-14 17:28:28 INFO semantic_router.utils.logger Getting route layer...\u001b[0m\n"
"\u001b[32m2023-12-15 11:41:54 INFO semantic_router.utils.logger Extracting parameters...\u001b[0m\n",
"\u001b[32m2023-12-15 11:41:54 INFO semantic_router.utils.logger Calling Mistral model\u001b[0m\n",
"\u001b[32m2023-12-15 11:41:55 INFO semantic_router.utils.logger AI message: \n",
" {\n",
" 'location': 'Stockholm'\n",
" }\u001b[0m\n",
"\u001b[32m2023-12-15 11:41:55 INFO semantic_router.utils.logger Extracted parameters: {'location': 'Stockholm'}\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"AI message: {\"name\": \"get_time\", \"utterances\": [\"What is the time in SF?\", \"What is the current time in London?\", \"Time in Tokyo?\", \"Tell me the time in New York\", \"What is the time now in Paris?\"]}\n",
"Config: [{'name': 'get_time', 'utterances': ['What is the time in SF?', 'What is the current time in London?', 'Time in Tokyo?', 'Tell me the time in New York', 'What is the time now in Paris?']}]\n",
"Route: {'name': 'get_time', 'utterances': ['What is the time in SF?', 'What is the current time in London?', 'Time in Tokyo?', 'Tell me the time in New York', 'What is the time now in Paris?']}\n",
"None What is the weather like in Barcelona?\n"
"parameters: {'location': 'Stockholm'}\n",
"Calling `get_time` function with location: Stockholm\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[32m2023-12-14 17:28:29 INFO semantic_router.utils.logger Extracting parameters...\u001b[0m\n"
"\u001b[32m2023-12-15 11:41:55 INFO semantic_router.utils.logger Extracting parameters...\u001b[0m\n",
"\u001b[32m2023-12-15 11:41:55 INFO semantic_router.utils.logger Calling Mistral model\u001b[0m\n",
"\u001b[32m2023-12-15 11:41:56 INFO semantic_router.utils.logger AI message: \n",
" {\n",
" 'category': 'tech',\n",
" 'country': 'Lithuania'\n",
" }\u001b[0m\n",
"\u001b[32m2023-12-15 11:41:56 INFO semantic_router.utils.logger Extracted parameters: {'category': 'tech', 'country': 'Lithuania'}\u001b[0m\n"
"""Useful to get the news in a specific country"""
print(
f"Calling `get_news` function with category: {category} and country: {country}"
)
return"get_news"
%% Output
[32m2023-12-14 17:28:22 INFO semantic_router.utils.logger Generating config...[0m
[32m2023-12-14 17:28:28 INFO semantic_router.utils.logger AI message: {"name": "get_time", "utterances": ["What is the time in SF?", "What is the current time in London?", "Time in Tokyo?", "Tell me the time in New York", "What is the time now in Paris?"]}[0m
[32m2023-12-14 17:28:28 INFO semantic_router.utils.logger Generated config: {'name': 'get_time', 'utterances': ['What is the time in SF?', 'What is the current time in London?', 'Time in Tokyo?', 'Tell me the time in New York', 'What is the time now in Paris?']}[0m
[32m2023-12-14 17:28:28 INFO semantic_router.utils.logger Getting route layer...[0m
AI message: {"name": "get_time", "utterances": ["What is the time in SF?", "What is the current time in London?", "Time in Tokyo?", "Tell me the time in New York", "What is the time now in Paris?"]}
Config: [{'name': 'get_time', 'utterances': ['What is the time in SF?', 'What is the current time in London?', 'Time in Tokyo?', 'Tell me the time in New York', 'What is the time now in Paris?']}]
Route: {'name': 'get_time', 'utterances': ['What is the time in SF?', 'What is the current time in London?', 'Time in Tokyo?', 'Tell me the time in New York', 'What is the time now in Paris?']}
None What is the weather like in Barcelona?
# Registering functions to the router
route_get_time=generate_route(get_time)
route_get_news=generate_route(get_news)
[32m2023-12-14 17:28:29 INFO semantic_router.utils.logger Extracting parameters...[0m
routes=[route_get_time,route_get_news]
router=create_router(routes)
get_time What time is it in Taiwan?
# Tools
tools=[get_time,get_news]
```
%% Cell type:code id: tags:
``` python
call(query="What is the time in Stockholm?",
functions=tools,
router=router)
call(
query="What is the tech news in the Lithuania?",
functions=tools,
router=router)
call(
query="Hi!",
functions=tools,
router=router)
```
%% Output
[32m2023-12-15 11:41:54 INFO semantic_router.utils.logger Extracting parameters...[0m
[32m2023-12-15 11:41:54 INFO semantic_router.utils.logger Calling Mistral model[0m
[32m2023-12-15 11:41:55 INFO semantic_router.utils.logger AI message:
{
'location': 'Stockholm'
}[0m
[32m2023-12-15 11:41:55 INFO semantic_router.utils.logger Extracted parameters: {'location': 'Stockholm'}[0m
parameters: {'location': 'Stockholm'}
Calling `get_time` function with location: Stockholm
[32m2023-12-15 11:41:55 INFO semantic_router.utils.logger Extracting parameters...[0m
[32m2023-12-15 11:41:55 INFO semantic_router.utils.logger Calling Mistral model[0m
[32m2023-12-15 11:41:56 INFO semantic_router.utils.logger AI message:
{
'category': 'tech',
'country': 'Lithuania'
}[0m
[32m2023-12-15 11:41:56 INFO semantic_router.utils.logger Extracted parameters: {'category': 'tech', 'country': 'Lithuania'}[0m