Skip to content

Commit

Permalink
ADDED: news agent
Browse files Browse the repository at this point in the history
  • Loading branch information
AquibPy committed Jun 24, 2024
1 parent df30c35 commit d303418
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 33 deletions.
54 changes: 27 additions & 27 deletions api.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Mail
from uuid import uuid4
# from tech_news_agent.crew import run_crew
from tech_news_agent.crew import run_crew
from langchain.agents import AgentExecutor
from langchain_core.prompts import ChatPromptTemplate
from langchain_cohere.react_multi_hop.agent import create_cohere_react_agent
Expand Down Expand Up @@ -650,32 +650,32 @@ async def get_data(endpoint_name: str, token: str = Depends(oauth2_scheme)):

return data

# @app.post("/news_agent",description="""
# This endpoint leverages AI agents to conduct research and generate articles on various tech topics.
# The agents are designed to uncover groundbreaking technologies and narrate compelling tech stories
# """)
# async def run_news_agent(topic: str = Form("AI in healthcare")):
# try:
# cache_key = f"news_agent:{topic}"
# cached_response = redis.get(cache_key)
# if cached_response:
# print("Retrieving response from Redis cache")
# return ResponseText(response=cached_response.decode("utf-8"))

# output = run_crew(topic=topic)
# redis.set(cache_key, output, ex=10)
# db = MongoDB()
# payload = {
# "endpoint": "/news_agent",
# "topic" : topic,
# "output": output
# }
# mongo_data = {"Document": payload}
# result = db.insert_data(mongo_data)
# print(result)
# return ResponseText(response=output)
# except Exception as e:
# return {"error": str(e)}
@app.post("/news_agent",description="""
This endpoint leverages AI agents to conduct research and generate articles on various tech topics.
The agents are designed to uncover groundbreaking technologies and narrate compelling tech stories
""")
async def run_news_agent(topic: str = Form("AI in healthcare")):
try:
cache_key = f"news_agent:{topic}"
cached_response = redis.get(cache_key)
if cached_response:
print("Retrieving response from Redis cache")
return ResponseText(response=cached_response.decode("utf-8"))

output = run_crew(topic=topic)
redis.set(cache_key, output, ex=10)
db = MongoDB()
payload = {
"endpoint": "/news_agent",
"topic" : topic,
"output": output
}
mongo_data = {"Document": payload}
result = db.insert_data(mongo_data)
print(result)
return ResponseText(response=output)
except Exception as e:
return {"error": str(e)}

@app.post("/query_db",description="""
The Query Database endpoint provides a service for interacting with SQL databases using a Cohere ReAct Agent.
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ sendgrid
llama-index-llms-groq
llama-index-embeddings-langchain
grpcio
# crewai
# crewai-tools
crewai
crewai-tools
proto-plus
langchain-cohere
slowapi
4 changes: 2 additions & 2 deletions tech_news_agent/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"innovation, eager to explore and share knowledge that could change"
"the world."
),
# tools=[tool],
tools=[tool],
llm=llm,
allow_delegation=True

Expand All @@ -42,7 +42,7 @@
"engaging narratives that captivate and educate, bringing new"
"discoveries to light in an accessible manner."
),
# tools=[tool],
tools=[tool],
llm=llm,
allow_delegation=False
)
4 changes: 2 additions & 2 deletions tech_news_agent/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"its market opportunities, and potential risks."
),
expected_output='A comprehensive 3 paragraphs long report on the latest AI trends.',
# tools=[tool],
tools=[tool],
agent=news_researcher,
)

Expand All @@ -23,7 +23,7 @@
"This article should be easy to understand, engaging, and positive."
),
expected_output='A 4 paragraph article on {topic} advancements formatted as markdown.',
# tools=[tool],
tools=[tool],
agent=news_writer,
async_execution=False,
# output_file='new-blog-post.md'
Expand Down

0 comments on commit d303418

Please sign in to comment.