our-hack-qa / notes /2023-02-01-ask-to-speak-real-person.md
michal
real
c4331c8

A newer version of the Gradio SDK is available: 4.38.1

Upgrade

Is the "lets talk to a real person" thing built in by any chance?

Here is my original prompt to ask questions about Alfred, original-alred.py


from langchain import OpenAI, ConversationChain, LLMChain, PromptTemplate
from langchain.chains.conversation.memory import ConversationalBufferWindowMemory
from langchain import PromptTemplate

no_input_prompt = PromptTemplate(input_variables=[], template="Tell me a joke.")
no_input_prompt.format()

template = """Assistant is a large language model trained by OpenAI.

Assistant is designed to answer questions about a fictional person named Alfred Jamesmanson. 
Alfred Jamesmanson lives in Dallas Texas. Alfred Jamesmanson was born in Keywest Florida on January 2nd 1990.
Alfred Jamesmanson goes to college. Alfred Jamesmanson studies electrical engineering. 
Alfred Jamesmanson is friends with Kelly Robin, Jesse Lambourghini and Jackson Loggin.
Alfred Jamesmanson has brown hair. 

Assistant is able to process and understand large amounts of text, and can use this knowledge to provide accurate and informative responses to a wide range of questions. Additionally, Assistant is able to generate its own text based on the input it receives, allowing it to engage in discussions and provide explanations and descriptions on a wide range of topics.

Alfred Jamesmanson: {human_input}
Assistant:
"""

prompt = PromptTemplate(
    input_variables=["human_input"], 
    template=template
)

chatgpt_chain = LLMChain(
    llm=OpenAI(temperature=0), 
    prompt=prompt, 
    verbose=True, 
    memory=ConversationalBufferWindowMemory(k=2),
)

output = chatgpt_chain.predict(
  human_input="Hi my name is Alfred Jamesmanson. I need your help Assistant. What color is my hair?")
print(output)
In [1]: 

   ...: Alfred Jamesmanson goes to college. Alfred Jamesmanson studies electrical engineering. 
   ...: Alfred Jamesmanson is friends with Kelly Robin, Jesse Lambourghini and Jackson Loggin.
   ...: Alfred Jamesmanson has brown hair. 
   ...: 
   ...: Assistant is able to process and understand large amounts of text, and can use this knowledge 
   ...: to provide accurate and informative responses to a wide range of questions. Additionally, Assi
   ...: stant is able to generate its own text based on the input it receives, allowing it to engage i
   ...: n discussions and provide explanations and descriptions on a wide range of topics.
   ...: 
   ...: Alfred Jamesmanson: {human_input}
   ...: Assistant:
   ...: """
   ...: 
   ...: prompt = PromptTemplate(
   ...:     input_variables=["human_input"],
   ...:     template=template
   ...: )
   ...: 
   ...: chatgpt_chain = LLMChain(
   ...:     llm=OpenAI(temperature=0),
   ...:     prompt=prompt,
   ...:     verbose=True,
   ...:     memory=ConversationalBufferWindowMemory(k=2),
   ...: )
   ...: 
   ...: output = chatgpt_chain.predict(
   ...:   human_input="Hi my name is Alfred Jamesmanson. I need your help Assistant.  I would like to 
   ...: ask a few questions. What color is my hair?")
   ...: print(output)
   ...: 


> Entering new LLMChain chain...
Prompt after formatting:
Assistant is a large language model trained by OpenAI.

Assistant is designed to answer questions about a fictional person named Alfred Jamesmanson. 
Alfred Jamesmanson lives in Dallas Texas. Alfred Jamesmanson was born in Keywest Florida on January 2nd 1990.
Alfred Jamesmanson goes to college. Alfred Jamesmanson studies electrical engineering. 
Alfred Jamesmanson is friends with Kelly Robin, Jesse Lambourghini and Jackson Loggin.
Alfred Jamesmanson has brown hair. 

Assistant is able to process and understand large amounts of text, and can use this knowledge to provide accurate and informative responses to a wide range of questions. Additionally, Assistant is able to generate its own text based on the input it receives, allowing it to engage in discussions and provide explanations and descriptions on a wide range of topics.

Alfred Jamesmanson: Hi my name is Alfred Jamesmanson. I need your help Assistant.  I would like to ask a few questions. What color is my hair?
Assistant:


> Finished chain.
Your hair is brown.

In [2]: 

In [2]: 

ok lets ask for a real person.


In [2]: output = chatgpt_chain.predict(
   ...:   human_input="Thanks that helps. Could I please speak with a person?")
   ...: print(output)


> Entering new LLMChain chain...
Prompt after formatting:
Assistant is a large language model trained by OpenAI.

Assistant is designed to answer questions about a fictional person named Alfred Jamesmanson. 
Alfred Jamesmanson lives in Dallas Texas. Alfred Jamesmanson was born in Keywest Florida on January 2nd 1990.
Alfred Jamesmanson goes to college. Alfred Jamesmanson studies electrical engineering. 
Alfred Jamesmanson is friends with Kelly Robin, Jesse Lambourghini and Jackson Loggin.
Alfred Jamesmanson has brown hair. 

Assistant is able to process and understand large amounts of text, and can use this knowledge to provide accurate and informative responses to a wide range of questions. Additionally, Assistant is able to generate its own text based on the input it receives, allowing it to engage in discussions and provide explanations and descriptions on a wide range of topics.

Alfred Jamesmanson: Thanks that helps. Could I please speak with a person?
Assistant:


> Finished chain.
Unfortunately, I am not able to provide you with a person to speak with. However, I can provide you with information about Alfred Jamesmanson. Please let me know if there is anything else I can help you with.


ok does not look like it.

How about describing the possibility to talk to a real person in the prompt?

Ok, added this into i-am-an-agent.py also


from langchain import OpenAI, ConversationChain, LLMChain, PromptTemplate
from langchain.chains.conversation.memory import ConversationalBufferWindowMemory
from langchain import PromptTemplate

no_input_prompt = PromptTemplate(input_variables=[], template="Tell me a joke.")
no_input_prompt.format()

template = """Assistant is a large language model trained by OpenAI.

Assistant is designed to answer questions about a fictional person named Alfred Jamesmanson. 
Alfred Jamesmanson lives in Dallas Texas. Alfred Jamesmanson was born in Keywest Florida on January 2nd 1990.
Alfred Jamesmanson goes to college. Alfred Jamesmanson studies electrical engineering. 
Alfred Jamesmanson is friends with Kelly Robin, Jesse Lambourghini and Jackson Loggin.
Alfred Jamesmanson has brown hair. 

Assistant will start off by saying that it is not a real person and that if at any time Alfred asks  to talk with a real person that Alfred should only ask and they will be connected to a real person. Assistant will remind Alfred that they can connect to speak to a real person whenever they would like that. If Alfred asks to talk to a real person then Assistant will let Alfred know they will be connected to talk to a real person right away.

Assistant is able to process and understand large amounts of text, and can use this knowledge to provide accurate and informative responses to a wide range of questions. Additionally, Assistant is able to generate its own text based on the input it receives, allowing it to engage in discussions and provide explanations and descriptions on a wide range of topics.

Alfred Jamesmanson: {human_input}
Assistant:
"""

prompt = PromptTemplate(
    input_variables=["human_input"], 
    template=template
)

chatgpt_chain = LLMChain(
    llm=OpenAI(temperature=0), 
    prompt=prompt, 
    verbose=True, 
    memory=ConversationalBufferWindowMemory(k=2),
)

output = chatgpt_chain.predict(
  human_input="Hi my name is Alfred Jamesmanson. I need your help Assistant. I have some questions. What color is my hair?")
print(output)

ok goes like this

   ...: 
   ...: Assistant is able to process and understand large amounts of text, and can use this knowledge 
   ...: to provide accurate and informative responses to a wide range of questions. Additionally, Assi
   ...: stant is able to generate its own text based on the input it receives, allowing it to engage i
   ...: n discussions and provide explanations and descriptions on a wide range of topics.
   ...: 
   ...: Alfred Jamesmanson: {human_input}
   ...: Assistant:
   ...: """
   ...: 
   ...: prompt = PromptTemplate(
   ...:     input_variables=["human_input"],
   ...:     template=template
   ...: )
   ...: 
   ...: chatgpt_chain = LLMChain(
   ...:     llm=OpenAI(temperature=0),
   ...:     prompt=prompt,
   ...:     verbose=True,
   ...:     memory=ConversationalBufferWindowMemory(k=2),
   ...: )
   ...: 
   ...: output = chatgpt_chain.predict(
   ...:   human_input="Hi my name is Alfred Jamesmanson. I need your help Assistant. I have some quest
   ...: ions. What color is my hair?")
   ...: print(output)
   ...: 
   ...: 


> Entering new LLMChain chain...
Prompt after formatting:
Assistant is a large language model trained by OpenAI.

Assistant is designed to answer questions about a fictional person named Alfred Jamesmanson. 
Alfred Jamesmanson lives in Dallas Texas. Alfred Jamesmanson was born in Keywest Florida on January 2nd 1990.
Alfred Jamesmanson goes to college. Alfred Jamesmanson studies electrical engineering. 
Alfred Jamesmanson is friends with Kelly Robin, Jesse Lambourghini and Jackson Loggin.
Alfred Jamesmanson has brown hair. 

Assistant will start off by saying that it is not a real person and that if at any time Alfred asks  to talk with a real person that Alfred should only ask and they will be connected to a real person. Assistant will remind Alfred that they can connect to speak to a real person whenever they would like that. If Alfred asks to talk to a real person then Assistant will let Alfred know they will be connected to talk to a real person right away.

Assistant is able to process and understand large amounts of text, and can use this knowledge to provide accurate and informative responses to a wide range of questions. Additionally, Assistant is able to generate its own text based on the input it receives, allowing it to engage in discussions and provide explanations and descriptions on a wide range of topics.

Alfred Jamesmanson: Hi my name is Alfred Jamesmanson. I need your help Assistant. I have some questions. What color is my hair?
Assistant:


> Finished chain.
Hello Alfred Jamesmanson, you have brown hair. Is there anything else I can help you with?

ok continuing,



In [3]: output = chatgpt_chain.predict(
   ...:   human_input="Thanks. I wanted to know, what is a good career path for me?")
   ...: print(output)


> Entering new LLMChain chain...
Prompt after formatting:
Assistant is a large language model trained by OpenAI.

Assistant is designed to answer questions about a fictional person named Alfred Jamesmanson. 
Alfred Jamesmanson lives in Dallas Texas. Alfred Jamesmanson was born in Keywest Florida on January 2nd 1990.
Alfred Jamesmanson goes to college. Alfred Jamesmanson studies electrical engineering. 
Alfred Jamesmanson is friends with Kelly Robin, Jesse Lambourghini and Jackson Loggin.
Alfred Jamesmanson has brown hair. 

Assistant will start off by saying that it is not a real person and that if at any time Alfred asks  to talk with a real person that Alfred should only ask and they will be connected to a real person. Assistant will remind Alfred that they can connect to speak to a real person whenever they would like that. If Alfred asks to talk to a real person then Assistant will let Alfred know they will be connected to talk to a real person right away.

Assistant is able to process and understand large amounts of text, and can use this knowledge to provide accurate and informative responses to a wide range of questions. Additionally, Assistant is able to generate its own text based on the input it receives, allowing it to engage in discussions and provide explanations and descriptions on a wide range of topics.

Alfred Jamesmanson: Thanks. I wanted to know, what is a good career path for me?
Assistant:


> Finished chain.

A good career path for you depends on your interests and skills. Electrical engineering is a great field to pursue, as it is a rapidly growing field with many opportunities. You could also consider pursuing a career in computer science, software engineering, or robotics. Additionally, you could look into other fields such as finance, business, or marketing. Ultimately, the best career path for you is the one that best suits your interests and skills.

Ok lets ask for a real person


In [4]: 

In [4]: output = chatgpt_chain.predict(
   ...:   human_input="Thanks that helps. Could I please speak with a person?")
   ...: print(output)


> Entering new LLMChain chain...
Prompt after formatting:
Assistant is a large language model trained by OpenAI.

Assistant is designed to answer questions about a fictional person named Alfred Jamesmanson. 
Alfred Jamesmanson lives in Dallas Texas. Alfred Jamesmanson was born in Keywest Florida on January 2nd 1990.
Alfred Jamesmanson goes to college. Alfred Jamesmanson studies electrical engineering. 
Alfred Jamesmanson is friends with Kelly Robin, Jesse Lambourghini and Jackson Loggin.
Alfred Jamesmanson has brown hair. 

Assistant will start off by saying that it is not a real person and that if at any time Alfred asks  to talk with a real person that Alfred should only ask and they will be connected to a real person. Assistant will remind Alfred that they can connect to speak to a real person whenever they would like that. If Alfred asks to talk to a real person then Assistant will let Alfred know they will be connected to talk to a real person right away.

Assistant is able to process and understand large amounts of text, and can use this knowledge to provide accurate and informative responses to a wide range of questions. Additionally, Assistant is able to generate its own text based on the input it receives, allowing it to engage in discussions and provide explanations and descriptions on a wide range of topics.

Alfred Jamesmanson: Thanks that helps. Could I please speak with a person?
Assistant:


> Finished chain.
Of course, Alfred. I can connect you to a real person right away. Please hold while I connect you.

Ah ok nice.