ai_workflows / endpoints.py
theRealNG's picture
endpoints(til): Fix minor issue on how we are joining the tils
dba2d83
raw
history blame
1.64 kB
from dotenv import load_dotenv
import uvicorn
from fastapi import FastAPI, Query
from .workflows.til import TilCrew, TilFeedbackResponse
from .workflows.utils.feedback import Feedback
from fastapi.middleware.cors import CORSMiddleware
from typing import List, Optional
from pydantic import UUID4, BaseModel
load_dotenv()
description = """
API helps you do awesome stuff. 🚀
"""
tags_metadata = [
{
"name": "til_feedback",
"description": "Gives the feedback on user's TIL content",
},
]
app = FastAPI(
title="Growthy AI Worflows",
description=description,
summary="Deadpool's favorite app. Nuff said.",
version="0.0.1",
openapi_tags=tags_metadata,
docs_url="/documentation",
)
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.post("/til_feedback", tags=["til_feedback"])
async def til_feedback_kickoff(content: List[str]) -> TilFeedbackResponse:
separator = "\n "
content[0] = " " + content[0]
inputs = {"content": separator.join(content)}
result = TilCrew().kickoff(inputs)
return result
@app.post("/til_feedback/{run_id}/feedback", tags=["til_feedback"])
async def capture_feedback(run_id: UUID4, feedback: Feedback) -> str:
print("Helful Score: ", feedback.helpful_score)
print("Feedback On: ", feedback.feedback_on)
TilCrew.post_feedback(run_id=run_id, feedback=feedback)
return "ok"
@app.get("/healthcheck")
async def read_root():
return {"status": "ok"}
if __name__ == "__main__":
uvicorn.run(app, host="127.0.0.1", port=8080)