Spaces:
Runtime error
Runtime error
endpoints(course_learn): Add support for expectation_revision & suggest_expectation
Browse files- endpoints.py +14 -0
- workflows/courses/expectation_revision.py +17 -9
- workflows/courses/suggest_expectations.py +19 -13
- workflows/utils/feedback.py +0 -1
endpoints.py
CHANGED
|
@@ -2,6 +2,8 @@ from dotenv import load_dotenv
|
|
| 2 |
import uvicorn
|
| 3 |
from fastapi import FastAPI, Query
|
| 4 |
from .workflows.til import TilCrew, TilFeedbackResponse
|
|
|
|
|
|
|
| 5 |
from .workflows.utils.feedback import Feedback
|
| 6 |
from fastapi.middleware.cors import CORSMiddleware
|
| 7 |
from typing import List, Optional
|
|
@@ -52,6 +54,18 @@ async def capture_feedback(run_id: UUID4, feedback: Feedback) -> str:
|
|
| 52 |
TilCrew.post_feedback(run_id=run_id, feedback=feedback)
|
| 53 |
return "ok"
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
@app.get("/healthcheck")
|
| 56 |
async def read_root():
|
| 57 |
return {"status": "ok"}
|
|
|
|
| 2 |
import uvicorn
|
| 3 |
from fastapi import FastAPI, Query
|
| 4 |
from .workflows.til import TilCrew, TilFeedbackResponse
|
| 5 |
+
from .workflows.courses.suggest_expectations import SuggestExpectations, Inputs as SuggestExpectationsInputs, Expectations, Expectation
|
| 6 |
+
from .workflows.courses.expectation_revision import ExpectationRevision, Inputs as ExpectationRevisionInputs
|
| 7 |
from .workflows.utils.feedback import Feedback
|
| 8 |
from fastapi.middleware.cors import CORSMiddleware
|
| 9 |
from typing import List, Optional
|
|
|
|
| 54 |
TilCrew.post_feedback(run_id=run_id, feedback=feedback)
|
| 55 |
return "ok"
|
| 56 |
|
| 57 |
+
@app.post("course_learn/suggest_expectations", tags=["course_learn"])
|
| 58 |
+
async def course_learn_suggest_expectations(inputs: SuggestExpectationsInputs) -> Expectations:
|
| 59 |
+
print("Inputs: ", inputs)
|
| 60 |
+
result = SuggestExpectations().kickoff(inputs=inputs)
|
| 61 |
+
return result
|
| 62 |
+
|
| 63 |
+
@app.post("course_learn/expectation_revision", tags=["course_learn"])
|
| 64 |
+
async def course_learn_suggest_expectations(inputs: ExpectationRevisionInputs) -> Expectation:
|
| 65 |
+
print("Inputs: ", inputs)
|
| 66 |
+
result = ExpectationRevision().kickoff(inputs=inputs)
|
| 67 |
+
return result
|
| 68 |
+
|
| 69 |
@app.get("/healthcheck")
|
| 70 |
async def read_root():
|
| 71 |
return {"status": "ok"}
|
workflows/courses/expectation_revision.py
CHANGED
|
@@ -1,9 +1,16 @@
|
|
| 1 |
-
from langchain_core.output_parsers import JsonOutputParser
|
| 2 |
-
from suggest_expectations import Expectation
|
| 3 |
from langchain import hub
|
|
|
|
| 4 |
from langchain_openai import ChatOpenAI
|
|
|
|
|
|
|
|
|
|
| 5 |
import os
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
class ExpectationRevision:
|
| 8 |
def kickoff(self, inputs={}):
|
| 9 |
self.learning_outcome = inputs["expectation"]
|
|
@@ -33,10 +40,11 @@ class ExpectationRevision:
|
|
| 33 |
return response
|
| 34 |
|
| 35 |
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from langchain import hub
|
| 2 |
+
from langchain_core.output_parsers import JsonOutputParser
|
| 3 |
from langchain_openai import ChatOpenAI
|
| 4 |
+
from pydantic import BaseModel
|
| 5 |
+
from workflows.courses.suggest_expectations import Expectation
|
| 6 |
+
from typing import List, Optional
|
| 7 |
import os
|
| 8 |
|
| 9 |
+
class Inputs(BaseModel):
|
| 10 |
+
expectation: str
|
| 11 |
+
check_question: str
|
| 12 |
+
request: str
|
| 13 |
+
|
| 14 |
class ExpectationRevision:
|
| 15 |
def kickoff(self, inputs={}):
|
| 16 |
self.learning_outcome = inputs["expectation"]
|
|
|
|
| 40 |
return response
|
| 41 |
|
| 42 |
|
| 43 |
+
# Example usage
|
| 44 |
+
# rework = ExpectationRevision()
|
| 45 |
+
# response = rework.kickoff(inputs={
|
| 46 |
+
# "expectation": "Recognize the importance of query rewriting and how to transform inefficient queries into more efficient ones.",
|
| 47 |
+
# "check_question": "Can you provide an example of a poorly written SQL query and demonstrate how you would rewrite it to optimize its performance?",
|
| 48 |
+
# "request": "Can you provide the poorly written SQL query that user has to rewrite"
|
| 49 |
+
# })
|
| 50 |
+
# print(response)
|
workflows/courses/suggest_expectations.py
CHANGED
|
@@ -1,10 +1,10 @@
|
|
| 1 |
-
from dotenv import load_dotenv
|
| 2 |
-
load_dotenv()
|
| 3 |
from langchain import hub
|
| 4 |
from langchain_core.output_parsers import JsonOutputParser
|
| 5 |
from langchain_openai import ChatOpenAI
|
| 6 |
from pydantic import BaseModel, Field
|
| 7 |
from typing import List
|
|
|
|
|
|
|
| 8 |
import os
|
| 9 |
|
| 10 |
class Expectation(BaseModel):
|
|
@@ -14,6 +14,11 @@ class Expectation(BaseModel):
|
|
| 14 |
class Expectations(BaseModel):
|
| 15 |
expectations: List[Expectation]
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
class SuggestExpectations:
|
| 19 |
def kickoff(self, inputs={}):
|
|
@@ -44,14 +49,15 @@ class SuggestExpectations:
|
|
| 44 |
return response
|
| 45 |
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from langchain import hub
|
| 2 |
from langchain_core.output_parsers import JsonOutputParser
|
| 3 |
from langchain_openai import ChatOpenAI
|
| 4 |
from pydantic import BaseModel, Field
|
| 5 |
from typing import List
|
| 6 |
+
from pydantic import BaseModel
|
| 7 |
+
from typing import List, Optional
|
| 8 |
import os
|
| 9 |
|
| 10 |
class Expectation(BaseModel):
|
|
|
|
| 14 |
class Expectations(BaseModel):
|
| 15 |
expectations: List[Expectation]
|
| 16 |
|
| 17 |
+
class Inputs(BaseModel):
|
| 18 |
+
course: str
|
| 19 |
+
module: str
|
| 20 |
+
tasks: List[str]
|
| 21 |
+
|
| 22 |
|
| 23 |
class SuggestExpectations:
|
| 24 |
def kickoff(self, inputs={}):
|
|
|
|
| 49 |
return response
|
| 50 |
|
| 51 |
|
| 52 |
+
# Example usage
|
| 53 |
+
# suggester = SuggestExpectations()
|
| 54 |
+
# response = suggester.kickoff(inputs={
|
| 55 |
+
# "course": "SQL",
|
| 56 |
+
# "module": "Query Optimization Techniques",
|
| 57 |
+
# "tasks": [
|
| 58 |
+
# "Watch this video https://youtu.be/BHwzDmr6d7s?si=sfFYnd73y9w0EjGB to understand SQL execution order and some optimization techniques.",
|
| 59 |
+
# "Watch this video https://youtu.be/FoznjTU929c?si=6M3xUIUwAxE6EbKS to understand SQL explain command usage.",
|
| 60 |
+
# "Go over these articles https://intellipaat.com/blog/sql-optimization-techniques/ & https://www.thoughtspot.com/data-trends/data-modeling/optimizing-sql-queries to understand various query optimization techniques."
|
| 61 |
+
# ]
|
| 62 |
+
# })
|
| 63 |
+
# print(response)
|
workflows/utils/feedback.py
CHANGED
|
@@ -2,7 +2,6 @@ from pydantic import BaseModel
|
|
| 2 |
from typing import List, Optional
|
| 3 |
|
| 4 |
class Feedback(BaseModel):
|
| 5 |
-
helpful_score: Optional[float]=None
|
| 6 |
metric_type: Optional[str]
|
| 7 |
metric_score: Optional[float]
|
| 8 |
feedback_on: Optional[str]
|
|
|
|
| 2 |
from typing import List, Optional
|
| 3 |
|
| 4 |
class Feedback(BaseModel):
|
|
|
|
| 5 |
metric_type: Optional[str]
|
| 6 |
metric_score: Optional[float]
|
| 7 |
feedback_on: Optional[str]
|