Spaces:
Runtime error
Runtime error
k-manjunath commited on
Commit ·
571c059
1
Parent(s): 1fe1487
workflows(til_v2): create new feedback endpoints
Browse files* create specific endpoints for each til sub-workflow
* create new feedback class NewFeedback
- endpoints.py +45 -1
- workflows/utils/feedback.py +30 -0
endpoints.py
CHANGED
|
@@ -8,7 +8,7 @@ from .workflows.courses.suggest_check_question import SuggestCheckQuestion, Inpu
|
|
| 8 |
from .workflows.courses.suggest_expectations import SuggestExpectations, Inputs as SuggestExpectationsInputs, Expectation, Response as SuggestExpectationsResponse
|
| 9 |
from .workflows.til.analyse_til import TilCrew, TilFeedbackResponse
|
| 10 |
from .workflows.til.analyse_til_v2 import AnalyseTilV2, TilV2FeedbackResponse
|
| 11 |
-
from .workflows.utils.feedback import Feedback, post_feedback
|
| 12 |
from .utils.endpoints_utils import CreateTilInputs
|
| 13 |
from fastapi import FastAPI
|
| 14 |
from fastapi.middleware.cors import CORSMiddleware
|
|
@@ -99,6 +99,13 @@ async def til_v2_feedback_kickoff(content: List[str]) -> TilV2FeedbackResponse:
|
|
| 99 |
with TemporaryEnvironment({"LANGCHAIN_PROJECT": LANGSMITH_PROD_PROJECT, "OPENAI_MODEL": LANGSMITH_PROD_MODEL}):
|
| 100 |
return til_v2_analyze_logic(content)
|
| 101 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
@app.post("/staging/v2/til_feedback", tags=["til_feedback", "staging"])
|
| 104 |
async def staging_til_v2_feedback_kickoff(content: List[str]) -> TilV2FeedbackResponse:
|
|
@@ -106,6 +113,13 @@ async def staging_til_v2_feedback_kickoff(content: List[str]) -> TilV2FeedbackRe
|
|
| 106 |
return til_v2_analyze_logic(content)
|
| 107 |
|
| 108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
@app.post("/v2/til_rewrite", tags=["til_readability"])
|
| 110 |
async def til_v2_rewrite_kickoff(content: List[str]) -> RewriteTilResponse:
|
| 111 |
with TemporaryEnvironment({"LANGCHAIN_PROJECT": LANGSMITH_PROD_PROJECT, "OPENAI_MODEL": LANGSMITH_PROD_MODEL}):
|
|
@@ -114,6 +128,13 @@ async def til_v2_rewrite_kickoff(content: List[str]) -> RewriteTilResponse:
|
|
| 114 |
return result
|
| 115 |
|
| 116 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
@app.post("/staging/v2/til_rewrite", tags=["til_readability", "staging"])
|
| 118 |
async def staging_til_v2_rewrite_kickoff(content: List[str]) -> RewriteTilResponse:
|
| 119 |
with TemporaryEnvironment({"LANGCHAIN_PROJECT": LANGSMITH_STAGING_PROJECT, "OPENAI_MODEL": LANGSMITH_STAGING_MODEL}):
|
|
@@ -122,6 +143,13 @@ async def staging_til_v2_rewrite_kickoff(content: List[str]) -> RewriteTilRespon
|
|
| 122 |
return result
|
| 123 |
|
| 124 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
@app.post("/v2/til_headlines", tags=["til_headlines"])
|
| 126 |
async def til_v2_suggest_headlines(content: List[str]) -> SuggestHeadlinesResponse:
|
| 127 |
with TemporaryEnvironment({"LANGCHAIN_PROJECT": LANGSMITH_PROD_PROJECT, "OPENAI_MODEL": LANGSMITH_PROD_MODEL}):
|
|
@@ -130,6 +158,13 @@ async def til_v2_suggest_headlines(content: List[str]) -> SuggestHeadlinesRespon
|
|
| 130 |
return result
|
| 131 |
|
| 132 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
@app.post("/staging/v2/til_headlines", tags=["til_headlines", "staging"])
|
| 134 |
async def staging_til_v2_suggest_headlines(content: List[str]) -> SuggestHeadlinesResponse:
|
| 135 |
with TemporaryEnvironment({"LANGCHAIN_PROJECT": LANGSMITH_STAGING_PROJECT, "OPENAI_MODEL": LANGSMITH_STAGING_MODEL}):
|
|
@@ -138,6 +173,15 @@ async def staging_til_v2_suggest_headlines(content: List[str]) -> SuggestHeadlin
|
|
| 138 |
return result
|
| 139 |
|
| 140 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
# Course Learn
|
| 142 |
def course_learn_suggest_expectations_logic(inputs) -> SuggestExpectationsResponse:
|
| 143 |
print("Inputs: ", inputs)
|
|
|
|
| 8 |
from .workflows.courses.suggest_expectations import SuggestExpectations, Inputs as SuggestExpectationsInputs, Expectation, Response as SuggestExpectationsResponse
|
| 9 |
from .workflows.til.analyse_til import TilCrew, TilFeedbackResponse
|
| 10 |
from .workflows.til.analyse_til_v2 import AnalyseTilV2, TilV2FeedbackResponse
|
| 11 |
+
from .workflows.utils.feedback import Feedback, post_feedback, NewFeedback
|
| 12 |
from .utils.endpoints_utils import CreateTilInputs
|
| 13 |
from fastapi import FastAPI
|
| 14 |
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
| 99 |
with TemporaryEnvironment({"LANGCHAIN_PROJECT": LANGSMITH_PROD_PROJECT, "OPENAI_MODEL": LANGSMITH_PROD_MODEL}):
|
| 100 |
return til_v2_analyze_logic(content)
|
| 101 |
|
| 102 |
+
@app.post("/v2/til_feedback/{run_id}/feedback", tags=["til_feedback"])
|
| 103 |
+
async def capture_til_v2_feedback(run_id: UUID4, feedback: NewFeedback) -> str:
|
| 104 |
+
with TemporaryEnvironment({"LANGCHAIN_PROJECT": LANGSMITH_PROD_PROJECT, "OPENAI_MODEL": LANGSMITH_PROD_MODEL}):
|
| 105 |
+
feedback.post({"run_id": run_id, "sub_workflow": "til_analysis"})
|
| 106 |
+
return "ok"
|
| 107 |
+
|
| 108 |
+
|
| 109 |
|
| 110 |
@app.post("/staging/v2/til_feedback", tags=["til_feedback", "staging"])
|
| 111 |
async def staging_til_v2_feedback_kickoff(content: List[str]) -> TilV2FeedbackResponse:
|
|
|
|
| 113 |
return til_v2_analyze_logic(content)
|
| 114 |
|
| 115 |
|
| 116 |
+
@app.post("/staging/v2/til_feedback/{run_id}/feedback", tags=["til_feedback", "staging"])
|
| 117 |
+
async def staging_capture_til_v2_feedback(run_id: UUID4, feedback: NewFeedback) -> str:
|
| 118 |
+
with TemporaryEnvironment({"LANGCHAIN_PROJECT": LANGSMITH_STAGING_MODEL, "OPENAI_MODEL": LANGSMITH_STAGING_MODEL}):
|
| 119 |
+
feedback.post({"run_id": run_id, "sub_workflow": "til_analysis"})
|
| 120 |
+
return "ok"
|
| 121 |
+
|
| 122 |
+
|
| 123 |
@app.post("/v2/til_rewrite", tags=["til_readability"])
|
| 124 |
async def til_v2_rewrite_kickoff(content: List[str]) -> RewriteTilResponse:
|
| 125 |
with TemporaryEnvironment({"LANGCHAIN_PROJECT": LANGSMITH_PROD_PROJECT, "OPENAI_MODEL": LANGSMITH_PROD_MODEL}):
|
|
|
|
| 128 |
return result
|
| 129 |
|
| 130 |
|
| 131 |
+
@app.post("/v2/til_rewrite/{run_id}/feedback", tags=["til_readability"])
|
| 132 |
+
async def capture_til_v2_rewrite_feedback(run_id: UUID4, feedback: NewFeedback) -> str:
|
| 133 |
+
with TemporaryEnvironment({"LANGCHAIN_PROJECT": LANGSMITH_PROD_PROJECT, "OPENAI_MODEL": LANGSMITH_PROD_MODEL}):
|
| 134 |
+
feedback.post({"run_id": run_id, "sub_workflow": "til_understandability"})
|
| 135 |
+
return "ok"
|
| 136 |
+
|
| 137 |
+
|
| 138 |
@app.post("/staging/v2/til_rewrite", tags=["til_readability", "staging"])
|
| 139 |
async def staging_til_v2_rewrite_kickoff(content: List[str]) -> RewriteTilResponse:
|
| 140 |
with TemporaryEnvironment({"LANGCHAIN_PROJECT": LANGSMITH_STAGING_PROJECT, "OPENAI_MODEL": LANGSMITH_STAGING_MODEL}):
|
|
|
|
| 143 |
return result
|
| 144 |
|
| 145 |
|
| 146 |
+
@app.post("/staging/v2/til_rewrite/{run_id}/feedback", tags=["til_readability", "staging"])
|
| 147 |
+
async def staging_capture_til_v2_rewrite_feedback(run_id: UUID4, feedback: NewFeedback) -> str:
|
| 148 |
+
with TemporaryEnvironment({"LANGCHAIN_PROJECT": LANGSMITH_STAGING_PROJECT, "OPENAI_MODEL": LANGSMITH_STAGING_MODEL}):
|
| 149 |
+
feedback.post({"run_id": run_id, "sub_workflow": "til_understandability"})
|
| 150 |
+
return "ok"
|
| 151 |
+
|
| 152 |
+
|
| 153 |
@app.post("/v2/til_headlines", tags=["til_headlines"])
|
| 154 |
async def til_v2_suggest_headlines(content: List[str]) -> SuggestHeadlinesResponse:
|
| 155 |
with TemporaryEnvironment({"LANGCHAIN_PROJECT": LANGSMITH_PROD_PROJECT, "OPENAI_MODEL": LANGSMITH_PROD_MODEL}):
|
|
|
|
| 158 |
return result
|
| 159 |
|
| 160 |
|
| 161 |
+
@app.post("/v2/til_headlines/{run_id}/feedback", tags=["til_headlines"])
|
| 162 |
+
async def capture_til_v2_headlines(run_id: UUID4, feedback: NewFeedback) -> str:
|
| 163 |
+
with TemporaryEnvironment({"LANGCHAIN_PROJECT": LANGSMITH_PROD_PROJECT, "OPENAI_MODEL": LANGSMITH_PROD_MODEL}):
|
| 164 |
+
feedback.post({"run_id": run_id, "sub_workflow": "til_headline"})
|
| 165 |
+
return "ok"
|
| 166 |
+
|
| 167 |
+
|
| 168 |
@app.post("/staging/v2/til_headlines", tags=["til_headlines", "staging"])
|
| 169 |
async def staging_til_v2_suggest_headlines(content: List[str]) -> SuggestHeadlinesResponse:
|
| 170 |
with TemporaryEnvironment({"LANGCHAIN_PROJECT": LANGSMITH_STAGING_PROJECT, "OPENAI_MODEL": LANGSMITH_STAGING_MODEL}):
|
|
|
|
| 173 |
return result
|
| 174 |
|
| 175 |
|
| 176 |
+
@app.post("/staging/v2/til_headlines/{run_id}/feedback", tags=["til_headlines", "staging"])
|
| 177 |
+
async def staging_capture_til_v2_headlines(run_id: UUID4, feedback: NewFeedback) -> str:
|
| 178 |
+
with TemporaryEnvironment({"LANGCHAIN_PROJECT": LANGSMITH_STAGING_MODEL, "OPENAI_MODEL": LANGSMITH_STAGING_MODEL}):
|
| 179 |
+
feedback.post({"run_id": run_id, "sub_workflow": "til_headline"})
|
| 180 |
+
return "ok"
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
|
| 185 |
# Course Learn
|
| 186 |
def course_learn_suggest_expectations_logic(inputs) -> SuggestExpectationsResponse:
|
| 187 |
print("Inputs: ", inputs)
|
workflows/utils/feedback.py
CHANGED
|
@@ -20,3 +20,33 @@ def post_feedback(run_id: UUID4, feedback: Feedback):
|
|
| 20 |
source_info={"content": feedback.feedback_on},
|
| 21 |
type="api",
|
| 22 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
source_info={"content": feedback.feedback_on},
|
| 21 |
type="api",
|
| 22 |
)
|
| 23 |
+
|
| 24 |
+
## fields of inputs dict: run_id, sub_workflow
|
| 25 |
+
class NewFeedback(BaseModel):
|
| 26 |
+
metric_type: str
|
| 27 |
+
metric_score: float
|
| 28 |
+
original_content: Optional[str]
|
| 29 |
+
modified_content: Optional[str]
|
| 30 |
+
|
| 31 |
+
def post(self, inputs={}):
|
| 32 |
+
run_id = inputs["run_id"]
|
| 33 |
+
sub_workflow = inputs["sub_workflow"]
|
| 34 |
+
|
| 35 |
+
# make a call to supabase
|
| 36 |
+
self._post_to_supbase()
|
| 37 |
+
|
| 38 |
+
self._post_to_langsmith(run_id)
|
| 39 |
+
|
| 40 |
+
def _post_to_supbase(self):
|
| 41 |
+
return
|
| 42 |
+
|
| 43 |
+
def _post_to_langsmith(self, run_id: UUID4):
|
| 44 |
+
client = Client()
|
| 45 |
+
client.create_feedback(
|
| 46 |
+
str(run_id),
|
| 47 |
+
key=self.metric_type,
|
| 48 |
+
score=self.metric_score,
|
| 49 |
+
source_info={"original_content": self.original_content, "modified_content": self.modified_content},
|
| 50 |
+
type="api",
|
| 51 |
+
)
|
| 52 |
+
|