-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9e19d18
commit bae6252
Showing
6 changed files
with
184 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from datetime import datetime | ||
from typing import Optional | ||
|
||
from pydantic import BaseModel, Field | ||
|
||
from domain.data.course_dto import CourseDTO | ||
|
||
|
||
class TextExerciseDTO(BaseModel): | ||
id: int | ||
name: str | ||
course: CourseDTO | ||
problem_statement: str = Field(alias="problemStatement") | ||
start_date: Optional[datetime] = Field(alias="startDate", default=None) | ||
end_date: Optional[datetime] = Field(alias="endDate", default=None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from pydantic import BaseModel, Field | ||
|
||
from domain import PipelineExecutionDTO | ||
from domain.data.text_exercise_dto import TextExerciseDTO | ||
|
||
|
||
class TextExerciseChatPipelineExecutionDTO(BaseModel): | ||
execution: PipelineExecutionDTO | ||
exercise: TextExerciseDTO | ||
current_answer: str = Field(alias="currentAnswer") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
def system_prompt( | ||
exercise_name: str, | ||
course_name: str, | ||
course_description: str, | ||
problem_statement: str, | ||
start_date: str, | ||
end_date: str, | ||
current_date: str, | ||
current_answer: str, | ||
) -> str: | ||
return """ | ||
The student is working on a free-response exercise called '{exercise_name}' in the course '{course_name}'. | ||
The course has the following description: | ||
{course_description} | ||
The exercise has the following problem statement: | ||
{problem_statement} | ||
The exercise began on {start_date} and will end on {end_date}. The current date is {current_date}. | ||
This is what the student has written so far: | ||
{current_answer} | ||
You are a writing tutor. Provide feedback to the student on their response, | ||
giving specific tips to better answer the problem statement. | ||
""".format( | ||
exercise_name=exercise_name, | ||
course_name=course_name, | ||
course_description=course_description, | ||
problem_statement=problem_statement, | ||
start_date=start_date, | ||
end_date=end_date, | ||
current_date=current_date, | ||
current_answer=current_answer, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import logging | ||
from datetime import datetime | ||
from typing import Optional | ||
|
||
from app.llm import CapabilityRequestHandler, RequirementList, CompletionArguments | ||
from app.pipeline import Pipeline | ||
from domain import PyrisMessage, IrisMessageRole | ||
from domain.data.text_message_content_dto import TextMessageContentDTO | ||
from domain.text_exercise_chat_pipeline_execution_dto import ( | ||
TextExerciseChatPipelineExecutionDTO, | ||
) | ||
from pipeline.prompts.text_exercise_chat_prompts import system_prompt | ||
from web.status.status_update import TextExerciseChatCallback | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class TextExerciseChatPipeline(Pipeline): | ||
callback: TextExerciseChatCallback | ||
request_handler: CapabilityRequestHandler | ||
|
||
def __init__(self, callback: Optional[TextExerciseChatCallback] = None): | ||
super().__init__(implementation_id="text_exercise_chat_pipeline_reference_impl") | ||
self.callback = callback | ||
self.request_handler = CapabilityRequestHandler( | ||
requirements=RequirementList(context_length=8000) | ||
) | ||
|
||
def __call__( | ||
self, | ||
dto: TextExerciseChatPipelineExecutionDTO, | ||
**kwargs, | ||
): | ||
if not dto.exercise: | ||
raise ValueError("Exercise is required") | ||
|
||
prompt = system_prompt( | ||
exercise_name=dto.exercise.name, | ||
course_name=dto.exercise.course.name, | ||
course_description=dto.exercise.course.description, | ||
problem_statement=dto.exercise.problem_statement, | ||
start_date=str(dto.exercise.start_date), | ||
end_date=str(dto.exercise.end_date), | ||
current_date=str(datetime.now()), | ||
current_answer=dto.current_answer, | ||
) | ||
prompt = PyrisMessage( | ||
sender=IrisMessageRole.SYSTEM, | ||
contents=[TextMessageContentDTO(text_content=prompt)], | ||
) | ||
|
||
# done building prompt | ||
|
||
response = self.request_handler.chat( | ||
[prompt], CompletionArguments(temperature=0.4) | ||
) | ||
response = response.contents[0].text_content | ||
|
||
self.callback.done(response) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters