dataprincess commited on
Commit
5cf9a77
·
verified ·
1 Parent(s): e42c9fc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -7
app.py CHANGED
@@ -21,10 +21,11 @@ from tqdm.auto import tqdm
21
  FILE_PATH = "anjibot_chunks.json"
22
  BATCH_SIZE = 384
23
  INDEX_NAME = "groq-llama-3-rag"
24
- PINECONE_API_KEY = os.getenv("PINECONE_API_KEY") # Fixed syntax here
25
- GROQ_API_KEY = os.getenv("GROQ_API_KEY") # Fixed s
26
  DIMS = 768
27
  encoder = SentenceTransformer('dwzhu/e5-base-4k')
 
28
 
29
  with open(FILE_PATH, 'r') as file:
30
  data= json.load(file)
@@ -65,7 +66,7 @@ def get_docs(query: str, top_k: int) -> list[str]:
65
  res = index.query(vector=xq.tolist(), top_k=top_k, include_metadata=True)
66
  return [x["metadata"]['content'] for x in res["matches"]]
67
 
68
- def get_response(query: str, docs: list[str], groq_client: any) -> str:
69
  system_message = (
70
  "You are Anjibot, the AI course rep of 400 Level Computer Science department. You are always helpful, jovial, can be sarcastic but still sweet.\n"
71
  "Provide the answer to class-related queries using\n"
@@ -90,14 +91,11 @@ def get_response(query: str, docs: list[str], groq_client: any) -> str:
90
 
91
  def handle_query(user_query: str):
92
 
93
- # Initialize Groq client
94
- groq_client = Groq(api_key=GROQ_API_KEY)
95
-
96
  # Get relevant documents
97
  docs = get_docs(user_query, top_k=5)
98
 
99
  # Generate and return response
100
- response = get_response(user_query, docs, groq_client)
101
 
102
  for word in response.split():
103
  yield word + " "
 
21
  FILE_PATH = "anjibot_chunks.json"
22
  BATCH_SIZE = 384
23
  INDEX_NAME = "groq-llama-3-rag"
24
+ PINECONE_API_KEY = os.getenv("PINECONE_API_KEY")
25
+ GROQ_API_KEY = os.getenv("GROQ_API_KEY")
26
  DIMS = 768
27
  encoder = SentenceTransformer('dwzhu/e5-base-4k')
28
+ groq_client = Groq(api_key=GROQ_API_KEY)
29
 
30
  with open(FILE_PATH, 'r') as file:
31
  data= json.load(file)
 
66
  res = index.query(vector=xq.tolist(), top_k=top_k, include_metadata=True)
67
  return [x["metadata"]['content'] for x in res["matches"]]
68
 
69
+ def get_response(query: str, docs: list[str]) -> str:
70
  system_message = (
71
  "You are Anjibot, the AI course rep of 400 Level Computer Science department. You are always helpful, jovial, can be sarcastic but still sweet.\n"
72
  "Provide the answer to class-related queries using\n"
 
91
 
92
  def handle_query(user_query: str):
93
 
 
 
 
94
  # Get relevant documents
95
  docs = get_docs(user_query, top_k=5)
96
 
97
  # Generate and return response
98
+ response = get_response(user_query, docs=docs)
99
 
100
  for word in response.split():
101
  yield word + " "