dygoo commited on
Commit
841fd83
·
verified ·
1 Parent(s): 04519a3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -11
app.py CHANGED
@@ -84,7 +84,7 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
84
  @lru_cache(maxsize=100)
85
  def cached_search(query):
86
  try:
87
- print(f"Performing search for: {query[:5000]}...")
88
  result = search_tool(query)
89
  print(f"Search successful, returned {len(result)} characters")
90
  return result
@@ -121,10 +121,10 @@ class BasicAgent:
121
 
122
  """Initialize the Gemini model with appropriate settings"""
123
  generation_config = {
124
- "temperature": 0.7,
125
  "top_p": 0.95,
126
  "top_k": 40,
127
- "max_output_tokens": 1024,
128
  }
129
 
130
  safety_settings = {
@@ -218,13 +218,13 @@ class BasicAgent:
218
 
219
  def _extract_key_info(self, search_results, question):
220
  # Basic check for empty results
221
- if not search_results or len(search_results) < 5:
222
  return "No relevant information found."
223
 
224
  # For YouTube transcripts, extract the most relevant portion
225
  if "Transcript from YouTube video" in search_results:
226
  # Split by sentences but keep limited context
227
- max_chars = 5000 # Keep a reasonable chunk size
228
  if len(search_results) > max_chars:
229
  # Take a portion from the middle of the transcript for better relevance
230
  start_idx = search_results.find("\n") + 1 # Skip the first line which is the header
@@ -236,7 +236,7 @@ class BasicAgent:
236
  # Split results into sentences and find most relevant
237
  sentences = search_results.split('. ')
238
  if len(sentences) <= 100:
239
- return search_results[:8000]
240
 
241
  # Try to find sentences with keywords from question
242
  keywords = [w for w in question.lower().split() if len(w) > 100]
@@ -269,19 +269,20 @@ class BasicAgent:
269
 
270
 
271
  prompt = f"""
272
- Question: {question}
273
-
274
- Relevant information: {relevant_info}
275
-
276
  Instructions:
277
  1. Read the question and think about what you need to answer it. Stick to the question. If you need search results, use the search results. If not, just answer the question directly and ignore the search results. Do not use search results if you can answer the question without using them.
278
  2. If the question is not comprehensible, try reading each letter backwards, from the last character in the last word, to the first letter of the first word. Read carefully, all the way to the beginning. If the backwards text turns out to be an instruction, just follow the instruction and provide a direct answer. Don't provide comments.
279
  3. If the question is still not comprehensible, try seeing if it is in another language.
280
- 4. Think about whether you need to elaborate on the information. For example, if you know that John and Jane are kids of Joan, you know Joan has at least two kids. In other words, if you don't have a number that is asked of you, see if you can count to produce an answer. Once you have counted, just answer the number. In the example I just gace, you would answer: "FINAL ANSWER: Two".
281
  5. Provide a direct answer.
282
  6. If the information doesn't contain the answer, say so honestly.
283
  7. Do not invent anything. You can apply method to elaborate, but based on facts. Do not provide comments. Just the raw answer.
284
  8. Format your response as a direct answer. For example, if you are asked the year in which World War II began, just reply: "FINAL ANSWER: 1939".
 
 
 
 
285
  """
286
 
287
  response = self.gemini_model.generate_content(prompt)
 
84
  @lru_cache(maxsize=100)
85
  def cached_search(query):
86
  try:
87
+ print(f"Performing search for: {query[:50000]}...")
88
  result = search_tool(query)
89
  print(f"Search successful, returned {len(result)} characters")
90
  return result
 
121
 
122
  """Initialize the Gemini model with appropriate settings"""
123
  generation_config = {
124
+ "temperature": 0.1,
125
  "top_p": 0.95,
126
  "top_k": 40,
127
+ "max_output_tokens": 10000,
128
  }
129
 
130
  safety_settings = {
 
218
 
219
  def _extract_key_info(self, search_results, question):
220
  # Basic check for empty results
221
+ if not search_results or len(search_results) < 15:
222
  return "No relevant information found."
223
 
224
  # For YouTube transcripts, extract the most relevant portion
225
  if "Transcript from YouTube video" in search_results:
226
  # Split by sentences but keep limited context
227
+ max_chars = 10000 # Keep a reasonable chunk size
228
  if len(search_results) > max_chars:
229
  # Take a portion from the middle of the transcript for better relevance
230
  start_idx = search_results.find("\n") + 1 # Skip the first line which is the header
 
236
  # Split results into sentences and find most relevant
237
  sentences = search_results.split('. ')
238
  if len(sentences) <= 100:
239
+ return search_results[:10000]
240
 
241
  # Try to find sentences with keywords from question
242
  keywords = [w for w in question.lower().split() if len(w) > 100]
 
269
 
270
 
271
  prompt = f"""
272
+ You: You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER]. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.
 
 
 
273
  Instructions:
274
  1. Read the question and think about what you need to answer it. Stick to the question. If you need search results, use the search results. If not, just answer the question directly and ignore the search results. Do not use search results if you can answer the question without using them.
275
  2. If the question is not comprehensible, try reading each letter backwards, from the last character in the last word, to the first letter of the first word. Read carefully, all the way to the beginning. If the backwards text turns out to be an instruction, just follow the instruction and provide a direct answer. Don't provide comments.
276
  3. If the question is still not comprehensible, try seeing if it is in another language.
277
+ 4. Think about whether you need to elaborate on the information. For example, if you know that John and Jane are kids of Joan, you know Joan has at least two kids. In other words, if you don't have a number that is asked of you, see if you can count to produce an answer. Once you have counted, just answer the number. Be succinct, coesive, I would even say tight in your answers. If the question asks "how many?", just reply back the number that answers. In the example I just gave, you would answer: "FINAL ANSWER: Two".
278
  5. Provide a direct answer.
279
  6. If the information doesn't contain the answer, say so honestly.
280
  7. Do not invent anything. You can apply method to elaborate, but based on facts. Do not provide comments. Just the raw answer.
281
  8. Format your response as a direct answer. For example, if you are asked the year in which World War II began, just reply: "FINAL ANSWER: 1939".
282
+
283
+ Question: {question}
284
+
285
+ Relevant information: {relevant_info}
286
  """
287
 
288
  response = self.gemini_model.generate_content(prompt)