File size: 1,485 Bytes
23d16d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1bbbd4e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from langchain_core.prompts import PromptTemplate

queries_prompt_template = PromptTemplate.from_template("""
You are an expert in generating effective search queries to discover the latest trends, news, laws, regulations, and recent developments from {year} onward related to a given Topic in United Kingdom.
Based on the Topic provided, create a comprehensive and highly relevant search queries that can be used in search engines to find up-to-date information.

# The queries should cover:
- Latest trends and emerging topics
- Recent news and noteworthy events
- New or updated laws and regulations
- Market insights and innovations
- Expert opinions and industry reports

# Generate at least 5 specific, diverse, and concise search queries that capture different aspects of the Topic.
# Use variations in phrasing to ensure comprehensive search results.
# Make sure the queries are unique So that we get diverse search results.
# Don't include any irrelevant information in the queries like Markdown, Newlines etc. Only give the search queries.

Topic = {topic}
""")

# Generate Queries
from datetime import date
current_year = date.today().strftime("%Y")

def generate_queries(llm, state):
  topic = state["topic"][0].content
  prompt = queries_prompt_template.invoke({"topic": topic, "year": current_year})
  response = llm.invoke(prompt)
  content = response.content
  response_list = [item.strip('"') for item in content.split('\n')]
  return {"search_queries": response_list}