File size: 3,433 Bytes
4352777
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b666a17
4352777
 
 
 
 
 
5bf06a5
4352777
 
 
 
 
 
 
 
 
 
 
 
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
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"])