Update 6 files
- /rag/history_manager.py - /rag/query_processor.py - /rag/rag_orchestrator.py - /rag/rag_api.py - /rag/rag_server.py - /rag/__init__.py
This commit is contained in:
@@ -13,10 +13,11 @@
|
||||
import logging
|
||||
from typing import List, Dict, Optional, Any
|
||||
|
||||
from core.services.postgres_service import PostgresService
|
||||
from core.services.giga_client import GigaClient
|
||||
from core.utils.text_utils import count_tokens
|
||||
from core.functions.hierarchical_summarize import hierarchical_summarize
|
||||
from rag.services.postgres_service import PostgresService
|
||||
from rag.services.giga_client import GigaClient
|
||||
from rag.utils.text_utils import count_tokens
|
||||
from rag.functions.hierarchical_summarize import hierarchical_summarize
|
||||
from rag.config_models import AppConfig
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -30,7 +31,7 @@ class HistoryManager:
|
||||
self,
|
||||
db: PostgresService,
|
||||
giga: GigaClient,
|
||||
config,
|
||||
config: AppConfig,
|
||||
default_prompts: Optional[Dict[str, str]] = None
|
||||
):
|
||||
"""
|
||||
@@ -39,7 +40,7 @@ class HistoryManager:
|
||||
Аргументы:
|
||||
db: сервис PostgreSQL (для получения и сохранения истории)
|
||||
giga: клиент GigaChat (для сжатия истории)
|
||||
config: объект конфигурации (BotConfig)
|
||||
config: объект конфигурации (AppConfig)
|
||||
default_prompts: словарь промптов по умолчанию (нужен для hierarchical_summary)
|
||||
"""
|
||||
self.db = db
|
||||
@@ -47,10 +48,6 @@ class HistoryManager:
|
||||
self.config = config
|
||||
self.default_prompts = default_prompts or {}
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Получение и форматирование истории
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
async def get_history(
|
||||
self,
|
||||
user_jid: str,
|
||||
@@ -116,7 +113,7 @@ class HistoryManager:
|
||||
if not prompt_template:
|
||||
# Пытаемся загрузить из файла, если он есть
|
||||
try:
|
||||
prompt_path = self.config.prompts_dir / 'hierarchical_summary.txt'
|
||||
prompt_path = self.config.prompts_dir_path / 'hierarchical_summary.txt'
|
||||
with open(prompt_path, 'r', encoding='utf-8') as f:
|
||||
prompt_template = f.read()
|
||||
except Exception as e:
|
||||
@@ -130,11 +127,11 @@ class HistoryManager:
|
||||
)
|
||||
|
||||
# Параметры сжатия из конфига
|
||||
summarization_config = getattr(self.config, 'summarization', {})
|
||||
target_tokens = summarization_config.get('target_tokens_after_summary', max_tokens)
|
||||
chunk_size = summarization_config.get('chunk_size_tokens', 500)
|
||||
max_depth = summarization_config.get('max_depth', 2)
|
||||
temperature = getattr(self.config, 'ai_temperature', 0.1)
|
||||
summarization_config = self.config.summarization
|
||||
target_tokens = summarization_config.target_tokens_after_summary
|
||||
chunk_size = summarization_config.chunk_size_tokens
|
||||
max_depth = summarization_config.max_depth
|
||||
temperature = self.config.ai.temperature
|
||||
|
||||
try:
|
||||
compressed_text = await hierarchical_summarize(
|
||||
|
||||
Reference in New Issue
Block a user