nikhmr1235 commited on
Commit
7f44b5f
·
verified ·
1 Parent(s): 570dc2b

Update helper.py

Browse files
Files changed (1) hide show
  1. helper.py +1 -52
helper.py CHANGED
@@ -486,7 +486,7 @@ gemini_multimodal_tool = Tool(
486
  func=analyze_image_with_gemini,
487
  )
488
 
489
- '''
490
  def wiki_search(query: str) -> str:
491
  """Search Wikipedia for a query and return maximum 2 results.
492
 
@@ -508,54 +508,3 @@ wikipedia_search_tool2 = Tool(
508
  description=wiki_search.__doc__,
509
  func=wiki_search,
510
  )
511
- '''
512
-
513
- from langchain_community.document_loaders import WikipediaLoader
514
- from langchain_core.tools import Tool
515
- from typing import Optional, List
516
-
517
- def wiki_search(
518
- query: str,
519
- load_max_docs: int = 3,
520
- auto_suggest: bool = False, # New parameter
521
- lang: str = "en" # New parameter
522
- ) -> str:
523
- """Search Wikipedia for a query and return a specified maximum number of results.
524
-
525
- Args:
526
- query: The search query.
527
- load_max_docs: The maximum number of documents to load. Default is 2.
528
- auto_suggest: If True, Wikipedia's auto-suggestion feature will be used to refine the query.
529
- This can lead to more consistent results for slightly misspelled or ambiguous queries.
530
- lang: The language of the Wikipedia to search (e.g., "en" for English). Default is "en".
531
- Returns:
532
- A string with formatted Wikipedia search results.
533
- """
534
- try:
535
- # Use auto_suggest to let Wikipedia refine the query
536
- search_docs = WikipediaLoader(
537
- query=query,
538
- load_max_docs=load_max_docs,
539
- auto_suggest=auto_suggest,
540
- lang=lang
541
- ).load()
542
-
543
- if not search_docs:
544
- return "No relevant Wikipedia results found."
545
-
546
- formatted_search_docs = "\n\n---\n\n".join(
547
- [
548
- f'<Document source="{doc.metadata.get("source", "")}" page="{doc.metadata.get("page", "")}"/>\n{doc.page_content}\n</Document>'
549
- for doc in search_docs
550
- ])
551
- return formatted_search_docs
552
- except Exception as e:
553
- # Catching potential Wikipedia API errors (e.g., query too ambiguous)
554
- return f"An error occurred during Wikipedia search: {e}"
555
-
556
-
557
- wikipedia_search_tool2 = Tool(
558
- name="wikipedia_search_tool2",
559
- description="Search Wikipedia for a query and return a specified maximum number of results. Can use auto-suggestion and specify language.",
560
- func=wiki_search,
561
- )
 
486
  func=analyze_image_with_gemini,
487
  )
488
 
489
+
490
  def wiki_search(query: str) -> str:
491
  """Search Wikipedia for a query and return maximum 2 results.
492
 
 
508
  description=wiki_search.__doc__,
509
  func=wiki_search,
510
  )