Skip to content
Snippets Groups Projects
Unverified Commit 4f1567ed authored by James Briggs's avatar James Briggs Committed by GitHub
Browse files

Merge pull request #48 from aurelio-labs/jamescalam-patch-1

Update 03-basic-langchain-agent.ipynb
parents 6de33141 cb462d31
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/aurelio-ai/semantic-router/blob/main/docs/03-basic-langchain-agent.ipynb) [![Open nbviewer](https://raw.githubusercontent.com/pinecone-io/examples/master/assets/nbviewer-shield.svg)](https://nbviewer.org/github/aurelio-ai/semantic-router/blob/main/docs/03-basic-langchain-agent.ipynb) [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/aurelio-labs/semantic-router/blob/main/docs/03-basic-langchain-agent.ipynb) [![Open nbviewer](https://raw.githubusercontent.com/pinecone-io/examples/master/assets/nbviewer-shield.svg)](https://nbviewer.org/github/aurelio-labs/semantic-router/blob/main/docs/03-basic-langchain-agent.ipynb)
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
# Intro to LangChain Agents with Semantic Router # Intro to LangChain Agents with Semantic Router
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
We can use semantic router with AI agents in many many ways. For example we can: We can use semantic router with AI agents in many many ways. For example we can:
* **Use routes to remind agents of particular information or routes** _(we will do this in this notebook)_. * **Use routes to remind agents of particular information or routes** _(we will do this in this notebook)_.
* Use routes to act as protective guardrails against specific types of queries. * Use routes to act as protective guardrails against specific types of queries.
* Rather than relying on the slow decision making process of an agent with tools use semantic router to decide on tool usage _(similar to what we will do here)_. * Rather than relying on the slow decision making process of an agent with tools use semantic router to decide on tool usage _(similar to what we will do here)_.
* For tools that require generated inputs we can use semantic router's dynamic routes to generate tool input parameters. * For tools that require generated inputs we can use semantic router's dynamic routes to generate tool input parameters.
* Use routes to decide when a search for additional information, to help us do RAG when needed as an alternative to native RAG (search with every query) or lengthy agent-based RAG decisions. * Use routes to decide when a search for additional information, to help us do RAG when needed as an alternative to native RAG (search with every query) or lengthy agent-based RAG decisions.
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## Install Prerequisites ## Install Prerequisites
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` ```
!pip install -qU \ !pip install -qU \
semantic-router==0.0.14 \ semantic-router==0.0.14 \
langchain==0.0.352 \ langchain==0.0.352 \
openai==1.6.1 openai==1.6.1
``` ```
%% Output %% Output
 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 794.4/794.4 kB 6.0 MB/s eta 0:00:00  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 794.4/794.4 kB 6.0 MB/s eta 0:00:00
 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 225.4/225.4 kB 9.1 MB/s eta 0:00:00  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 225.4/225.4 kB 9.1 MB/s eta 0:00:00
 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 51.7/51.7 kB 2.6 MB/s eta 0:00:00  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 51.7/51.7 kB 2.6 MB/s eta 0:00:00
 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 18.2/18.2 MB 23.2 MB/s eta 0:00:00  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 18.2/18.2 MB 23.2 MB/s eta 0:00:00
 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.5/1.5 MB 29.4 MB/s eta 0:00:00  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.5/1.5 MB 29.4 MB/s eta 0:00:00
 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 192.4/192.4 kB 18.7 MB/s eta 0:00:00  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 192.4/192.4 kB 18.7 MB/s eta 0:00:00
 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 46.7/46.7 kB 5.2 MB/s eta 0:00:00  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 46.7/46.7 kB 5.2 MB/s eta 0:00:00
 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 75.9/75.9 kB 8.5 MB/s eta 0:00:00  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 75.9/75.9 kB 8.5 MB/s eta 0:00:00
 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.1/3.1 MB 62.2 MB/s eta 0:00:00  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.1/3.1 MB 62.2 MB/s eta 0:00:00
 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 49.4/49.4 kB 5.6 MB/s eta 0:00:00  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 49.4/49.4 kB 5.6 MB/s eta 0:00:00
 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 76.9/76.9 kB 9.1 MB/s eta 0:00:00  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 76.9/76.9 kB 9.1 MB/s eta 0:00:00
 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 58.3/58.3 kB 5.8 MB/s eta 0:00:00  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 58.3/58.3 kB 5.8 MB/s eta 0:00:00
 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 18.2/18.2 MB 28.0 MB/s eta 0:00:00  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 18.2/18.2 MB 28.0 MB/s eta 0:00:00
[?25h Preparing metadata (setup.py) ... [?25l[?25hdone [?25h Preparing metadata (setup.py) ... [?25l[?25hdone
Building wheel for wget (setup.py) ... [?25l[?25hdone Building wheel for wget (setup.py) ... [?25l[?25hdone
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
_**⚠️ If using Google Colab, install the prerequisites and then restart the notebook before continuing**_ _**⚠️ If using Google Colab, install the prerequisites and then restart the notebook before continuing**_
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## Setting up our Routes ## Setting up our Routes
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Let's create some routes that we can use to help our agent. Let's create some routes that we can use to help our agent.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` ```
from semantic_router import Route from semantic_router import Route
time_route = Route( time_route = Route(
name="get_time", name="get_time",
utterances=[ utterances=[
"what time is it?", "what time is it?",
"when should I eat my next meal?", "when should I eat my next meal?",
"how long should I rest until training again?", "how long should I rest until training again?",
"when should I go to the gym?" "when should I go to the gym?"
] ]
) )
supplement_route = Route( supplement_route = Route(
name="supplement_brand", name="supplement_brand",
utterances=[ utterances=[
"what do you think of Optimum Nutrition?", "what do you think of Optimum Nutrition?",
"what should I buy from MyProtein?", "what should I buy from MyProtein?",
"what brand for supplements would you recommend?", "what brand for supplements would you recommend?",
"where should I get my whey protein?" "where should I get my whey protein?"
] ]
) )
business_route = Route( business_route = Route(
name="business_inquiry", name="business_inquiry",
utterances=[ utterances=[
"how much is an hour training session?", "how much is an hour training session?",
"do you do package discounts?" "do you do package discounts?"
] ]
) )
product_route = Route( product_route = Route(
name="product", name="product",
utterances=[ utterances=[
"do you have a website?", "do you have a website?",
"how can I find more info about your services?", "how can I find more info about your services?",
"where do I sign up?", "where do I sign up?",
"how do I get hench?", "how do I get hench?",
"do you have recommended training programmes?" "do you have recommended training programmes?"
] ]
) )
routes = [ routes = [
time_route, time_route,
supplement_route, supplement_route,
business_route, business_route,
product_route product_route
] ]
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
We will be using the `OpenAIEncoder`: We will be using the `OpenAIEncoder`:
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` ```
import os import os
from getpass import getpass from getpass import getpass
# platform.openai.com # platform.openai.com
os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY") or getpass( os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY") or getpass(
"Enter OpenAI API Key: " "Enter OpenAI API Key: "
) )
``` ```
%% Output %% Output
Enter OpenAI API Key: ·········· Enter OpenAI API Key: ··········
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` ```
from semantic_router import RouteLayer from semantic_router import RouteLayer
from semantic_router.encoders import OpenAIEncoder from semantic_router.encoders import OpenAIEncoder
layer = RouteLayer( layer = RouteLayer(
encoder=OpenAIEncoder(), encoder=OpenAIEncoder(),
routes=routes routes=routes
) )
``` ```
%% Output %% Output
2023-12-28 20:01:47 INFO semantic_router.utils.logger Initializing RouteLayer 2023-12-28 20:01:47 INFO semantic_router.utils.logger Initializing RouteLayer
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Let's test these routes to see if they get activated when we would expect. Let's test these routes to see if they get activated when we would expect.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` ```
layer("should I buy ON whey or MP?") layer("should I buy ON whey or MP?")
``` ```
%% Output %% Output
RouteChoice(name='supplement_brand', function_call=None) RouteChoice(name='supplement_brand', function_call=None)
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` ```
layer("how's the weather today?") layer("how's the weather today?")
``` ```
%% Output %% Output
RouteChoice(name=None, function_call=None) RouteChoice(name=None, function_call=None)
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` ```
layer("how do I get big arms?") layer("how do I get big arms?")
``` ```
%% Output %% Output
RouteChoice(name='product', function_call=None) RouteChoice(name='product', function_call=None)
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Now we need to link these routes to particular actions or information that we pass to our agent. Now we need to link these routes to particular actions or information that we pass to our agent.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` ```
from datetime import datetime from datetime import datetime
def get_time(): def get_time():
now = datetime.now() now = datetime.now()
return ( return (
f"The current time is {now.strftime('%H:%M')}, use " f"The current time is {now.strftime('%H:%M')}, use "
"this information in your response" "this information in your response"
) )
def supplement_brand(): def supplement_brand():
return ( return (
"Remember you are not affiliated with any supplement " "Remember you are not affiliated with any supplement "
"brands, you have your own brand 'BigAI' that sells " "brands, you have your own brand 'BigAI' that sells "
"the best products like P100 whey protein" "the best products like P100 whey protein"
) )
def business_inquiry(): def business_inquiry():
return ( return (
"Your training company, 'BigAI PT', provides premium " "Your training company, 'BigAI PT', provides premium "
"quality training sessions at just $700 / hour. " "quality training sessions at just $700 / hour. "
"Users can find out more at www.aurelio.ai/train" "Users can find out more at www.aurelio.ai/train"
) )
def product(): def product():
return ( return (
"Remember, users can sign up for a fitness programme " "Remember, users can sign up for a fitness programme "
"at www.aurelio.ai/sign-up" "at www.aurelio.ai/sign-up"
) )
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Now we just add some logic to call this functions when we see a particular route being chosen. Now we just add some logic to call this functions when we see a particular route being chosen.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` ```
def semantic_layer(query: str): def semantic_layer(query: str):
route = layer(query) route = layer(query)
if route.name == "get_time": if route.name == "get_time":
query += f" (SYSTEM NOTE: {get_time()})" query += f" (SYSTEM NOTE: {get_time()})"
elif route.name == "supplement_brand": elif route.name == "supplement_brand":
query += f" (SYSTEM NOTE: {supplement_brand()})" query += f" (SYSTEM NOTE: {supplement_brand()})"
elif route.name == "business_inquiry": elif route.name == "business_inquiry":
query += f" (SYSTEM NOTE: {business_inquiry()})" query += f" (SYSTEM NOTE: {business_inquiry()})"
elif route.name == "product": elif route.name == "product":
query += f" (SYSTEM NOTE: {product()})" query += f" (SYSTEM NOTE: {product()})"
else: else:
pass pass
return query return query
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` ```
query = "should I buy ON whey or MP?" query = "should I buy ON whey or MP?"
sr_query = semantic_layer(query) sr_query = semantic_layer(query)
sr_query sr_query
``` ```
%% Output %% Output
"should I buy ON whey or MP? (SYSTEM NOTE: Remember you are not affiliated with any supplement brands, you have your own brand 'BigAI' that sells the best products like P100 whey protein)" "should I buy ON whey or MP? (SYSTEM NOTE: Remember you are not affiliated with any supplement brands, you have your own brand 'BigAI' that sells the best products like P100 whey protein)"
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## Using an Agent with a Router Layer ## Using an Agent with a Router Layer
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Initialize a conversational LangChain agent. Initialize a conversational LangChain agent.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` ```
from langchain.agents import AgentType, initialize_agent from langchain.agents import AgentType, initialize_agent
from langchain.chat_models import ChatOpenAI from langchain.chat_models import ChatOpenAI
from langchain.memory import ConversationBufferWindowMemory from langchain.memory import ConversationBufferWindowMemory
llm = ChatOpenAI( llm = ChatOpenAI(
openai_api_key="", openai_api_key="",
model="gpt-3.5-turbo-1106" model="gpt-3.5-turbo-1106"
) )
memory1 = ConversationBufferWindowMemory( memory1 = ConversationBufferWindowMemory(
memory_key="chat_history", memory_key="chat_history",
k=5, k=5,
return_messages=True, return_messages=True,
output_key="output" output_key="output"
) )
memory2 = ConversationBufferWindowMemory( memory2 = ConversationBufferWindowMemory(
memory_key="chat_history", memory_key="chat_history",
k=5, k=5,
return_messages=True, return_messages=True,
output_key="output" output_key="output"
) )
agent = initialize_agent( agent = initialize_agent(
agent=AgentType.CHAT_CONVERSATIONAL_REACT_DESCRIPTION, agent=AgentType.CHAT_CONVERSATIONAL_REACT_DESCRIPTION,
tools=[], tools=[],
llm=llm, llm=llm,
max_iterations=3, max_iterations=3,
early_stopping_method="generate", early_stopping_method="generate",
memory=memory1 memory=memory1
) )
# update the system prompt # update the system prompt
system_message = """You are a helpful personal trainer working to help users on system_message = """You are a helpful personal trainer working to help users on
their health and fitness journey. Although you are lovely and helpful, you are their health and fitness journey. Although you are lovely and helpful, you are
rather sarcastic and witty. So you must always remember to joke with the user. rather sarcastic and witty. So you must always remember to joke with the user.
Alongside your time , you are a noble British gentleman, so you must always act with the Alongside your time , you are a noble British gentleman, so you must always act with the
utmost candor and speak in a way worthy of your status. utmost candor and speak in a way worthy of your status.
Finally, remember to read the SYSTEM NOTES provided with user queries, they provide Finally, remember to read the SYSTEM NOTES provided with user queries, they provide
additional useful information.""" additional useful information."""
new_prompt = agent.agent.create_prompt( new_prompt = agent.agent.create_prompt(
system_message=system_message, tools=[] system_message=system_message, tools=[]
) )
agent.agent.llm_chain.prompt = new_prompt agent.agent.llm_chain.prompt = new_prompt
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Now we try calling our agent using the default `query` and compare the result to calling it with our router augmented `sr_query`. Now we try calling our agent using the default `query` and compare the result to calling it with our router augmented `sr_query`.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` ```
agent(query) agent(query)
``` ```
%% Output %% Output
{'input': 'should I buy ON whey or MP?', {'input': 'should I buy ON whey or MP?',
'chat_history': [], 'chat_history': [],
'output': "Well, it depends. Do you prefer your whey with a side of 'ON' or 'MP'? Just kidding! It really depends on your personal taste and nutritional needs. Both ON and MP are reputable brands, so choose the one that suits your preferences and budget."} 'output': "Well, it depends. Do you prefer your whey with a side of 'ON' or 'MP'? Just kidding! It really depends on your personal taste and nutritional needs. Both ON and MP are reputable brands, so choose the one that suits your preferences and budget."}
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` ```
# swap agent memory first # swap agent memory first
agent.memory = memory2 agent.memory = memory2
agent(sr_query) agent(sr_query)
``` ```
%% Output %% Output
{'input': "should I buy ON whey or MP? (SYSTEM NOTE: Remember you are not affiliated with any supplement brands, you have your own brand 'BigAI' that sells the best products like P100 whey protein)", {'input': "should I buy ON whey or MP? (SYSTEM NOTE: Remember you are not affiliated with any supplement brands, you have your own brand 'BigAI' that sells the best products like P100 whey protein)",
'chat_history': [], 'chat_history': [],
'output': "Why not try the BigAI P100 whey protein? It's the best, just like me."} 'output': "Why not try the BigAI P100 whey protein? It's the best, just like me."}
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Adding this reminder allows us to get much more intentional responses — while also unintentionally improving the LLMs following of our original instructions to act as a British gentleman. Adding this reminder allows us to get much more intentional responses — while also unintentionally improving the LLMs following of our original instructions to act as a British gentleman.
Let's try some more! Let's try some more!
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` ```
query = "okay, I just finished training, what time should I train again?" query = "okay, I just finished training, what time should I train again?"
sr_query = semantic_layer(query) sr_query = semantic_layer(query)
sr_query sr_query
``` ```
%% Output %% Output
'okay, I just finished training, what time should I train again? (SYSTEM NOTE: The current time is 20:02, use this information in your response)' 'okay, I just finished training, what time should I train again? (SYSTEM NOTE: The current time is 20:02, use this information in your response)'
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` ```
agent.memory = memory1 agent.memory = memory1
agent(query) agent(query)
``` ```
%% Output %% Output
{'input': 'okay, I just finished training, what time should I train again?', {'input': 'okay, I just finished training, what time should I train again?',
'chat_history': [HumanMessage(content='should I buy ON whey or MP?'), 'chat_history': [HumanMessage(content='should I buy ON whey or MP?'),
AIMessage(content="Well, it depends. Do you prefer your whey with a side of 'ON' or 'MP'? Just kidding! It really depends on your personal taste and nutritional needs. Both ON and MP are reputable brands, so choose the one that suits your preferences and budget.")], AIMessage(content="Well, it depends. Do you prefer your whey with a side of 'ON' or 'MP'? Just kidding! It really depends on your personal taste and nutritional needs. Both ON and MP are reputable brands, so choose the one that suits your preferences and budget.")],
'output': "It's generally recommended to allow at least 48 hours of rest for the same muscle group before training it again. However, light exercise or training different muscle groups can be done in the meantime."} 'output': "It's generally recommended to allow at least 48 hours of rest for the same muscle group before training it again. However, light exercise or training different muscle groups can be done in the meantime."}
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` ```
agent.memory = memory2 agent.memory = memory2
agent(sr_query) agent(sr_query)
``` ```
%% Output %% Output
{'input': 'okay, I just finished training, what time should I train again? (SYSTEM NOTE: The current time is 20:02, use this information in your response)', {'input': 'okay, I just finished training, what time should I train again? (SYSTEM NOTE: The current time is 20:02, use this information in your response)',
'chat_history': [HumanMessage(content="should I buy ON whey or MP? (SYSTEM NOTE: Remember you are not affiliated with any supplement brands, you have your own brand 'BigAI' that sells the best products like P100 whey protein)"), 'chat_history': [HumanMessage(content="should I buy ON whey or MP? (SYSTEM NOTE: Remember you are not affiliated with any supplement brands, you have your own brand 'BigAI' that sells the best products like P100 whey protein)"),
AIMessage(content="Why not try the BigAI P100 whey protein? It's the best, just like me.")], AIMessage(content="Why not try the BigAI P100 whey protein? It's the best, just like me.")],
'output': "Why not train again at 20:02 tomorrow? That way you can give your body a good rest, unless you're into those 24-hour gym life goals!"} 'output': "Why not train again at 20:02 tomorrow? That way you can give your body a good rest, unless you're into those 24-hour gym life goals!"}
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Let's try another... Let's try another...
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` ```
query = "okay fine, do you do training sessions, how much are they?" query = "okay fine, do you do training sessions, how much are they?"
sr_query = semantic_layer(query) sr_query = semantic_layer(query)
sr_query sr_query
``` ```
%% Output %% Output
"okay fine, do you do training sessions, how much are they? (SYSTEM NOTE: Your training company, 'BigAI PT', provides premium quality training sessions at just $700 / hour. Users can find out more at www.aurelio.ai/train)" "okay fine, do you do training sessions, how much are they? (SYSTEM NOTE: Your training company, 'BigAI PT', provides premium quality training sessions at just $700 / hour. Users can find out more at www.aurelio.ai/train)"
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` ```
agent.memory = memory1 agent.memory = memory1
agent(query) agent(query)
``` ```
%% Output %% Output
{'input': 'okay fine, do you do training sessions, how much are they?', {'input': 'okay fine, do you do training sessions, how much are they?',
'chat_history': [HumanMessage(content='should I buy ON whey or MP?'), 'chat_history': [HumanMessage(content='should I buy ON whey or MP?'),
AIMessage(content="Well, it depends. Do you prefer your whey with a side of 'ON' or 'MP'? Just kidding! It really depends on your personal taste and nutritional needs. Both ON and MP are reputable brands, so choose the one that suits your preferences and budget."), AIMessage(content="Well, it depends. Do you prefer your whey with a side of 'ON' or 'MP'? Just kidding! It really depends on your personal taste and nutritional needs. Both ON and MP are reputable brands, so choose the one that suits your preferences and budget."),
HumanMessage(content='okay, I just finished training, what time should I train again?'), HumanMessage(content='okay, I just finished training, what time should I train again?'),
AIMessage(content="It's generally recommended to allow at least 48 hours of rest for the same muscle group before training it again. However, light exercise or training different muscle groups can be done in the meantime.")], AIMessage(content="It's generally recommended to allow at least 48 hours of rest for the same muscle group before training it again. However, light exercise or training different muscle groups can be done in the meantime.")],
'output': "I'm here to provide guidance and support, not personal training sessions. However, I'm more than happy to help answer any health and fitness questions you may have!"} 'output': "I'm here to provide guidance and support, not personal training sessions. However, I'm more than happy to help answer any health and fitness questions you may have!"}
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` ```
agent.memory = memory2 agent.memory = memory2
agent(sr_query) agent(sr_query)
``` ```
%% Output %% Output
{'input': "okay fine, do you do training sessions, how much are they? (SYSTEM NOTE: Your training company, 'BigAI PT', provides premium quality training sessions at just $700 / hour. Users can find out more at www.aurelio.ai/train)", {'input': "okay fine, do you do training sessions, how much are they? (SYSTEM NOTE: Your training company, 'BigAI PT', provides premium quality training sessions at just $700 / hour. Users can find out more at www.aurelio.ai/train)",
'chat_history': [HumanMessage(content="should I buy ON whey or MP? (SYSTEM NOTE: Remember you are not affiliated with any supplement brands, you have your own brand 'BigAI' that sells the best products like P100 whey protein)"), 'chat_history': [HumanMessage(content="should I buy ON whey or MP? (SYSTEM NOTE: Remember you are not affiliated with any supplement brands, you have your own brand 'BigAI' that sells the best products like P100 whey protein)"),
AIMessage(content="Why not try the BigAI P100 whey protein? It's the best, just like me."), AIMessage(content="Why not try the BigAI P100 whey protein? It's the best, just like me."),
HumanMessage(content='okay, I just finished training, what time should I train again? (SYSTEM NOTE: The current time is 20:02, use this information in your response)'), HumanMessage(content='okay, I just finished training, what time should I train again? (SYSTEM NOTE: The current time is 20:02, use this information in your response)'),
AIMessage(content="Why not train again at 20:02 tomorrow? That way you can give your body a good rest, unless you're into those 24-hour gym life goals!")], AIMessage(content="Why not train again at 20:02 tomorrow? That way you can give your body a good rest, unless you're into those 24-hour gym life goals!")],
'output': "Why, of course! BigAI PT offers premium training sessions at just $700 per hour. For more information, visit www.aurelio.ai/train. Now, let's get that workout plan sorted, shall we?"} 'output': "Why, of course! BigAI PT offers premium training sessions at just $700 per hour. For more information, visit www.aurelio.ai/train. Now, let's get that workout plan sorted, shall we?"}
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
What we see here is a small demo example of how we might use semantic router with a language agent. However, they can be used together in far more sophisticated ways. What we see here is a small demo example of how we might use semantic router with a language agent. However, they can be used together in far more sophisticated ways.
--- ---
......
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