Ritesh-hf commited on
Commit
d2715ff
1 Parent(s): 773d1e7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -19
app.py CHANGED
@@ -1,3 +1,9 @@
 
 
 
 
 
 
1
  import os
2
  from dotenv import load_dotenv
3
  import asyncio
@@ -15,6 +21,8 @@ from pinecone_text.sparse import BM25Encoder
15
  from langchain_huggingface import HuggingFaceEmbeddings
16
  from langchain_community.retrievers import PineconeHybridSearchRetriever
17
  from langchain_groq import ChatGroq
 
 
18
 
19
  # Load environment variables
20
  load_dotenv(".env")
@@ -32,7 +40,7 @@ os.environ["TOKENIZERS_PARALLELISM"] = 'true'
32
  # Initialize Flask app and SocketIO with CORS
33
  app = Flask(__name__)
34
  CORS(app)
35
- socketio = SocketIO(app, cors_allowed_origins="*")
36
  app.config['SESSION_COOKIE_SECURE'] = True # Use HTTPS
37
  app.config['SESSION_COOKIE_HTTPONLY'] = True
38
  app.config['SESSION_COOKIE_SAMESITE'] = 'Lax'
@@ -56,27 +64,10 @@ def initialize_pinecone(index_name: str):
56
  pinecone_index = initialize_pinecone("traveler-demo-website-vectorstore")
57
  bm25 = BM25Encoder().load("./bm25_traveler_website.json")
58
 
59
- ### This is for UAE Legislation Website
60
- # pinecone_index = initialize_pinecone("uae-legislation-site-data")
61
- # bm25 = BM25Encoder().load("./bm25_uae_legislation_data.json")
62
-
63
-
64
- ### This is for u.ae Website
65
- # pinecone_index = initialize_pinecone("vector-store-index")
66
- # bm25 = BM25Encoder().load("./bm25_u.ae.json")
67
-
68
-
69
- # #### This is for UAE Economic Department Website
70
- # pinecone_index = initialize_pinecone("uae-department-of-economics-site-data")
71
- # bm25 = BM25Encoder().load("./bm25_uae_department_of_economics_data.json")
72
-
73
-
74
 
75
  ##################################################
76
  ##################################################
77
 
78
- old_embed_model = HuggingFaceEmbeddings(model_name="sentence-transformers/all-mpnet-base-v2")
79
-
80
  # Initialize models and retriever
81
  embed_model = HuggingFaceEmbeddings(model_name="Alibaba-NLP/gte-large-en-v1.5", model_kwargs={"trust_remote_code":True})
82
  retriever = PineconeHybridSearchRetriever(
@@ -88,7 +79,8 @@ retriever = PineconeHybridSearchRetriever(
88
  )
89
 
90
  # Initialize LLM
91
- llm = ChatGroq(model="llama-3.1-70b-versatile", temperature=0, max_tokens=1024, max_retries=2)
 
92
 
93
  # Contextualization prompt and retriever
94
  contextualize_q_system_prompt = """Given a chat history and the latest user question \
 
1
+ from gevent import monkey
2
+ monkey.patch_all()
3
+
4
+ import nltk
5
+ nltk.download('punkt_tab')
6
+
7
  import os
8
  from dotenv import load_dotenv
9
  import asyncio
 
21
  from langchain_huggingface import HuggingFaceEmbeddings
22
  from langchain_community.retrievers import PineconeHybridSearchRetriever
23
  from langchain_groq import ChatGroq
24
+ from langchain.retrievers.document_compressors import FlashrankRerank
25
+ from langchain_community.chat_models import ChatPerplexity
26
 
27
  # Load environment variables
28
  load_dotenv(".env")
 
40
  # Initialize Flask app and SocketIO with CORS
41
  app = Flask(__name__)
42
  CORS(app)
43
+ socketio = SocketIO(app, async_mode='gevent', cors_allowed_origins="*")
44
  app.config['SESSION_COOKIE_SECURE'] = True # Use HTTPS
45
  app.config['SESSION_COOKIE_HTTPONLY'] = True
46
  app.config['SESSION_COOKIE_SAMESITE'] = 'Lax'
 
64
  pinecone_index = initialize_pinecone("traveler-demo-website-vectorstore")
65
  bm25 = BM25Encoder().load("./bm25_traveler_website.json")
66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
 
68
  ##################################################
69
  ##################################################
70
 
 
 
71
  # Initialize models and retriever
72
  embed_model = HuggingFaceEmbeddings(model_name="Alibaba-NLP/gte-large-en-v1.5", model_kwargs={"trust_remote_code":True})
73
  retriever = PineconeHybridSearchRetriever(
 
79
  )
80
 
81
  # Initialize LLM
82
+ # llm = ChatGroq(model="llama-3.1-70b-versatile", temperature=0, max_tokens=1024, max_retries=2)
83
+ llm = ChatPerplexity(temperature=0, pplx_api_key=GROQ_API_KEY, model="llama-3.1-sonar-large-128k-online", max_tokens=1024, max_retries=2)
84
 
85
  # Contextualization prompt and retriever
86
  contextualize_q_system_prompt = """Given a chat history and the latest user question \