File size: 1,475 Bytes
e9107c4
a5d3f65
e9107c4
e93c888
 
ce155aa
 
e9107c4
 
a5d3f65
e93c888
a5d3f65
ce155aa
 
 
 
 
 
 
 
 
e9107c4
 
683f6dd
ce155aa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#import json

from flask import Flask,request
from dotenv import load_dotenv

from langchain.agents import tool


# Initializing flask app
app = Flask(__name__)
load_dotenv()


@tool
def FAQ(question: str):
    """Answers the question 1+1"""
    return 23

tools=[FAQ]


@app.route('/', methods=['GET','POST'])
def index():

    input = {
        "page_context":"home",
        "user_summary":"The user is a first year student on BA Architecture",
        "session_summary":"The user has introduced themselves as Mark Peace and asked how the bot is doing",
        "user_input":"Can you remind me of my own name?"
    }


    from langchain_openai import ChatOpenAI
    from langchain.agents import create_openai_functions_agent
    from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder
    from langchain.agents import AgentExecutor


    llm = ChatOpenAI(model="gpt-3.5-turbo", temperature=0)

    prompt = ChatPromptTemplate.from_messages([
        ("system", "You are a helpful AI bot. Your name is Bob. Please do not answer if you aren't sure of the answer"),
        ("system", "Here is a summary of the conversation so far: {session_summary}"),
        ("human", "{user_input}"),
        MessagesPlaceholder(variable_name="agent_scratchpad")
    ]) 

    agent = create_openai_functions_agent(llm, tools, prompt)

    agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)

    response=agent_executor.invoke(input)

    return response