Spaces:
Sleeping
Sleeping
Update blog_content_generator.py
Browse files- blog_content_generator.py +27 -13
blog_content_generator.py
CHANGED
|
@@ -1,29 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
def blog_content_agent(llm, state):
|
| 2 |
from langgraph.graph import MessagesState
|
| 3 |
from langchain_community.tools import DuckDuckGoSearchRun
|
| 4 |
-
from
|
| 5 |
from langchain_core.messages import HumanMessage, SystemMessage
|
| 6 |
from datetime import date
|
| 7 |
|
| 8 |
topic = state["final_topic"]
|
|
|
|
|
|
|
| 9 |
# tool
|
| 10 |
-
def
|
| 11 |
"""
|
| 12 |
-
Performs a search on
|
|
|
|
| 13 |
Args:
|
| 14 |
query (str): The search query to be executed.
|
|
|
|
| 15 |
Returns:
|
| 16 |
str: The result of the search query.
|
| 17 |
"""
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
|
| 21 |
-
result = search.invoke(f"Search this in UK: {query} after:{current_year}")
|
| 22 |
print("Tool Call")
|
| 23 |
-
print(
|
| 24 |
-
return
|
| 25 |
|
| 26 |
-
tool = [
|
| 27 |
# llm = ChatGoogleGenerativeAI(model="gemini-2.0-flash-exp", api_key = gemini_api_key)
|
| 28 |
llm_with_tools = llm.bind_tools(tool)
|
| 29 |
|
|
@@ -126,9 +141,9 @@ Replacing your boiler is a big investment, but it’s one that can bring signifi
|
|
| 126 |
|
| 127 |
Context:
|
| 128 |
- The blog post should be informative and engaging.
|
| 129 |
-
- The Blog
|
| 130 |
-
- Always Use the attached tool
|
| 131 |
-
- Always use the Tool Message in writing the Blog content.
|
| 132 |
|
| 133 |
Constraints:
|
| 134 |
- The blog post should be between 700 to 800 words.
|
|
@@ -169,5 +184,4 @@ Output Format:
|
|
| 169 |
|
| 170 |
message = [HumanMessage(content=f"Search this query: {topic}")]
|
| 171 |
messages = react_graph.invoke({"messages": message})
|
| 172 |
-
# print(messages['messages'][-1].content)
|
| 173 |
return {"blog_content": messages['messages'][-1].content}
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from dotenv import load_dotenv
|
| 3 |
+
|
| 4 |
+
# Secret Key
|
| 5 |
+
load_dotenv(override=True)
|
| 6 |
+
tavily_api_key = os.getenv("TAVILY_API_KEY")
|
| 7 |
+
|
| 8 |
def blog_content_agent(llm, state):
|
| 9 |
from langgraph.graph import MessagesState
|
| 10 |
from langchain_community.tools import DuckDuckGoSearchRun
|
| 11 |
+
from langchain_community.tools import TavilySearchResults
|
| 12 |
from langchain_core.messages import HumanMessage, SystemMessage
|
| 13 |
from datetime import date
|
| 14 |
|
| 15 |
topic = state["final_topic"]
|
| 16 |
+
print(topic)
|
| 17 |
+
|
| 18 |
# tool
|
| 19 |
+
def tavily_search(query: str) -> str:
|
| 20 |
"""
|
| 21 |
+
Performs a search on Tavily using the provided query.
|
| 22 |
+
|
| 23 |
Args:
|
| 24 |
query (str): The search query to be executed.
|
| 25 |
+
|
| 26 |
Returns:
|
| 27 |
str: The result of the search query.
|
| 28 |
"""
|
| 29 |
+
tavily = TavilySearchResults(
|
| 30 |
+
max_results=5,
|
| 31 |
+
search_depth="advanced",
|
| 32 |
+
include_answer=True,
|
| 33 |
+
include_raw_content=True,
|
| 34 |
+
)
|
| 35 |
|
| 36 |
+
text = tavily.invoke({"query": f"Search this in UK: {query} After:2025"})
|
|
|
|
| 37 |
print("Tool Call")
|
| 38 |
+
print(text)
|
| 39 |
+
return text
|
| 40 |
|
| 41 |
+
tool = [tavily_search]
|
| 42 |
# llm = ChatGoogleGenerativeAI(model="gemini-2.0-flash-exp", api_key = gemini_api_key)
|
| 43 |
llm_with_tools = llm.bind_tools(tool)
|
| 44 |
|
|
|
|
| 141 |
|
| 142 |
Context:
|
| 143 |
- The blog post should be informative and engaging.
|
| 144 |
+
- The Blog Post is for the UK audience.
|
| 145 |
+
- Always Use the attached tool tavily_search to get the latest information about the topic.
|
| 146 |
+
- Always use the Tool Message in writing the Blog content.
|
| 147 |
|
| 148 |
Constraints:
|
| 149 |
- The blog post should be between 700 to 800 words.
|
|
|
|
| 184 |
|
| 185 |
message = [HumanMessage(content=f"Search this query: {topic}")]
|
| 186 |
messages = react_graph.invoke({"messages": message})
|
|
|
|
| 187 |
return {"blog_content": messages['messages'][-1].content}
|