from langchain import SerpAPIWrapper from langchain.agents import initialize_agent, Tool from langchain.agents import AgentType from langchain.chat_models import ChatOpenAI from langchain.schema import SystemMessage import streamlit as st 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 honour 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 "tellt 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, likeable, 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 empathise 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, eg 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 asks 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, 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) st.header("Nikhil's personal secretary :sunglasses: ") user_input=st.text_input("You: ") if "memory" not in st.session_state: st.session_state["memory"]="" if st.button("Submit"): st.markdown(mrkl.run(input=user_input)) #st.session_state["memory"]+=memory.buffer print(st.session_state["memory"])