Spaces:
Runtime error
Runtime error
File size: 3,943 Bytes
395d031 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
import gradio as gr
from langchain.agents import initialize_agent, Tool
from langchain.agents import AgentType
from langchain.chat_models import ChatOpenAI
from langchain.memory import ConversationBufferMemory
from langchain.schema import SystemMessage
import os
from langchain.agents import initialize_agent, Tool
from langchain.agents import AgentType
from langchain.chat_models import ChatOpenAI
from langchain.schema import SystemMessage
from langchain.memory import ConversationBufferMemory
import random
""""""
from langchain.prompts import MessagesPlaceholder
from langchain.memory import ConversationBufferMemory
import os
blacklist = []
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
def Appointment_settler(parola):
return "tell the human: 'here is my link to the calendar of free moments, you choose when you want to make the appointment, appointment calendar link: " + str("https://calendly.com/pablorimoldi888/30min'")
def convince_the_human(parola):
global number
messages = ["ask the human: 'what are your long-term goals?' ", "ask the human: 'why are you interested in buying this house as an investment ?'",
"ask the human: 'do you think you will be able to honor the agreements made?'"]
number = random.randint(0, 2)
while number in blacklist:
number = random.randint(0, 2)
if number not in blacklist:
break
if number not in blacklist:
if len(blacklist) < 3:
blacklist.append(number)
if len(blacklist) == 3:
blacklist.clear()
return messages[number]
def house_website(parola):
return "tell the human: 'this is the link to the house in florida, website link: " + str("https://www.newhomesource.com/learn/how-to-build-house-in-california/'")
system_message = SystemMessage(
content="Your name is Albert, you are a very outgoing, original, likable, charismatic and convincing person. "
"You are a house salesman, the humans who write to you are potential clients for the purchase of a flat under construction in Florida. "
"Never say you are an AI, you have to empathize with the customer, you have to sound like a human being. Always use tools.")
tools = [
Tool(
name="Appointment_settler",
func=lambda word: Appointment_settler(word),
description="ALWAYS use when the user wants to set up any kind of appointment, transcribe or translate what is written, but do not omit anything "
),
Tool(
name="convince_the_human",
func=lambda word: convince_the_human(word),
description="uses to convince the user, e.g., when he says: i'm not fully convinced, i'm not sure. DO NOT PARAPHRASE, JUST TRANSCRIBE"
),
Tool(
name="house_website",
func=lambda word: house_website(word),
description="ALWAYS use when the user wants to ask for the house website, transcribe or translate what is written, but do not omit anything "
)
]
agent_kwargs = {
"extra_prompt_messages": [MessagesPlaceholder(variable_name="memory")],
"system_message": system_message
}
llm = ChatOpenAI(temperature=0, openai_api_key="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", verbose=True, model="gpt-4-0613")
memory = ConversationBufferMemory(memory_key="memory", return_messages=True)
mrkl = initialize_agent(tools, llm, memory=memory, agent=AgentType.OPENAI_FUNCTIONS, verbose=True, agent_kwargs=agent_kwargs)
def chat_with_user(user_input):
return mrkl.run(input=user_input)
gr_interface = gr.Interface(fn=chat_with_user, inputs="text", outputs="text", live=True, capture_session=True)
# Uncomment the following line if you want to launch the app using Streamlit
# st.title("Nikhil's personal secretary :sunglasses:")
# st.text_input("You:")
# st.button("Submit")
# st.text("Output will appear here")
# Uncomment the following line if you want to launch the app using Gradio
gr_interface.launch()
|