diff --git a/api.py b/api.py index 8652202..48f7173 100644 --- a/api.py +++ b/api.py @@ -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 @@ -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. diff --git a/requirements.txt b/requirements.txt index e306831..b1b6fb3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 \ No newline at end of file diff --git a/tech_news_agent/agents.py b/tech_news_agent/agents.py index 44cfd68..67eb1d9 100644 --- a/tech_news_agent/agents.py +++ b/tech_news_agent/agents.py @@ -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 @@ -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 ) diff --git a/tech_news_agent/tasks.py b/tech_news_agent/tasks.py index 17bc509..16d4737 100644 --- a/tech_news_agent/tasks.py +++ b/tech_news_agent/tasks.py @@ -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, ) @@ -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'