muhammadhasnain100 commited on
Commit
5ed2fef
1 Parent(s): 19a8026

Update chatbot.py

Browse files
Files changed (1) hide show
  1. chatbot.py +8 -10
chatbot.py CHANGED
@@ -6,16 +6,13 @@ from deep_translator import GoogleTranslator
6
  from langchain_community.document_loaders.csv_loader import CSVLoader
7
  from langchain_community.vectorstores import FAISS
8
  class Comsatsbot:
9
- def __init__(self, hf, llm, api_key, db_client, paths, db_name="chat_database", collection_name="chats",
10
- index_path='faiss_kb'):
11
  self.llm = llm
12
  self.client = Groq(api_key=api_key)
13
 
14
  # Initialize memory buffer and MongoDB connection
15
- self.memory = ConversationSummaryBufferMemory(llm=self.llm, max_token_limit=4000)
16
- self.db_client = db_client
17
- self.db = self.db_client[db_name]
18
- self.chats_collection = self.db[collection_name]
19
  self.index_path = index_path
20
  self.hf = hf
21
  self.faiss_index = None
@@ -63,13 +60,13 @@ class Comsatsbot:
63
  def load_chat(self, chat_id):
64
  chat_record = self.chats_collection.find_one({"_id": chat_id})
65
  if not chat_record:
66
- raise ValueError(f"Chat ID {chat_id} does not exist.")
67
  return chat_record.get('history', [])
68
 
69
  def new_chat(self, chat_id):
70
  # Check if chat ID already exists
71
  if self.chats_collection.find_one({"_id": chat_id}):
72
- raise ValueError(f"Chat ID {chat_id} exist already.")
73
 
74
  # Create a new chat record if it doesn't exist
75
  self.create_chat_record(chat_id)
@@ -78,7 +75,7 @@ class Comsatsbot:
78
  def delete_chat(self, chat_id):
79
  # Check if the chat ID exists
80
  if not self.chats_collection.find_one({"_id": chat_id}):
81
- raise ValueError(f"Chat ID {chat_id} does not exist.")
82
 
83
  # Delete the chat if it exists
84
  self.chats_collection.delete_one({"_id": chat_id})
@@ -91,7 +88,8 @@ class Comsatsbot:
91
  "role": "user",
92
  "content": f'''
93
 
94
- You are a conversational and helpfull agent to help the comsats university attock campus students, and your task is to provide concise and direct answers to the questions asked.
 
95
  Please follow these guidelines when answering:
96
  DOnt need to explain and repeat the prompt in response.
97
 
 
6
  from langchain_community.document_loaders.csv_loader import CSVLoader
7
  from langchain_community.vectorstores import FAISS
8
  class Comsatsbot:
9
+ def __init__(self, hf, llm, api_key, chats_collection, paths, index_path='faiss_kb'):
 
10
  self.llm = llm
11
  self.client = Groq(api_key=api_key)
12
 
13
  # Initialize memory buffer and MongoDB connection
14
+ self.memory = ConversationSummaryBufferMemory(llm=self.llm, max_token_limit=3000)
15
+ self.chats_collection = chats_collection
 
 
16
  self.index_path = index_path
17
  self.hf = hf
18
  self.faiss_index = None
 
60
  def load_chat(self, chat_id):
61
  chat_record = self.chats_collection.find_one({"_id": chat_id})
62
  if not chat_record:
63
+ raise KeyError(f"Chat ID {chat_id} does not exist.")
64
  return chat_record.get('history', [])
65
 
66
  def new_chat(self, chat_id):
67
  # Check if chat ID already exists
68
  if self.chats_collection.find_one({"_id": chat_id}):
69
+ raise KeyError(f"Chat ID {chat_id} exist already.")
70
 
71
  # Create a new chat record if it doesn't exist
72
  self.create_chat_record(chat_id)
 
75
  def delete_chat(self, chat_id):
76
  # Check if the chat ID exists
77
  if not self.chats_collection.find_one({"_id": chat_id}):
78
+ raise KeyError(f"Chat ID {chat_id} does not exist.")
79
 
80
  # Delete the chat if it exists
81
  self.chats_collection.delete_one({"_id": chat_id})
 
88
  "role": "user",
89
  "content": f'''
90
 
91
+ You are a conversational and helpfull agent to help the comsats university attock campus students, and your task is to provide concise and direct answers to the questions asked. IF question is about to urdu and then kindly please answer in correct and to the point answer.
92
+ Dont need to explain irrelevant thinga nd use the correct urdu in response.
93
  Please follow these guidelines when answering:
94
  DOnt need to explain and repeat the prompt in response.
95