diff --git a/services/backend/services/conversation_service.py b/services/backend/services/conversation_service.py index 7d85482..7a49af3 100644 --- a/services/backend/services/conversation_service.py +++ b/services/backend/services/conversation_service.py @@ -68,7 +68,7 @@ def handle_message(self, text: str) -> str: :return: Идентификатор задачи, созданной для обработки сообщения. """ - task_id = RagService.create_task(text) + task_id = RagService.create_task(self.model.id, text) MessageService.save_message( SaveMessageOptions(text = text, task_id = task_id, conversation_id = self.model.id, role = Role.USER) diff --git a/services/backend/services/rag_service.py b/services/backend/services/rag_service.py index c3ad08a..0db93be 100644 --- a/services/backend/services/rag_service.py +++ b/services/backend/services/rag_service.py @@ -58,15 +58,16 @@ def on_success(self, retval, task_id, args, kwargs): class RagService: @staticmethod - def create_task(question: str) -> str: + def create_task(conversation_id, question: str) -> str: """ Создает задачу для обработки вопроса. + :param conversation_id: Идентификатор беседы. :param question: Вопрос для обработки. :return: Идентификатор созданной задачи. """ - return run_question_task.delay(question).id + return run_question_task.delay(conversation_id, question).id @staticmethod def create_file_question_task(file: FileModel, question: str) -> str: @@ -83,10 +84,11 @@ def create_file_question_task(file: FileModel, question: str) -> str: @shared_task(base = QuestionTask,ignore_result=False) -def run_question_task(question: str): +def run_question_task(conversation_id, question: str): """ Обрабатывает вопрос. + :param conversation_id: Идентификатор беседы. :param question: Вопрос для обработки. :return: Результат обработки вопроса. """ @@ -98,7 +100,15 @@ def run_question_task(question: str): "context": "Контекст" } } - response = requests.post(rag_url, json=data) + + all_messages = MessageService.get_message(conversation_id) + + query = { + "data": data, + "messages": all_messages + } + + response = requests.post(rag_url, json=query) response.raise_for_status() result = response.json() @@ -131,6 +141,7 @@ def run_file_question_task(file_id, file_path, question: str) -> dict: } } + json.dumps(result) return result #