wt002 commited on
Commit
257f406
·
verified ·
1 Parent(s): 892f091

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +29 -5
agent.py CHANGED
@@ -137,15 +137,36 @@ with open("system_prompt.txt", "r", encoding="utf-8") as f:
137
  sys_msg = SystemMessage(content=system_prompt)
138
 
139
 
140
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  # -------------------------------
142
- # Step 2: Create Documents from Each JSON Object
143
  # -------------------------------
144
  docs = []
145
  for task in tasks:
146
  # Debugging: Print the keys of each task to ensure 'question' exists
147
  print(f"Keys in task: {task.keys()}")
148
-
149
  # Ensure the required field 'question' exists
150
  if 'question' not in task:
151
  print(f"Skipping task with missing 'question' field: {task}")
@@ -163,8 +184,9 @@ for task in tasks:
163
  docs.append(Document(page_content=content, metadata=task))
164
 
165
 
 
166
  # -------------------------------
167
- # Step 3: Set up HuggingFace Embeddings and FAISS VectorStore
168
  # -------------------------------
169
  # Initialize HuggingFace Embedding model
170
  embedding_model = HuggingFaceEmbeddings(model_name="sentence-transformers/all-mpnet-base-v2")
@@ -177,8 +199,10 @@ vector_store.save_local("faiss_index")
177
 
178
  #print("✅ FAISS index created and saved locally.")
179
 
 
 
180
  # -------------------------------
181
- # Step 4: Create Retriever Tool (for use in LangChain)
182
  # -------------------------------
183
  retriever = vector_store.as_retriever()
184
 
 
137
  sys_msg = SystemMessage(content=system_prompt)
138
 
139
 
140
+
141
+ # -------------------------------
142
+ # Step 2: Load the JSON file or tasks (Replace this part if you're loading tasks dynamically)
143
+ # -------------------------------
144
+ # Here we assume the tasks are already fetched from a URL or file.
145
+ # For now, using an example JSON array directly. Replace this with the actual loading logic.
146
+
147
+ tasks = [
148
+ {
149
+ "task_id": "8e867cd7-cff9-4e6c-867a-ff5ddc2550be",
150
+ "question": "How many studio albums were published by Mercedes Sosa between 2000 and 2009 (included)? You can use the latest 2022 version of English Wikipedia.",
151
+ "Level": "1",
152
+ "file_name": ""
153
+ },
154
+ {
155
+ "task_id": "a1e91b78-d3d8-4675-bb8d-62741b4b68a6",
156
+ "question": "In the video https://www.youtube.com/watch?v=L1vXCYZAYYM, what is the highest number of bird species to be on camera simultaneously?",
157
+ "Level": "1",
158
+ "file_name": ""
159
+ }
160
+ ]
161
+
162
  # -------------------------------
163
+ # Step 3: Create Documents from Each JSON Object
164
  # -------------------------------
165
  docs = []
166
  for task in tasks:
167
  # Debugging: Print the keys of each task to ensure 'question' exists
168
  print(f"Keys in task: {task.keys()}")
169
+
170
  # Ensure the required field 'question' exists
171
  if 'question' not in task:
172
  print(f"Skipping task with missing 'question' field: {task}")
 
184
  docs.append(Document(page_content=content, metadata=task))
185
 
186
 
187
+
188
  # -------------------------------
189
+ # Step 4: Set up HuggingFace Embeddings and FAISS VectorStore
190
  # -------------------------------
191
  # Initialize HuggingFace Embedding model
192
  embedding_model = HuggingFaceEmbeddings(model_name="sentence-transformers/all-mpnet-base-v2")
 
199
 
200
  #print("✅ FAISS index created and saved locally.")
201
 
202
+
203
+
204
  # -------------------------------
205
+ # Step 5: Create Retriever Tool (for use in LangChain)
206
  # -------------------------------
207
  retriever = vector_store.as_retriever()
208