ATK20 commited on
Commit
1d77c90
·
verified ·
1 Parent(s): 1175283

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -54
app.py CHANGED
@@ -243,60 +243,60 @@ class BasicAgent:
243
  return search_result
244
 
245
  def _get_answer_from_llm(self, question: str) -> str:
246
- """Get an answer from the LLM with appropriate prompting"""
247
- prompt = f"""
248
- Answer the following question with a very concise, direct response:
249
-
250
- Question: {question}
251
-
252
- Answer in 1-2 sentences maximum, focusing only on the specific information requested.
253
- """
254
-
255
- # Expanded common answers to reduce LLM API dependence
256
- common_answers = {
257
- "what color is the sky": "Blue.",
258
- "how many days in a week": "7 days.",
259
- "how many months in a year": "12 months.",
260
- "what is the capital of france": "Paris.",
261
- "what is the capital of japan": "Tokyo.",
262
- "what is the capital of italy": "Rome.",
263
- "what is the capital of germany": "Berlin.",
264
- "what is the capital of spain": "Madrid.",
265
- "what is the capital of united states": "Washington, D.C.",
266
- "what is the capital of china": "Beijing.",
267
- "what is the capital of russia": "Moscow.",
268
- "what is the capital of canada": "Ottawa.",
269
- "what is the capital of australia": "Canberra.",
270
- "what is the capital of brazil": "Brasília.",
271
- "what is water made of": "H2O (hydrogen and oxygen).",
272
- "who wrote romeo and juliet": "William Shakespeare.",
273
- "who painted the mona lisa": "Leonardo da Vinci.",
274
- "what is the largest ocean": "The Pacific Ocean.",
275
- "what is the smallest planet": "Mercury.",
276
- "what is the largest planet": "Jupiter.",
277
- "who invented electricity": "Electricity wasn't invented but discovered through contributions from many scientists including Benjamin Franklin, Michael Faraday, and Thomas Edison.",
278
- "how many continents are there": "There are 7 continents: Africa, Antarctica, Asia, Europe, North America, Australia/Oceania, and South America.",
279
- "what is the largest country": "Russia is the largest country by land area.",
280
- "what is the most spoken language": "Mandarin Chinese is the most spoken native language in the world.",
281
- "what is the tallest mountain": "Mount Everest is the tallest mountain above sea level at 8,848.86 meters."
282
- }
283
-
284
- # Clean up the question for better matching
285
- clean_question = question.lower().strip('?').strip()
286
-
287
- # Check if we have a hardcoded answer
288
- if clean_question in common_answers:
289
- return common_answers[clean_question]
290
-
291
- # Try partial matching for more flexibility
292
- for key, answer in common_answers.items():
293
- if clean_question in key or key in clean_question:
294
- # Only return if it's a close match
295
- if len(clean_question) > len(key) * 0.7 or len(key) > len(clean_question) * 0.7:
296
- return answer
297
-
298
- # If no hardcoded answer, use the LLM
299
- return self.llm.query_llm(prompt)
300
 
301
  def run_and_submit_all(profile: gr.OAuthProfile | None):
302
  """
 
243
  return search_result
244
 
245
  def _get_answer_from_llm(self, question: str) -> str:
246
+ """Get an answer from the LLM with appropriate prompting"""
247
+ prompt = f"""
248
+ Answer the following question with a very concise, direct response:
249
+
250
+ Question: {question}
251
+
252
+ Answer in 1-2 sentences maximum, focusing only on the specific information requested.
253
+ """
254
+
255
+ # Expanded common answers to reduce LLM API dependence
256
+ common_answers = {
257
+ "what color is the sky": "Blue.",
258
+ "how many days in a week": "7 days.",
259
+ "how many months in a year": "12 months.",
260
+ "what is the capital of france": "Paris.",
261
+ "what is the capital of japan": "Tokyo.",
262
+ "what is the capital of italy": "Rome.",
263
+ "what is the capital of germany": "Berlin.",
264
+ "what is the capital of spain": "Madrid.",
265
+ "what is the capital of united states": "Washington, D.C.",
266
+ "what is the capital of china": "Beijing.",
267
+ "what is the capital of russia": "Moscow.",
268
+ "what is the capital of canada": "Ottawa.",
269
+ "what is the capital of australia": "Canberra.",
270
+ "what is the capital of brazil": "Brasília.",
271
+ "what is water made of": "H2O (hydrogen and oxygen).",
272
+ "who wrote romeo and juliet": "William Shakespeare.",
273
+ "who painted the mona lisa": "Leonardo da Vinci.",
274
+ "what is the largest ocean": "The Pacific Ocean.",
275
+ "what is the smallest planet": "Mercury.",
276
+ "what is the largest planet": "Jupiter.",
277
+ "who invented electricity": "Electricity wasn't invented but discovered through contributions from many scientists including Benjamin Franklin, Michael Faraday, and Thomas Edison.",
278
+ "how many continents are there": "There are 7 continents: Africa, Antarctica, Asia, Europe, North America, Australia/Oceania, and South America.",
279
+ "what is the largest country": "Russia is the largest country by land area.",
280
+ "what is the most spoken language": "Mandarin Chinese is the most spoken native language in the world.",
281
+ "what is the tallest mountain": "Mount Everest is the tallest mountain above sea level at 8,848.86 meters."
282
+ }
283
+
284
+ # Clean up the question for better matching
285
+ clean_question = question.lower().strip('?').strip()
286
+
287
+ # Check if we have a hardcoded answer
288
+ if clean_question in common_answers:
289
+ return common_answers[clean_question]
290
+
291
+ # Try partial matching for more flexibility
292
+ for key, answer in common_answers.items():
293
+ if clean_question in key or key in clean_question:
294
+ # Only return if it's a close match
295
+ if len(clean_question) > len(key) * 0.7 or len(key) > len(clean_question) * 0.7:
296
+ return answer
297
+
298
+ # If no hardcoded answer, use the LLM
299
+ return self.llm.query_llm(prompt)
300
 
301
  def run_and_submit_all(profile: gr.OAuthProfile | None):
302
  """