Skip to content

Commit

Permalink
Merge pull request #57 from jamakase/feature/backend-api
Browse files Browse the repository at this point in the history
add messages to ml
  • Loading branch information
anntish authored Sep 12, 2024
2 parents d938b97 + b8dc753 commit 7ea23db
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion services/backend/services/conversation_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 15 additions & 4 deletions services/backend/services/rag_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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: Результат обработки вопроса.
"""
Expand All @@ -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()
Expand Down Expand Up @@ -131,6 +141,7 @@ def run_file_question_task(file_id, file_path, question: str) -> dict:
}
}


json.dumps(result)
return result
#
Expand Down

0 comments on commit 7ea23db

Please sign in to comment.