From cc8956d96a5dfb794e4e40a47db36e8e9a731b79 Mon Sep 17 00:00:00 2001 From: Yassine Souissi Date: Tue, 9 Jul 2024 14:36:26 +0200 Subject: [PATCH 1/3] Fix Bugs fixes found on Sentry --- app/pipeline/chat/exercise_chat_pipeline.py | 2 +- app/pipeline/prompts/reranker_prompt.txt | 2 +- app/pipeline/shared/reranker_pipeline.py | 2 +- app/retrieval/lecture_retrieval.py | 5 +++-- app/web/status/status_update.py | 4 ++-- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/pipeline/chat/exercise_chat_pipeline.py b/app/pipeline/chat/exercise_chat_pipeline.py index 3f87f686..efea3d19 100644 --- a/app/pipeline/chat/exercise_chat_pipeline.py +++ b/app/pipeline/chat/exercise_chat_pipeline.py @@ -346,7 +346,7 @@ def _add_relevant_chunks_to_prompt(self, retrieved_lecture_chunks: List[dict]): ) txt += lct - self.prompt += SystemMessagePromptTemplate.from_template(txt) + self.prompt += SystemMessagePromptTemplate.from_template(txt.replace("{", "{{").replace("}", "}}")) def should_execute_lecture_pipeline(self, course_id: int) -> bool: """ diff --git a/app/pipeline/prompts/reranker_prompt.txt b/app/pipeline/prompts/reranker_prompt.txt index c682c425..7bfea83d 100644 --- a/app/pipeline/prompts/reranker_prompt.txt +++ b/app/pipeline/prompts/reranker_prompt.txt @@ -3,7 +3,7 @@ Respond with the numbers of the paragraphs you should consult to answer the ques The relevance score is a number from 1 to 10 based on how relevant the paragraphs are to answer the question. Do not include any paragraphs that are not relevant to the question. Without any comment, return the result in the following JSON format, it is important to avoid giving -unnecessary information, only the number of the paragraph if it's really necessary for answering the student's question +unnecessary information, only the number of the paragraph if it's necessary for answering the student's question otherwise leave the array empty. {{"selected_paragraphs": [, , ...]}} diff --git a/app/pipeline/shared/reranker_pipeline.py b/app/pipeline/shared/reranker_pipeline.py index 178bb4e6..0ca25819 100644 --- a/app/pipeline/shared/reranker_pipeline.py +++ b/app/pipeline/shared/reranker_pipeline.py @@ -29,7 +29,7 @@ def __init__(self): super().__init__(implementation_id="reranker_pipeline") request_handler = CapabilityRequestHandler( requirements=RequirementList( - gpt_version_equivalent=3.5, + gpt_version_equivalent=4, context_length=16385, ) ) diff --git a/app/retrieval/lecture_retrieval.py b/app/retrieval/lecture_retrieval.py index 566acb87..df832ebc 100644 --- a/app/retrieval/lecture_retrieval.py +++ b/app/retrieval/lecture_retrieval.py @@ -143,7 +143,8 @@ def __call__( selected_chunks_index = self.reranker_pipeline( paragraphs=merged_chunks, query=student_query, chat_history=chat_history ) - return [merged_chunks[int(i)] for i in selected_chunks_index] + if selected_chunks_index: + return [merged_chunks[int(i)] for i in selected_chunks_index] return [] @traceable(name="Basic Lecture Retrieval") @@ -467,7 +468,7 @@ def run_parallel_rewrite_tasks( response_future = executor.submit( self.search_in_db, query=rewritten_query, - hybrid_factor=0.7, + hybrid_factor=0.9, result_limit=result_limit, course_id=course_id, base_url=base_url, diff --git a/app/web/status/status_update.py b/app/web/status/status_update.py index 6ab91f4c..533047ca 100644 --- a/app/web/status/status_update.py +++ b/app/web/status/status_update.py @@ -127,7 +127,7 @@ def error(self, message: str, exception=None): """ self.stage.state = StageStateEnum.ERROR self.stage.message = message - self.stage.result = None + self.status.result = None self.stage.suggestions = None # Set all subsequent stages to SKIPPED if an error occurs rest_of_index = ( @@ -157,7 +157,7 @@ def skip(self, message: Optional[str] = None, start_next_stage: bool = True): """ self.stage.state = StageStateEnum.SKIPPED self.stage.message = message - self.stage.result = None + self.status.result = None self.stage.suggestions = None next_stage = self.get_next_stage() if next_stage is not None: From d598376cb203f6b77da24b1842ad1599f5ba5b0b Mon Sep 17 00:00:00 2001 From: Yassine Souissi Date: Tue, 9 Jul 2024 14:36:53 +0200 Subject: [PATCH 2/3] Lint --- app/pipeline/chat/exercise_chat_pipeline.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/pipeline/chat/exercise_chat_pipeline.py b/app/pipeline/chat/exercise_chat_pipeline.py index efea3d19..8043e9ad 100644 --- a/app/pipeline/chat/exercise_chat_pipeline.py +++ b/app/pipeline/chat/exercise_chat_pipeline.py @@ -346,7 +346,9 @@ def _add_relevant_chunks_to_prompt(self, retrieved_lecture_chunks: List[dict]): ) txt += lct - self.prompt += SystemMessagePromptTemplate.from_template(txt.replace("{", "{{").replace("}", "}}")) + self.prompt += SystemMessagePromptTemplate.from_template( + txt.replace("{", "{{").replace("}", "}}") + ) def should_execute_lecture_pipeline(self, course_id: int) -> bool: """ From b93781cf27764cd1bf3de8d66d7b0c670d28ca46 Mon Sep 17 00:00:00 2001 From: Yassine Souissi Date: Wed, 10 Jul 2024 14:08:24 +0200 Subject: [PATCH 3/3] revert gpt to 3.5 --- app/pipeline/shared/reranker_pipeline.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/pipeline/shared/reranker_pipeline.py b/app/pipeline/shared/reranker_pipeline.py index 0ca25819..178bb4e6 100644 --- a/app/pipeline/shared/reranker_pipeline.py +++ b/app/pipeline/shared/reranker_pipeline.py @@ -29,7 +29,7 @@ def __init__(self): super().__init__(implementation_id="reranker_pipeline") request_handler = CapabilityRequestHandler( requirements=RequirementList( - gpt_version_equivalent=4, + gpt_version_equivalent=3.5, context_length=16385, ) )