File size: 1,841 Bytes
d52ae5a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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)