theRealNG commited on
Commit
d34b62b
·
unverified ·
2 Parent(s): a4d4feb3d8743c

Merge pull request #23 from beautiful-code/course_lessons_extraction

Browse files
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 ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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"]
17
+ self.check_question = inputs["check_question"]
18
+ self.request = inputs["request"]
19
+ return self._get_suggestion()
20
+
21
+ def _get_suggestion(self):
22
+ parser = JsonOutputParser(pydantic_object=Expectation)
23
+ prompt = hub.pull("course_learn_expectation_revision")
24
+ llm = ChatOpenAI(model=os.environ['OPENAI_MODEL'], temperature=0.2)
25
+ chain = (prompt | llm | parser).with_config({
26
+ "tags": ["course_learn", "suggest_expectations"], "run_name": "Suggest Module Expectations",
27
+ "metadata" : {
28
+ "versoin": "v1.0.0",
29
+ "growth_activity": "course_learn",
30
+ "env": os.environ["ENV"],
31
+ "model": os.environ["OPENAI_MODEL"],
32
+ }
33
+ })
34
+
35
+ response = chain.invoke({
36
+ "learning_outcome": self.learning_outcome, "check_question": self.check_question, "request": self.request,
37
+ "format_instructions": parser.get_format_instructions()
38
+ })
39
+
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 ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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):
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
+ class Inputs(BaseModel):
18
+ course: str
19
+ module: str
20
+ tasks: List[str]
21
+
22
+
23
+ class SuggestExpectations:
24
+ def kickoff(self, inputs={}):
25
+ self.course = inputs["course"]
26
+ self.module = inputs["module"]
27
+ self.tasks = inputs["tasks"]
28
+ return self._get_suggestions()
29
+
30
+ def _get_suggestions(self):
31
+ parser = JsonOutputParser(pydantic_object=Expectations)
32
+ prompt = hub.pull("course_learn_suggest_expectations_from_learner")
33
+ llm = ChatOpenAI(model=os.environ['OPENAI_MODEL'], temperature=0.2)
34
+ chain = (prompt | llm | parser).with_config({
35
+ "tags": ["course_learn", "suggest_expectations"], "run_name": "Suggest Module Expectations",
36
+ "metadata" : {
37
+ "versoin": "v1.0.0",
38
+ "growth_activity": "course_learn",
39
+ "env": os.environ["ENV"],
40
+ "model": os.environ["OPENAI_MODEL"],
41
+ }
42
+ })
43
+
44
+ response = chain.invoke({
45
+ "course": self.course, "module": self.module, "tasks": "* " + ("\n* ".join(self.tasks)),
46
+ "format_instructions": parser.get_format_instructions()
47
+ })
48
+
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]