Spaces:
Runtime error
Runtime error
workflows(courses): Add suggest_expectations & expectation_revision
Browse files
workflows/courses/expectation_revision.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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"]
|
| 10 |
+
self.check_question = inputs["check_question"]
|
| 11 |
+
self.request = inputs["request"]
|
| 12 |
+
return self._get_suggestion()
|
| 13 |
+
|
| 14 |
+
def _get_suggestion(self):
|
| 15 |
+
parser = JsonOutputParser(pydantic_object=Expectation)
|
| 16 |
+
prompt = hub.pull("course_learn_expectation_revision")
|
| 17 |
+
llm = ChatOpenAI(model=os.environ['OPENAI_MODEL'], temperature=0.2)
|
| 18 |
+
chain = (prompt | llm | parser).with_config({
|
| 19 |
+
"tags": ["course_learn", "suggest_expectations"], "run_name": "Suggest Module Expectations",
|
| 20 |
+
"metadata" : {
|
| 21 |
+
"versoin": "v1.0.0",
|
| 22 |
+
"growth_activity": "course_learn",
|
| 23 |
+
"env": os.environ["ENV"],
|
| 24 |
+
"model": os.environ["OPENAI_MODEL"],
|
| 25 |
+
}
|
| 26 |
+
})
|
| 27 |
+
|
| 28 |
+
response = chain.invoke({
|
| 29 |
+
"learning_outcome": self.learning_outcome, "check_question": self.check_question, "request": self.request,
|
| 30 |
+
"format_instructions": parser.get_format_instructions()
|
| 31 |
+
})
|
| 32 |
+
|
| 33 |
+
return response
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
rework = ExpectationRevision()
|
| 37 |
+
response = rework.kickoff(inputs={
|
| 38 |
+
"expectation": "Recognize the importance of query rewriting and how to transform inefficient queries into more efficient ones.",
|
| 39 |
+
"check_question": "Can you provide an example of a poorly written SQL query and demonstrate how you would rewrite it to optimize its performance?",
|
| 40 |
+
"request": "Can you provide the poorly written SQL query that user has to rewrite"
|
| 41 |
+
})
|
| 42 |
+
print(response)
|
workflows/courses/suggest_expectations.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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):
|
| 11 |
+
expectation: str = Field(description="The learning outcome that the course designer has identified for the learner to demonstrate upon successful completion of the module.")
|
| 12 |
+
check_question: str = Field(description="Targeted question that the course designer have developed to assess the learner's understanding of the learning outcomes.")
|
| 13 |
+
|
| 14 |
+
class Expectations(BaseModel):
|
| 15 |
+
expectations: List[Expectation]
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class SuggestExpectations:
|
| 19 |
+
def kickoff(self, inputs={}):
|
| 20 |
+
self.course = inputs["course"]
|
| 21 |
+
self.module = inputs["module"]
|
| 22 |
+
self.tasks = inputs["tasks"]
|
| 23 |
+
return self._get_suggestions()
|
| 24 |
+
|
| 25 |
+
def _get_suggestions(self):
|
| 26 |
+
parser = JsonOutputParser(pydantic_object=Expectations)
|
| 27 |
+
prompt = hub.pull("course_learn_suggest_expectations_from_learner")
|
| 28 |
+
llm = ChatOpenAI(model=os.environ['OPENAI_MODEL'], temperature=0.2)
|
| 29 |
+
chain = (prompt | llm | parser).with_config({
|
| 30 |
+
"tags": ["course_learn", "suggest_expectations"], "run_name": "Suggest Module Expectations",
|
| 31 |
+
"metadata" : {
|
| 32 |
+
"versoin": "v1.0.0",
|
| 33 |
+
"growth_activity": "course_learn",
|
| 34 |
+
"env": os.environ["ENV"],
|
| 35 |
+
"model": os.environ["OPENAI_MODEL"],
|
| 36 |
+
}
|
| 37 |
+
})
|
| 38 |
+
|
| 39 |
+
response = chain.invoke({
|
| 40 |
+
"course": self.course, "module": self.module, "tasks": "* " + ("\n* ".join(self.tasks)),
|
| 41 |
+
"format_instructions": parser.get_format_instructions()
|
| 42 |
+
})
|
| 43 |
+
|
| 44 |
+
return response
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
suggester = SuggestExpectations()
|
| 48 |
+
response = suggester.kickoff(inputs={
|
| 49 |
+
"course": "SQL",
|
| 50 |
+
"module": "Query Optimization Techniques",
|
| 51 |
+
"tasks": [
|
| 52 |
+
"Watch this video https://youtu.be/BHwzDmr6d7s?si=sfFYnd73y9w0EjGB to understand SQL execution order and some optimization techniques.",
|
| 53 |
+
"Watch this video https://youtu.be/FoznjTU929c?si=6M3xUIUwAxE6EbKS to understand SQL explain command usage.",
|
| 54 |
+
"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."
|
| 55 |
+
]
|
| 56 |
+
})
|
| 57 |
+
print(response)
|