Skip to content

Commit c869314

Browse files
committed
Update web_search_plugin.py
1 parent 84f80d0 commit c869314

File tree

1 file changed

+13
-23
lines changed

1 file changed

+13
-23
lines changed

optillm/plugins/web_search_plugin.py

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -517,39 +517,29 @@ def extract_search_queries(text: str) -> List[str]:
517517
queries.append(cleaned)
518518

519519
# If no explicit patterns, use the text as a search query
520+
# Since the user explicitly invoked the web_search plugin, we should always search
520521
if not queries:
521522
# Check if this is a search command with empty query (e.g., "search for" with nothing after)
522523
search_prefixes = ["search for", "find information about", "look up", "research"]
523524
text_lower = text.lower().strip()
524-
525+
525526
# Don't use fallback if it's just a search prefix with nothing meaningful after
526527
is_empty_search = any(
527-
text_lower.startswith(prefix) and
528+
text_lower.startswith(prefix) and
528529
len(text_lower.replace(prefix, "").strip().strip('"\'')) < 2
529530
for prefix in search_prefixes
530531
)
531-
532-
if not is_empty_search:
533-
# Remove question marks and clean up
534-
cleaned_query = text.replace("?", "").strip()
535-
# Remove quotes from the query
536-
cleaned_query = cleaned_query.strip('"\'')
537-
538-
# If it looks like a question or search query, use it
539-
if cleaned_query and len(cleaned_query.split()) > 2:
532+
533+
if not is_empty_search and text.strip():
534+
# User explicitly invoked web_search plugin - send the full query
535+
cleaned_query = text.strip()
536+
537+
# Just basic cleanup: normalize whitespace (replace newlines with spaces)
538+
cleaned_query = ' '.join(cleaned_query.split())
539+
540+
# Final validation - must have some meaningful content
541+
if cleaned_query and len(cleaned_query) >= 3:
540542
queries.append(cleaned_query)
541-
else:
542-
# Clean up the text to make it search-friendly
543-
cleaned_query = re.sub(r'[^\w\s\.]', ' ', text) # Keep periods for version numbers
544-
cleaned_query = ' '.join(cleaned_query.split())
545-
# Remove quotes after regex cleaning
546-
cleaned_query = cleaned_query.strip('"\'')
547-
548-
if len(cleaned_query) > 100:
549-
# Take first 100 characters
550-
cleaned_query = cleaned_query[:100].rsplit(' ', 1)[0]
551-
if cleaned_query and len(cleaned_query) > 2: # Ensure minimum length
552-
queries.append(cleaned_query)
553543

554544
return queries
555545

0 commit comments

Comments
 (0)