Бот работает
This commit is contained in:
@@ -25,7 +25,7 @@ from rag_agent.index.postgres import (
|
||||
update_story_indexed_range,
|
||||
upsert_document,
|
||||
)
|
||||
from rag_agent.agent.pipeline import StubLLMClient, answer_query
|
||||
from rag_agent.agent.pipeline import answer_query, get_llm_client
|
||||
|
||||
|
||||
def _file_version(path: Path) -> str:
|
||||
@@ -55,13 +55,24 @@ def cmd_index(args: argparse.Namespace) -> None:
|
||||
existing = filter_existing(changed_files)
|
||||
else:
|
||||
removed = []
|
||||
existing = [
|
||||
p for p in Path(config.repo_path).rglob("*") if p.is_file()
|
||||
]
|
||||
repo_path = Path(config.repo_path)
|
||||
if not repo_path.exists():
|
||||
raise SystemExit(f"RAG_REPO_PATH does not exist: {config.repo_path}")
|
||||
existing = [p for p in repo_path.rglob("*") if p.is_file()]
|
||||
|
||||
allowed = list(iter_text_files(existing, config.allowed_extensions))
|
||||
print(
|
||||
f"repo={config.repo_path} all_files={len(existing)} "
|
||||
f"allowed={len(allowed)} ext={config.allowed_extensions}"
|
||||
)
|
||||
if not allowed:
|
||||
print("No files to index (check path and extensions .md, .txt, .rst)")
|
||||
return
|
||||
|
||||
for path in removed:
|
||||
delete_document(conn, story_id, str(path))
|
||||
|
||||
indexed = 0
|
||||
for path, text in iter_text_files(existing, config.allowed_extensions):
|
||||
chunks = chunk_text_by_lines(
|
||||
text,
|
||||
@@ -88,11 +99,18 @@ def cmd_index(args: argparse.Namespace) -> None:
|
||||
replace_chunks(
|
||||
conn, document_id, chunks, embeddings, base_chunks=base_chunks
|
||||
)
|
||||
indexed += 1
|
||||
|
||||
print(f"Indexed {indexed} documents for story={args.story}")
|
||||
if args.changed:
|
||||
update_story_indexed_range(conn, story_id, base_ref, head_ref)
|
||||
|
||||
|
||||
def cmd_bot(args: argparse.Namespace) -> None:
|
||||
from rag_agent.telegram_bot import main as bot_main
|
||||
bot_main()
|
||||
|
||||
|
||||
def cmd_serve(args: argparse.Namespace) -> None:
|
||||
import uvicorn
|
||||
uvicorn.run(
|
||||
@@ -113,7 +131,7 @@ def cmd_ask(args: argparse.Namespace) -> None:
|
||||
if story_id is None:
|
||||
raise SystemExit(f"Story not found: {args.story}")
|
||||
embedding_client = get_embedding_client(config.embeddings_dim)
|
||||
llm_client = StubLLMClient()
|
||||
llm_client = get_llm_client(config)
|
||||
answer = answer_query(
|
||||
conn,
|
||||
config,
|
||||
@@ -185,6 +203,12 @@ def build_parser() -> argparse.ArgumentParser:
|
||||
)
|
||||
serve_parser.set_defaults(func=cmd_serve)
|
||||
|
||||
bot_parser = sub.add_parser(
|
||||
"bot",
|
||||
help="Run Telegram bot: answers questions using RAG (requires TELEGRAM_BOT_TOKEN)",
|
||||
)
|
||||
bot_parser.set_defaults(func=cmd_bot)
|
||||
|
||||
return parser
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user