setup / endpoints.py
AnanthulaShravya's picture
Upload 7 files
d52ae5a verified
from dotenv import load_dotenv
import uvicorn
from fastapi import FastAPI, Query
from crew import til
from fastapi.middleware.cors import CORSMiddleware
from langsmith import Client
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]) -> til.TilFeedbackResponse:
separator = "\n* "
content[0] = "* " + content[0]
inputs = {"content": separator.join(content)}
result = til.TilCrew().kickoff(inputs)
return result
class Feedback(BaseModel):
helpful_score: Optional[float]
feedback_on: Optional[str]
@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)
client = Client()
client.create_feedback(
str(run_id),
key="helpful",
score=feedback.helpful_score,
source_info={"til": feedback.feedback_on},
type="api",
)
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)