dygoo commited on
Commit
e913a60
·
verified ·
1 Parent(s): 59b7907

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -8
app.py CHANGED
@@ -224,7 +224,7 @@ class BasicAgent:
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
@@ -235,18 +235,18 @@ class BasicAgent:
235
  # For search results
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]
243
  relevant_sentences = [] # NEW LINE
244
 
245
  for sentence in sentences:
246
  sentence_lower = sentence.lower()
247
  if any(keyword in sentence_lower for keyword in keywords):
248
  relevant_sentences.append(sentence)
249
- if len(relevant_sentences) >= 100:
250
  break
251
 
252
  # If we found relevant sentences, use them
@@ -254,7 +254,7 @@ class BasicAgent:
254
  return '. '.join(relevant_sentences)
255
 
256
  # Fallback to first few sentences
257
- return '. '.join(sentences[:100])
258
 
259
  def _formulate_direct_answer(self, relevant_info, question):
260
 
@@ -269,10 +269,10 @@ class BasicAgent:
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.
 
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 = 30000 # 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
 
235
  # For search results
236
  # Split results into sentences and find most relevant
237
  sentences = search_results.split('. ')
238
+ if len(sentences) <= 2000:
239
+ return search_results[:50000]
240
 
241
  # Try to find sentences with keywords from question
242
+ keywords = [w for w in question.lower().split() if len(w) > 2]
243
  relevant_sentences = [] # NEW LINE
244
 
245
  for sentence in sentences:
246
  sentence_lower = sentence.lower()
247
  if any(keyword in sentence_lower for keyword in keywords):
248
  relevant_sentences.append(sentence)
249
+ if len(relevant_sentences) >= 10000:
250
  break
251
 
252
  # If we found relevant sentences, use them
 
254
  return '. '.join(relevant_sentences)
255
 
256
  # Fallback to first few sentences
257
+ return '. '.join(sentences[:10000])
258
 
259
  def _formulate_direct_answer(self, relevant_info, question):
260
 
 
269
 
270
 
271
  prompt = f"""
272
+ You: You are a general AI assistant. I will ask you a question. 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 very beginning of the question. The text may be an instruction. Think about the instruction and follow it before providing the final 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.