fix(etl & ocr): stabilize scud_export syntax/imports, revert to qwen2.5vl:7b-q8_0
This commit is contained in:
@@ -8,6 +8,7 @@ ROLE: Нативный оркестратор диалога, диспетчер
|
||||
===============================================================================
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
import logging
|
||||
@@ -146,6 +147,7 @@ def process_chat_message(
|
||||
f" - База знаний и регламенты -> db_get_rules\n"
|
||||
f" - Аномалии СКУД/1С -> db_get_anomalies\n"
|
||||
f" - Справка -> db_get_reference\n"
|
||||
f" - Распознавание PDF/сканов и экспорт в Word -> office_pdf_to_word\n"
|
||||
f"3. ЗАДАЧИ:\n"
|
||||
f" - При любых запросах на просмотр задач (включая опечатки вроде 'змдачи', 'таски', 'дела', 'покажи задачи') — "
|
||||
f"ТЫ ОБЯЗАН СРАЗУ ВЫЗВАТЬ db_get_tasks без лишних вопросов!\n"
|
||||
@@ -316,6 +318,46 @@ def process_chat_message(
|
||||
]
|
||||
}
|
||||
|
||||
# 4.1 Распознавание текста.
|
||||
elif fn_name == "office_pdf_to_word":
|
||||
# Извлекаем путь к файлу из сохраненных данных сессии
|
||||
attached_file_path = state_data.get("last_uploaded_filepath")
|
||||
original_name = state_data.get("last_uploaded_filename", "document.pdf")
|
||||
|
||||
# Страховочный fallback: если стейт очистился, ищем последний файл в data/uploads/
|
||||
if not attached_file_path or not os.path.exists(attached_file_path):
|
||||
from config import BASE_DIR
|
||||
uploads_dir = os.path.join(BASE_DIR, "data", "uploads")
|
||||
if os.path.exists(uploads_dir):
|
||||
files = [os.path.join(uploads_dir, f) for f in os.listdir(uploads_dir) if f.lower().endswith(".pdf")]
|
||||
if files:
|
||||
files.sort(key=os.path.getmtime, reverse=True)
|
||||
attached_file_path = files[0]
|
||||
original_name = os.path.basename(attached_file_path)
|
||||
|
||||
if not attached_file_path or not os.path.exists(attached_file_path):
|
||||
reply_text = "⚠️ Прикрепленный файл не найден. Пожалуйста, прикрепите PDF-файл к сообщению повторно."
|
||||
db_save_chat_message(session_id, "assistant", reply_text, is_ephemeral=1)[cite: 2]
|
||||
return reply_text, db_get_chat_history(session_id), None[cite: 2]
|
||||
|
||||
from services.office.service import convert_pdf_to_word_service
|
||||
office_res = convert_pdf_to_word_service(attached_file_path, original_name)
|
||||
|
||||
reply_text = (
|
||||
f"📄 **{office_res['message']}**\n\n"
|
||||
f"**Фрагмент первой страницы:**\n"
|
||||
f"```text\n{office_res['preview_text']}...\n```"
|
||||
)
|
||||
db_save_chat_message(session_id, "assistant", reply_text, is_ephemeral=0)[cite: 2]
|
||||
|
||||
action_payload = {
|
||||
"type": "FILE_DOWNLOAD_CARD",
|
||||
"filename": office_res["filename"],
|
||||
"download_url": office_res["download_url"],
|
||||
"tasks_count": f"{office_res['total_pages']} стр."
|
||||
}
|
||||
return reply_text, db_get_chat_history(session_id), action_payload[cite: 2]
|
||||
|
||||
# 5. Снапшоты СКУД
|
||||
elif fn_name == "db_get_snapshots":
|
||||
snapshots_res = db_get_snapshots(session_id=session_id, date_str=fn_args.get("date_str"), original_user_message=user_message)
|
||||
|
||||
Reference in New Issue
Block a user