Spaces:
Sleeping
Sleeping
| 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=["*"], | |
| ) | |
| 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] | |
| 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" | |
| async def read_root(): | |
| return {"status": "ok"} | |
| if __name__ == "__main__": | |
| uvicorn.run(app, host="127.0.0.1", port=8080) | |