Walid Aissa commited on
Commit
22eefa0
1 Parent(s): e8d113c

Improved the wikipedia_search method

Browse files
Files changed (1) hide show
  1. app.py +8 -1
app.py CHANGED
@@ -42,7 +42,14 @@ def wikipedia_search(input: str) -> str:
42
 
43
  try :
44
  #TODO: add better extraction and search
45
- page = wiki.page(keyphrases[0])
 
 
 
 
 
 
 
46
  return page.summary
47
  except:
48
  return "I cannot answer this question"
 
42
 
43
  try :
44
  #TODO: add better extraction and search
45
+ keyphrase_index = 0
46
+ page = wiki.page(keyphrases[keyphrase_index])
47
+
48
+ while not ('.' in page.summary) or not page.exists():
49
+ keyphrase_index += 1
50
+ if keyphrase_index == len(keyphrases):
51
+ raise Exception
52
+ page = wiki.page(keyphrases[keyphrase_index])
53
  return page.summary
54
  except:
55
  return "I cannot answer this question"