Spaces:
Runtime error
Runtime error
File size: 13,641 Bytes
adcb9db e25475d 1f39bb8 6b88892 aa7685e 923909d aa7685e 6b88892 35d4946 923909d 3fc3c48 adcb9db 3fc3c48 b43ad80 3fc3c48 adcb9db 3fc3c48 adcb9db 0413dd6 6b88892 3cf3b77 d1ebf41 6b88892 d1ebf41 3fc3c48 0413dd6 35d4946 923909d 35d4946 923909d 35d4946 6b88892 35d4946 e34773c 923909d 6b88892 e34773c 571c059 923909d 571c059 e34773c 35d4946 923909d 6b88892 11686ca 0413dd6 571c059 923909d 571c059 6b88892 923909d 6b88892 aa7685e 571c059 923909d 571c059 6b88892 923909d 6b88892 aa7685e 571c059 923909d 571c059 6b88892 923909d 6b88892 aa7685e 571c059 923909d 571c059 6b88892 923909d 6b88892 571c059 923909d 571c059 6b88892 35d4946 3d8743c b43ad80 e25475d b43ad80 3d8743c 0413dd6 35d4946 0413dd6 35d4946 923909d 35d4946 923909d 35d4946 923909d 35d4946 923909d 35d4946 3d8743c b43ad80 3d8743c 0413dd6 35d4946 923909d 35d4946 923909d 35d4946 0413dd6 35d4946 923909d 35d4946 923909d 35d4946 81e622d 35d4946 923909d 35d4946 923909d 35d4946 81e622d 35d4946 923909d 35d4946 923909d 35d4946 aa7685e 923909d aa7685e 923909d aa7685e adcb9db 0413dd6 adcb9db 11686ca 3fc3c48 11686ca | 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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | from dotenv import load_dotenv
load_dotenv()
from app.workflows.til.suggest_headlines_v2 import SuggestHeadlinesV2, Response as SuggestHeadlinesResponse
from app.workflows.til.rewrite_til_v2 import RewriteTilV2, Response as RewriteTilResponse
from app.workflows.courses.expectation_revision import ExpectationRevision, Inputs as ExpectationRevisionInputs, Response as ExpectationRevisionResponse
from app.workflows.courses.suggest_check_question import SuggestCheckQuestion, Inputs as SuggestCheckQuestionInputs, Response as SuggestCheckQuestionResponse
from app.workflows.courses.suggest_expectations import SuggestExpectations, Inputs as SuggestExpectationsInputs, Expectation, Response as SuggestExpectationsResponse
from app.workflows.til.analyse_til import TilCrew, TilFeedbackResponse
from app.workflows.til.analyse_til_v2 import AnalyseTilV2, TilV2FeedbackResponse
from app.workflows.utils.feedback import Feedback, post_feedback, NewFeedback
from app.utils.endpoints_utils import CreateTilInputs
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from pydantic import UUID4
from tempenv import TemporaryEnvironment
from typing import List
import os
import uvicorn
STAGING_ENV_CONFIG = {
"LANGCHAIN_PROJECT": "customer_agent",
"OPENAI_MODEL": "gpt-4o-mini",
"SUPABASE_URL": os.environ["SUPABASE_URL_STAGING"],
"SUPABASE_KEY": os.environ["SUPABASE_KEY_STAGING"]
}
PROD_ENV_CONFIG = {
"LANGCHAIN_PROJECT": "growthy-agents-prod",
"OPENAI_MODEL": "gpt-4o",
"SUPABASE_URL": os.environ["SUPABASE_URL_PROD"],
"SUPABASE_KEY": os.environ["SUPABASE_KEY_PROD"]
}
description = """
API helps you do awesome stuff. 🚀
"""
tags_metadata = [
{
"name": "til_feedback",
"description": "Gives the feedback on user's TIL content",
},
{
"name": "course_learn",
"description": "Workflows for course learn.",
},
]
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=["*"],
)
# TIL
@app.post("/til_feedback", tags=["til_feedback"])
async def til_feedback_kickoff(content: List[str]) -> TilFeedbackResponse:
inputs = CreateTilInputs(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:
post_feedback(run_id=run_id, feedback=feedback)
return "ok"
@app.post("/staging/til_feedback", tags=["til_feedback", "staging"])
async def staging_til_feedback_kickoff(content: List[str]) -> TilFeedbackResponse:
with TemporaryEnvironment(STAGING_ENV_CONFIG):
separator = "\n* "
content[0] = "* " + content[0]
inputs = {"content": separator.join(content)}
result = TilCrew().kickoff(inputs)
return result
@app.post("/staging/til_feedback/{run_id}/feedback", tags=["til_feedback", "staging"])
async def staging_capture_feedback(run_id: UUID4, feedback: Feedback) -> str:
with TemporaryEnvironment(STAGING_ENV_CONFIG):
post_feedback(run_id=run_id, feedback=feedback)
return "ok"
def til_v2_analyze_logic(content) -> TilV2FeedbackResponse:
inputs = CreateTilInputs(content)
result = AnalyseTilV2().kickoff(inputs)
return result
@app.post("/v2/til_feedback", tags=["til_feedback"])
async def til_v2_feedback_kickoff(content: List[str]) -> TilV2FeedbackResponse:
with TemporaryEnvironment(PROD_ENV_CONFIG):
return til_v2_analyze_logic(content)
@app.post("/v2/til_feedback/{run_id}/feedback", tags=["til_feedback"])
async def capture_til_v2_feedback(run_id: UUID4, feedback: NewFeedback) -> str:
with TemporaryEnvironment(PROD_ENV_CONFIG):
feedback.post({"run_id": run_id, "sub_workflow": "til_analysis"})
return "ok"
@app.post("/staging/v2/til_feedback", tags=["til_feedback", "staging"])
async def staging_til_v2_feedback_kickoff(content: List[str]) -> TilV2FeedbackResponse:
with TemporaryEnvironment(STAGING_ENV_CONFIG):
return til_v2_analyze_logic(content)
@app.post("/staging/v2/til_feedback/{run_id}/feedback", tags=["til_feedback", "staging"])
async def staging_capture_til_v2_feedback(run_id: UUID4, feedback: NewFeedback) -> str:
with TemporaryEnvironment(STAGING_ENV_CONFIG):
feedback.post({"run_id": run_id, "sub_workflow": "til_analysis"})
return "ok"
@app.post("/v2/til_rewrite", tags=["til_readability"])
async def til_v2_rewrite_kickoff(content: List[str]) -> RewriteTilResponse:
with TemporaryEnvironment(PROD_ENV_CONFIG):
inputs = CreateTilInputs(content)
result = RewriteTilV2().kickoff(inputs)
return result
@app.post("/v2/til_rewrite/{run_id}/feedback", tags=["til_readability"])
async def capture_til_v2_rewrite_feedback(run_id: UUID4, feedback: NewFeedback) -> str:
with TemporaryEnvironment(PROD_ENV_CONFIG):
feedback.post({"run_id": run_id, "sub_workflow": "til_understandability"})
return "ok"
@app.post("/staging/v2/til_rewrite", tags=["til_readability", "staging"])
async def staging_til_v2_rewrite_kickoff(content: List[str]) -> RewriteTilResponse:
with TemporaryEnvironment(STAGING_ENV_CONFIG):
inputs = CreateTilInputs(content)
result = RewriteTilV2().kickoff(inputs)
return result
@app.post("/staging/v2/til_rewrite/{run_id}/feedback", tags=["til_readability", "staging"])
async def staging_capture_til_v2_rewrite_feedback(run_id: UUID4, feedback: NewFeedback) -> str:
with TemporaryEnvironment(STAGING_ENV_CONFIG):
feedback.post({"run_id": run_id, "sub_workflow": "til_understandability"})
return "ok"
@app.post("/v2/til_headlines", tags=["til_headlines"])
async def til_v2_suggest_headlines(content: List[str]) -> SuggestHeadlinesResponse:
with TemporaryEnvironment(PROD_ENV_CONFIG):
inputs = CreateTilInputs(content)
result = SuggestHeadlinesV2().kickoff(inputs)
return result
@app.post("/v2/til_headlines/{run_id}/feedback", tags=["til_headlines"])
async def capture_til_v2_headlines(run_id: UUID4, feedback: NewFeedback) -> str:
with TemporaryEnvironment(PROD_ENV_CONFIG):
feedback.post({"run_id": run_id, "sub_workflow": "til_headline"})
return "ok"
@app.post("/staging/v2/til_headlines", tags=["til_headlines", "staging"])
async def staging_til_v2_suggest_headlines(content: List[str]) -> SuggestHeadlinesResponse:
with TemporaryEnvironment(STAGING_ENV_CONFIG):
inputs = CreateTilInputs(content)
result = SuggestHeadlinesV2().kickoff(inputs)
return result
@app.post("/staging/v2/til_headlines/{run_id}/feedback", tags=["til_headlines", "staging"])
async def staging_capture_til_v2_headlines(run_id: UUID4, feedback: NewFeedback) -> str:
with TemporaryEnvironment(STAGING_ENV_CONFIG):
feedback.post({"run_id": run_id, "sub_workflow": "til_headline"})
return "ok"
# Course Learn
def course_learn_suggest_expectations_logic(inputs) -> SuggestExpectationsResponse:
print("Inputs: ", inputs)
result = SuggestExpectations().kickoff(inputs={
"course": inputs.course,
"module": inputs.module,
"tasks": inputs.tasks,
"existing_expectations": inputs.existing_expectations,
})
return result
def course_learn_suggest_expectations_feedback_logic(run_id: UUID4, feedback: Feedback) -> str:
print("Helful Score: ", feedback.metric_type)
print("Feedback On: ", feedback.feedback_on)
post_feedback(run_id=run_id, feedback=feedback)
return "ok"
@app.post("/course_learn/suggest_expectations", tags=["course_learn"])
async def course_learn_suggest_expectations(inputs: SuggestExpectationsInputs) -> SuggestExpectationsResponse:
with TemporaryEnvironment(PROD_ENV_CONFIG):
return course_learn_suggest_expectations_logic(inputs)
@app.post("/staging/course_learn/suggest_expectations", tags=["course_learn", "staging"])
async def staging_course_learn_suggest_expectations(inputs: SuggestExpectationsInputs) -> SuggestExpectationsResponse:
with TemporaryEnvironment(STAGING_ENV_CONFIG):
return course_learn_suggest_expectations_logic(inputs)
@app.post("/course_learn/suggest_expectations/{run_id}/feedback", tags=["course_learn"])
async def capture_suggest_expectations_feedback(run_id: UUID4, feedback: Feedback) -> str:
with TemporaryEnvironment(PROD_ENV_CONFIG):
return course_learn_suggest_expectations_feedback_logic(run_id, feedback)
@app.post("/staging/course_learn/suggest_expectations/{run_id}/feedback", tags=["course_learn", "staging"])
async def staging_capture_suggest_expectations_feedback(run_id: UUID4, feedback: Feedback) -> str:
with TemporaryEnvironment(STAGING_ENV_CONFIG):
return course_learn_suggest_expectations_feedback_logic(run_id, feedback)
def course_learn_expectation_revision_logic(inputs: ExpectationRevisionInputs) -> ExpectationRevisionResponse:
print("Inputs: ", inputs)
result = ExpectationRevision().kickoff(inputs={
"expectation": inputs.expectation,
"check_question": inputs.check_question,
"request": inputs.request,
})
return result
@app.post("/course_learn/expectation_revision", tags=["course_learn"])
async def course_learn_expectation_revision(inputs: ExpectationRevisionInputs) -> ExpectationRevisionResponse:
with TemporaryEnvironment(PROD_ENV_CONFIG):
return course_learn_expectation_revision_logic(inputs)
@app.post("/staging/course_learn/expectation_revision", tags=["course_learn", "staging"])
async def staging_course_learn_expectation_revision(inputs: ExpectationRevisionInputs) -> ExpectationRevisionResponse:
with TemporaryEnvironment(STAGING_ENV_CONFIG):
return course_learn_expectation_revision_logic(inputs)
def capture_expectation_revision_feedback_logic(run_id: UUID4, feedback: Feedback) -> str:
print("Helful Score: ", feedback.metric_type)
print("Feedback On: ", feedback.feedback_on)
post_feedback(run_id=run_id, feedback=feedback)
return "ok"
@app.post("/course_learn/expectation_revision/{run_id}/feedback", tags=["course_learn"])
async def capture_expectation_revision_feedback(run_id: UUID4, feedback: Feedback) -> str:
with TemporaryEnvironment(PROD_ENV_CONFIG):
return capture_expectation_revision_feedback_logic(run_id, feedback)
@app.post("/staging/course_learn/expectation_revision/{run_id}/feedback", tags=["course_learn", "staging"])
async def staging_capture_expectation_revision_feedback(run_id: UUID4, feedback: Feedback) -> str:
with TemporaryEnvironment(STAGING_ENV_CONFIG):
return capture_expectation_revision_feedback_logic(run_id, feedback)
def course_learn_suggest_check_question_logic(inputs: SuggestCheckQuestionInputs) -> SuggestCheckQuestionResponse:
print("Inputs: ", inputs)
result = SuggestCheckQuestion().kickoff(inputs={
"course": inputs.course,
"module": inputs.module,
"tasks": inputs.tasks,
"expectation": inputs.expectation,
})
return result
@app.post("/course_learn/suggest_check_question", tags=["course_learn"])
async def course_learn_suggest_check_question(inputs: SuggestCheckQuestionInputs) -> SuggestCheckQuestionResponse:
with TemporaryEnvironment(PROD_ENV_CONFIG):
return course_learn_suggest_check_question_logic(inputs)
@app.post("/staging/course_learn/suggest_check_question", tags=["course_learn", "staging"])
async def staging_course_learn_suggest_check_question(inputs: SuggestCheckQuestionInputs) -> SuggestCheckQuestionResponse:
with TemporaryEnvironment(STAGING_ENV_CONFIG):
return course_learn_suggest_check_question_logic(inputs)
def course_learn_suggest_check_question_feedback_logic(run_id: UUID4, feedback: Feedback) -> str:
print("Helful Score: ", feedback.metric_type)
print("Feedback On: ", feedback.feedback_on)
post_feedback(run_id=run_id, feedback=feedback)
return "ok"
@app.post("/course_learn/suggest_check_question/{run_id}/feedback", tags=["course_learn"])
async def course_learn_suggest_check_question_feedback(run_id: UUID4, feedback: Feedback) -> str:
with TemporaryEnvironment(PROD_ENV_CONFIG):
return course_learn_suggest_check_question_feedback_logic(run_id, feedback)
@app.post("/staging/course_learn/suggest_check_question/{run_id}/feedback", tags=["course_learn", "staging"])
async def staging_course_learn_suggest_check_question_feedback(run_id: UUID4, feedback: Feedback) -> str:
with TemporaryEnvironment(STAGING_ENV_CONFIG):
return course_learn_suggest_check_question_feedback_logic(run_id, feedback)
@app.post("/llm_feedback/{run_id}/feedback", tags=["llm_feedback"])
async def capture_llm_feedback(run_id: UUID4, feedback: Feedback) -> str:
with TemporaryEnvironment(PROD_ENV_CONFIG):
post_feedback(run_id=run_id, feedback=feedback)
return "ok"
@app.post("/staging/llm_feedback/{run_id}/feedback", tags=["llm_feedback", "staging"])
async def staging_capture_llm_feedback(run_id: UUID4, feedback: Feedback) -> str:
with TemporaryEnvironment(STAGING_ENV_CONFIG):
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)
|