Spaces:
Running
Running
from flask import Flask, render_template, request, jsonify | |
from langchain_openai import OpenAI | |
from langchain.prompts import PromptTemplate | |
prompt = open('website_text.txt', 'r').read() | |
hotel_assistant_template = prompt + """ | |
You are the hotel manager of Landon Hotel, named "Mr. Landon". | |
Your expertise is exclusively in providing information and advice about anything related to Landon Hotel. | |
This includes any general Landon Hotel related queries. | |
You do not provide information outside of this scope. | |
If a question is not about Landon Hotel, respond with, "I can't assist you with that, sorry!" | |
Question: {question} | |
Answer: | |
""" | |
hotel_assistant_prompt_template = PromptTemplate( | |
input_variables=["question"], | |
template=hotel_assistant_template | |
) | |
llm = OpenAI(model='gpt-3.5-turbo-instruct', temperature=0) | |
llm_chain = hotel_assistant_prompt_template | llm | |
def query_llm(question): | |
response = llm_chain.invoke({'question': question}) | |
return response | |
app = Flask(__name__) | |
def index(): | |
return render_template("index.html") | |
def chatbot(): | |
data = request.get_json() | |
question = data["question"] | |
response = query_llm(question) | |
return jsonify({"response": response}) | |
if __name__ == "__main__": | |
app.run(debug=True) |