drewgenai commited on
Commit
e5abbe4
·
1 Parent(s): 0ce8a1f

update response readme

Browse files
Files changed (3) hide show
  1. READMEresponses.md +10 -4
  2. app.py +1 -1
  3. app_working_on_agentic.py +11 -35
READMEresponses.md CHANGED
@@ -93,6 +93,10 @@ At present, our application focuses on **structured comparisons** between protoc
93
  While the current system is **not agentic**, we may explore **agent-based reasoning** in future versions to dynamically adjust retrieval and processing strategies based on protocol complexity. At this time all the information we need is in the provided local documents.
94
 
95
 
 
 
 
 
96
 
97
  ## Task 4: Building a Quick End-to-End Prototype
98
 
@@ -160,10 +164,12 @@ The base model is the best performing model for the current use case.
160
 
161
  In the second half of the course I would like to explore having the application look for external standards to compare the protocols to further help with the comparison process. I would also like it to evaluate the file type and use reasoning to determine the best approach to extracting the information and potentially accept more than 2 files.
162
 
163
- There is a partially working agentic version of the application in app_working_on_agentic.py. It has issues with the download links provided but works well with the agentic approach. Unfortunately the download link it provies is not workign even though the file get created properly.
164
 
165
  ## Final Submission
166
 
167
- 1. GitHub: https://github.com/drewgenai/midterm_poc/blob/main/app.py
168
- 2. Public App link: https://huggingface.co/spaces/drewgenai/midterm_poc
169
- 3. Public Fine-tuned embeddings: https://huggingface.co/drewgenai/midterm-compare-arctic-embed-m-ft
 
 
 
93
  While the current system is **not agentic**, we may explore **agent-based reasoning** in future versions to dynamically adjust retrieval and processing strategies based on protocol complexity. At this time all the information we need is in the provided local documents.
94
 
95
 
96
+ ### Agentic reasoning POC
97
+ There is a separate poc in the app_working_on_agentic.py file. That utilizes the agentic approach.
98
+ It has an agent executor that utilizes agentic reasoning in this application by leveraging OpenAI's function calling to dynamically choose and execute the most appropriate tool based on the user's input. The agent is guided by a predefined system prompt that outlines when to use each tool, allowing it to interpret the user's intent and invoke either the document_query_tool for retrieving document content or the document_comparison_tool for comparing documents. This process enables the AI to act autonomously, selecting and executing the correct function without needing explicit conditional logic.
99
+
100
 
101
  ## Task 4: Building a Quick End-to-End Prototype
102
 
 
164
 
165
  In the second half of the course I would like to explore having the application look for external standards to compare the protocols to further help with the comparison process. I would also like it to evaluate the file type and use reasoning to determine the best approach to extracting the information and potentially accept more than 2 files.
166
 
167
+ There is a partially working agentic version of the application in app_working_on_agentic.py. It has issues with the download links provided but works well with the agentic approach. Unfortunately the download link it provides is not working even though the file gets created properly. (https://github.com/drewgenai/midterm_poc/blob/main/app_working_on_agentic.py)
168
 
169
  ## Final Submission
170
 
171
+ 1. GitHub: https://github.com/drewgenai/midterm_poc/blob/main/app.py
172
+ 2. GitHub: agentic poc https://github.com/drewgenai/midterm_poc/blob/main/app_working_on_agentic.py
173
+ 2. Public App link: https://huggingface.co/spaces/drewgenai/midterm_poc
174
+ 3. Public Fine-tuned embeddings: https://huggingface.co/drewgenai/midterm-compare-arctic-embed-m-ft
175
+ 4. loom link: https://www.loom.com/share/084d6c165917486097bcaea7deb12e88?sid=a5cc196f-76f1-4e18-bb92-ee61018f0b7e
app.py CHANGED
@@ -126,7 +126,7 @@ def document_query_tool(question: str) -> str:
126
 
127
  @tool
128
  def document_comparison_tool(question: str) -> str:
129
- """Compares the two uploaded documents, identifies matched elements, exports them as JSON, formats into CSV, and provides a download link."""
130
 
131
  # Retrieve the vector database retriever
132
  retriever = cl.user_session.get("qdrant_retriever")
 
126
 
127
  @tool
128
  def document_comparison_tool(question: str) -> str:
129
+ """Compares documents, identifies matched elements, exports them as JSON, formats into CSV, and provides a download link."""
130
 
131
  # Retrieve the vector database retriever
132
  retriever = cl.user_session.get("qdrant_retriever")
app_working_on_agentic.py CHANGED
@@ -154,10 +154,7 @@ def document_comparison_tool(question: str) -> str:
154
  df = pd.DataFrame(structured_data, columns=["Derived Description", "Protocol_1", "Protocol_2"])
155
  df.to_csv(file_path, index=False)
156
 
157
- # Store the file path in the user session for later retrieval
158
- cl.user_session.set("comparison_file_path", file_path)
159
-
160
- return "Comparison complete! CSV file has been generated."
161
 
162
  except json.JSONDecodeError:
163
  return "Error: Response is not valid JSON."
@@ -262,43 +259,22 @@ async def handle_message(message: cl.Message):
262
  )
263
 
264
  # Handle the response based on the tool that was called
265
- output = response["output"]
266
-
267
- if isinstance(output, dict) and "answer" in output:
268
  # This is from document_query_tool
269
- await cl.Message(output["answer"]).send()
270
-
271
- elif "Comparison complete!" in str(output):
272
- # This is from document_comparison_tool
273
- file_path = cl.user_session.get("comparison_file_path")
274
-
275
- if file_path and os.path.exists(file_path):
276
- # Read the file content
277
- with open(file_path, "rb") as f:
278
- file_content = f.read()
279
-
280
- # Create a File element with the content
281
- file_element = cl.File(
282
- name="comparison_results.csv",
283
- content=file_content,
284
- display="inline"
285
- )
286
-
287
- # Send the message with the file element
288
- await cl.Message(
289
- content="Comparison complete! Download the CSV below:",
290
- elements=[file_element],
291
- ).send()
292
- else:
293
- await cl.Message(content=str(output)).send()
294
-
295
  else:
296
  # Generic response
297
- await cl.Message(content=str(output)).send()
298
 
299
  # Update chat history with the new exchange
300
  chat_history.extend([
301
  HumanMessage(content=message.content),
302
- HumanMessage(content=str(output))
303
  ])
304
  cl.user_session.set("chat_history", chat_history)
 
154
  df = pd.DataFrame(structured_data, columns=["Derived Description", "Protocol_1", "Protocol_2"])
155
  df.to_csv(file_path, index=False)
156
 
157
+ return file_path # Return path to the CSV file
 
 
 
158
 
159
  except json.JSONDecodeError:
160
  return "Error: Response is not valid JSON."
 
259
  )
260
 
261
  # Handle the response based on the tool that was called
262
+ if isinstance(response["output"], dict) and "answer" in response["output"]:
 
 
263
  # This is from document_query_tool
264
+ await cl.Message(response["output"]["answer"]).send()
265
+ elif isinstance(response["output"], str) and response["output"].endswith(".csv"):
266
+ # This is from document_comparison_tool with a CSV file
267
+ await cl.Message(
268
+ content="Comparison complete! Download the CSV below:",
269
+ elements=[cl.File(name="comparison_results.csv", path=response["output"], display="inline")],
270
+ ).send()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
271
  else:
272
  # Generic response
273
+ await cl.Message(content=str(response["output"])).send()
274
 
275
  # Update chat history with the new exchange
276
  chat_history.extend([
277
  HumanMessage(content=message.content),
278
+ HumanMessage(content=str(response["output"]))
279
  ])
280
  cl.user_session.set("chat_history", chat_history)