Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions apex/validator/generate_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@
async def generate_query(llm: LLMBase, websearch: WebSearchBase) -> str:
random_words = " ".join(random.sample(get_english_words(), 3))
# Perform a lightweight search and pick a single result as context.
search_results = await websearch.search(random_words, max_results=5)
search_website = random.choice(search_results)
search_content = search_website.content
try:
search_results = await websearch.search(random_words, max_results=5)
search_website = random.choice(search_results)
search_content = search_website.content
except Exception as exc:
logger.debug(f"Error during web search: {exc}")
search_content = ""
query = QUERY_PROMPT_TEMPLATE.format(context=search_content)
query_response, _ = await llm.invoke([{"role": "user", "content": query}])
logger.debug(f"Generated query.\nPrompt: '{query}'\nResponse: '{query_response}'")
Expand Down