Spaces:
Runtime error
Runtime error
| from langchain import hub | |
| from langchain_core.output_parsers import JsonOutputParser | |
| from langchain_openai import ChatOpenAI | |
| from pydantic import BaseModel, Field | |
| from typing import List | |
| from pydantic import BaseModel | |
| from typing import List, Optional | |
| import os | |
| class Expectation(BaseModel): | |
| expectation: str = Field(description="The learning outcome that the course designer has identified for the learner to demonstrate upon successful completion of the module.") | |
| check_question: str = Field(description="Targeted question that the course designer have developed to assess the learner's understanding of the learning outcomes.") | |
| class Expectations(BaseModel): | |
| expectations: List[Expectation] | |
| class Inputs(BaseModel): | |
| course: str | |
| module: str | |
| tasks: List[str] | |
| class SuggestExpectations: | |
| def kickoff(self, inputs={}): | |
| self.course = inputs["course"] | |
| self.module = inputs["module"] | |
| self.tasks = inputs["tasks"] | |
| return self._get_suggestions() | |
| def _get_suggestions(self): | |
| parser = JsonOutputParser(pydantic_object=Expectations) | |
| prompt = hub.pull("course_learn_suggest_expectations_from_learner") | |
| llm = ChatOpenAI(model=os.environ['OPENAI_MODEL'], temperature=0.2) | |
| chain = (prompt | llm | parser).with_config({ | |
| "tags": ["course_learn", "suggest_expectations"], "run_name": "Suggest Module Expectations", | |
| "metadata" : { | |
| "versoin": "v1.0.0", | |
| "growth_activity": "course_learn", | |
| "env": os.environ["ENV"], | |
| "model": os.environ["OPENAI_MODEL"], | |
| } | |
| }) | |
| response = chain.invoke({ | |
| "course": self.course, "module": self.module, "tasks": "* " + ("\n* ".join(self.tasks)), | |
| "format_instructions": parser.get_format_instructions() | |
| }) | |
| return response | |
| # Example usage | |
| # suggester = SuggestExpectations() | |
| # response = suggester.kickoff(inputs={ | |
| # "course": "SQL", | |
| # "module": "Query Optimization Techniques", | |
| # "tasks": [ | |
| # "Watch this video https://youtu.be/BHwzDmr6d7s?si=sfFYnd73y9w0EjGB to understand SQL execution order and some optimization techniques.", | |
| # "Watch this video https://youtu.be/FoznjTU929c?si=6M3xUIUwAxE6EbKS to understand SQL explain command usage.", | |
| # "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." | |
| # ] | |
| # }) | |
| # print(response) | |