Skip to content

Commit

Permalink
MODIFIED: due to some issue in pip disabling news_agent route
Browse files Browse the repository at this point in the history
  • Loading branch information
AquibPy committed May 29, 2024
1 parent f3e1dca commit c3f6378
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 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


os.environ["LANGCHAIN_TRACING_V2"]="true"
Expand Down Expand Up @@ -628,32 +628,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)}

if __name__ == '__main__':
import uvicorn
Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ python-jose
sendgrid
llama-index-llms-groq
llama-index-embeddings-langchain
crewai
crewai[tools]
proto-plus
# crewai
# crewai-tools
# proto-plus

0 comments on commit c3f6378

Please sign in to comment.