-
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.
Add inconsistency check pipeline (#197)
- Loading branch information
1 parent
3eeab7f
commit d37f5c4
Showing
8 changed files
with
222 additions
and
28 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from pydantic import BaseModel | ||
|
||
from . import PipelineExecutionDTO | ||
from .data.programming_exercise_dto import ProgrammingExerciseDTO | ||
|
||
|
||
class InconsistencyCheckPipelineExecutionDTO(BaseModel): | ||
execution: PipelineExecutionDTO | ||
exercise: ProgrammingExerciseDTO |
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,5 @@ | ||
from app.domain.status.status_update_dto import StatusUpdateDTO | ||
|
||
|
||
class InconsistencyCheckStatusUpdateDTO(StatusUpdateDTO): | ||
result: str = "" |
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,71 @@ | ||
import logging | ||
from typing import Optional | ||
|
||
from langchain_core.output_parsers import StrOutputParser | ||
from langchain_core.prompts import PromptTemplate | ||
from langchain_core.runnables import Runnable | ||
from langsmith import traceable | ||
|
||
from app.common.PipelineEnum import PipelineEnum | ||
from app.domain import InconsistencyCheckPipelineExecutionDTO | ||
from app.llm import CapabilityRequestHandler, RequirementList, CompletionArguments | ||
from app.llm.langchain.iris_langchain_chat_model import IrisLangchainChatModel | ||
from app.pipeline import Pipeline | ||
from app.web.status.status_update import InconsistencyCheckCallback | ||
from app.pipeline.prompts.inconsistency_check_prompts import basic_prompt | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class InconsistencyCheckPipeline(Pipeline): | ||
pipeline: Runnable | ||
llm: IrisLangchainChatModel | ||
callback: InconsistencyCheckCallback | ||
|
||
def __init__(self, callback: Optional[InconsistencyCheckCallback] = None): | ||
super().__init__(implementation_id="inconsistency_check_pipeline") | ||
completion_args = CompletionArguments(temperature=0, max_tokens=2000) | ||
self.llm = IrisLangchainChatModel( | ||
request_handler=CapabilityRequestHandler( | ||
requirements=RequirementList( | ||
gpt_version_equivalent=4.5, | ||
context_length=16385, | ||
) | ||
), | ||
completion_args=completion_args, | ||
) | ||
self.prompt = PromptTemplate.from_template(basic_prompt) | ||
self.pipeline = self.prompt | self.llm | StrOutputParser() | ||
self.callback = callback | ||
self.tokens = [] | ||
|
||
@traceable(name="Inconsistency Check Pipeline") | ||
def __call__(self, dto: InconsistencyCheckPipelineExecutionDTO, **kwargs): | ||
""" | ||
Runs the pipeline to check for inconsistencies in the exercise | ||
:param dto: execution data transfer object | ||
:param kwargs: The keyword arguments | ||
""" | ||
|
||
if not dto.exercise: | ||
logger.error("Inconsistency check pipeline requires an exercise") | ||
raise ValueError("Exercise is required") | ||
|
||
logger.info("Running inconsistency check pipeline...") | ||
self.callback.in_progress() | ||
|
||
template_repository = "\n".join( | ||
f"<File path='{file_path}'>\n{file_content}</File>" | ||
for file_path, file_content in dto.exercise.template_repository.items() | ||
) | ||
|
||
response: str = self.pipeline.invoke( | ||
{ | ||
"problem_statement": dto.exercise.problem_statement, | ||
"template_repository": template_repository, | ||
} | ||
) | ||
|
||
self._append_tokens(self.llm.tokens, PipelineEnum.IRIS_INCONSISTENCY_CHECK) | ||
|
||
self.callback.done(final_result=response, tokens=self.tokens) |
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,34 @@ | ||
basic_prompt = """\ | ||
<Instruction> | ||
As detail-oriented expert, find inconsistencies between the provided problem statement and the template repository of \ | ||
a programming exercise. | ||
The student will use the the template repository to write code that solves the problem statement. | ||
Checks: | ||
- Given the problem statement, identify any missing or incorrect information in the template repository. | ||
- Given the template repository, identify any missing or incorrect information in the problem statement. | ||
- Ensure that the theme of the problem statement is consistent with the template repository. | ||
- Ensure that the problem statement is clear and concise and it covers everything that the student needs to know in \ | ||
order to solve the exercise. | ||
It is not an inconsistency, if the problem statement clearly states that the student is responsible for writing a \ | ||
specific part of the code. | ||
</Instruction> | ||
<Problem Statement> | ||
{problem_statement} | ||
</Problem Statement> | ||
<TemplateRepository> | ||
{template_repository} | ||
</TemplateRepository> | ||
<Response> | ||
Be smart about it, give a structured and actionable response that an instructor can use to significantly improve the \ | ||
exercise. Clearly state where the inconsistency lies. Do not make up inconsistencies just to have something to say. | ||
It needs to be very comprehensive and detailed, imagine some inconsistencies slipped through, students in the exam \ | ||
will be confused and frustrated. This is a high stakes exam, so we need to be very thorough. | ||
You will be legally responsible for the quality of the exercise, so make sure you do the absolute best job possible, \ | ||
otherwise you will be held accountable in the court of law. Do not quote whole files! 🔫 | ||
</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