rise_ai / app.py
markpeace's picture
basic chatbot
ce155aa
raw
history blame
1.48 kB
#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