Shreyas094 commited on
Commit
5ba029b
·
verified ·
1 Parent(s): 06e89a5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -1
app.py CHANGED
@@ -315,7 +315,6 @@ def respond(message, history, model, temperature, num_calls, use_web_search, sel
315
  logging.info(f"User Query: {message}")
316
  logging.info(f"Model Used: {model}")
317
  logging.info(f"Search Type: {'Web Search' if use_web_search else 'PDF Search'}")
318
-
319
  logging.info(f"Selected Documents: {selected_docs}")
320
 
321
  try:
@@ -336,12 +335,14 @@ def respond(message, history, model, temperature, num_calls, use_web_search, sel
336
  relevant_docs = [doc for doc in all_relevant_docs if doc.metadata["source"] in selected_docs]
337
 
338
  if not relevant_docs:
 
339
  yield "No relevant information found in the selected documents. Please try selecting different documents or rephrasing your query."
340
  return
341
 
342
  context_str = "\n".join([doc.page_content for doc in relevant_docs])
343
  else:
344
  context_str = "No documents available."
 
345
  yield "No documents available. Please upload PDF documents to answer questions."
346
  return
347
 
@@ -353,6 +354,7 @@ def respond(message, history, model, temperature, num_calls, use_web_search, sel
353
  yield partial_response
354
  elif model in ["gpt-4o-mini", "claude-3-haiku", "llama-3.1-70b", "mixtral-8x7b"]:
355
  # Use DuckDuckGo Chat API
 
356
  response = chat(message, model=model, timeout=30)
357
  yield response
358
  else:
@@ -381,6 +383,8 @@ def chat(self, keywords: str, model: str = "gpt-4o-mini", timeout: int = 30) ->
381
  Returns:
382
  str: The response from the AI.
383
  """
 
 
384
  if model == "gpt-4o-mini":
385
  url = "https://api.duckduckgo.com/api/d2a/v1/chat/gpt-4o-mini"
386
  elif model == "claude-3-haiku":
@@ -399,8 +403,11 @@ def chat(self, keywords: str, model: str = "gpt-4o-mini", timeout: int = 30) ->
399
  }
400
 
401
  try:
 
402
  response = requests.post(url, json=payload, headers=headers, timeout=timeout)
 
403
  response.raise_for_status()
 
404
  return response.json()["response"]
405
  except requests.exceptions.RequestException as e:
406
  logging.error(f"Error in DuckDuckGo chat: {str(e)}")
 
315
  logging.info(f"User Query: {message}")
316
  logging.info(f"Model Used: {model}")
317
  logging.info(f"Search Type: {'Web Search' if use_web_search else 'PDF Search'}")
 
318
  logging.info(f"Selected Documents: {selected_docs}")
319
 
320
  try:
 
335
  relevant_docs = [doc for doc in all_relevant_docs if doc.metadata["source"] in selected_docs]
336
 
337
  if not relevant_docs:
338
+ logging.info("No relevant information found in the selected documents.")
339
  yield "No relevant information found in the selected documents. Please try selecting different documents or rephrasing your query."
340
  return
341
 
342
  context_str = "\n".join([doc.page_content for doc in relevant_docs])
343
  else:
344
  context_str = "No documents available."
345
+ logging.info("No documents available.")
346
  yield "No documents available. Please upload PDF documents to answer questions."
347
  return
348
 
 
354
  yield partial_response
355
  elif model in ["gpt-4o-mini", "claude-3-haiku", "llama-3.1-70b", "mixtral-8x7b"]:
356
  # Use DuckDuckGo Chat API
357
+ logging.info(f"Calling DuckDuckGo Chat API with model: {model}")
358
  response = chat(message, model=model, timeout=30)
359
  yield response
360
  else:
 
383
  Returns:
384
  str: The response from the AI.
385
  """
386
+ logging.info(f"Calling DuckDuckGo Chat API with model: {model}")
387
+
388
  if model == "gpt-4o-mini":
389
  url = "https://api.duckduckgo.com/api/d2a/v1/chat/gpt-4o-mini"
390
  elif model == "claude-3-haiku":
 
403
  }
404
 
405
  try:
406
+ logging.info(f"Sending request to DuckDuckGo Chat API: {url}")
407
  response = requests.post(url, json=payload, headers=headers, timeout=timeout)
408
+ logging.info(f"DuckDuckGo Chat API response status code: {response.status_code}")
409
  response.raise_for_status()
410
+ logging.info(f"DuckDuckGo Chat API response: {response.json()}")
411
  return response.json()["response"]
412
  except requests.exceptions.RequestException as e:
413
  logging.error(f"Error in DuckDuckGo chat: {str(e)}")