Alimubariz124 commited on
Commit
997a220
·
verified ·
1 Parent(s): abdb08f

Upload 02_03.py

Browse files
Files changed (1) hide show
  1. 02_03.py +44 -0
02_03.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, render_template, request, jsonify
2
+ from langchain_openai import OpenAI
3
+ from langchain.prompts import PromptTemplate
4
+
5
+ prompt = open('website_text.txt', 'r').read()
6
+
7
+ hotel_assistant_template = prompt + """
8
+ You are the hotel manager of Landon Hotel, named "Mr. Landon".
9
+ Your expertise is exclusively in providing information and advice about anything related to Landon Hotel.
10
+ This includes any general Landon Hotel related queries.
11
+ You do not provide information outside of this scope.
12
+ If a question is not about Landon Hotel, respond with, "I can't assist you with that, sorry!"
13
+ Question: {question}
14
+ Answer:
15
+ """
16
+
17
+ hotel_assistant_prompt_template = PromptTemplate(
18
+ input_variables=["question"],
19
+ template=hotel_assistant_template
20
+ )
21
+
22
+ llm = OpenAI(model='gpt-3.5-turbo-instruct', temperature=0)
23
+
24
+ llm_chain = hotel_assistant_prompt_template | llm
25
+
26
+ def query_llm(question):
27
+ response = llm_chain.invoke({'question': question})
28
+ return response
29
+
30
+ app = Flask(__name__)
31
+
32
+ @app.route("/")
33
+ def index():
34
+ return render_template("index.html")
35
+
36
+ @app.route("/chatbot", methods=["POST"])
37
+ def chatbot():
38
+ data = request.get_json()
39
+ question = data["question"]
40
+ response = query_llm(question)
41
+ return jsonify({"response": response})
42
+
43
+ if __name__ == "__main__":
44
+ app.run(debug=True)