1
0
Fork 0
forked from zovos/bot_tg

update fronted and fix llm

This commit is contained in:
q 2026-04-12 13:14:00 +03:00
parent 90977abda7
commit 783b26003a
5 changed files with 49 additions and 8 deletions

5
.env
View file

@ -1,3 +1,6 @@
BOT_TOKEN=8156642467:AAEalekr-33lFS3tTTkXIEiaawfDzR6lBJc BOT_TOKEN=8156642467:AAEalekr-33lFS3tTTkXIEiaawfDzR6lBJc
TZ=Europe/Moscow TZ=Europe/Moscow
ODDS_API_KEY=c29bc26dee8aa9d95a5ce8d14ea63923 ODDS_API_KEY=c29bc26dee8aa9d95a5ce8d14ea63923
LLAMA_API_URL=https://mirror.porno4free.ru/zovos-ai/
LLAMA_FORCE_DISABLE_THINKING=0
LLAMA_LOG_THINKING=1

View file

@ -24,6 +24,7 @@ DB_PATH = os.getenv("CHAT_HISTORY_DB_PATH") or str(Path(__file__).resolve().with
BOT_MEMORY_NAME = os.getenv("BOT_MEMORY_NAME", "бот") BOT_MEMORY_NAME = os.getenv("BOT_MEMORY_NAME", "бот")
SKIP_TOKEN = "<skip>" SKIP_TOKEN = "<skip>"
FORCE_DISABLE_THINKING = os.getenv("LLAMA_FORCE_DISABLE_THINKING", "1").lower() not in {"0", "false", "no"} FORCE_DISABLE_THINKING = os.getenv("LLAMA_FORCE_DISABLE_THINKING", "1").lower() not in {"0", "false", "no"}
LOG_THINKING = os.getenv("LLAMA_LOG_THINKING", "1").lower() not in {"0", "false", "no"}
RECENT_MESSAGES_LIMIT = 14 RECENT_MESSAGES_LIMIT = 14
SUMMARY_TRIGGER_MESSAGES = 24 SUMMARY_TRIGGER_MESSAGES = 24
@ -614,6 +615,13 @@ async def _call_llm(
content = message.get("content", "") content = message.get("content", "")
reasoning_content = (message.get("reasoning_content") or "").strip() reasoning_content = (message.get("reasoning_content") or "").strip()
cleaned_content = content.strip() cleaned_content = content.strip()
if reasoning_content and LOG_THINKING:
logger.info(
"LLM reasoning detected. disable_thinking=%s finish_reason=%s reasoning=%s",
disable_thinking,
finish_reason,
_clip_text(reasoning_content, 800),
)
if not cleaned_content and reasoning_content and not disable_thinking: if not cleaned_content and reasoning_content and not disable_thinking:
retry_max_tokens = min(max(max_tokens * 2, RETRY_MIN_MAX_TOKENS), RETRY_MAX_MAX_TOKENS) retry_max_tokens = min(max(max_tokens * 2, RETRY_MIN_MAX_TOKENS), RETRY_MAX_MAX_TOKENS)
logger.warning( logger.warning(

View file

@ -32,6 +32,8 @@ docker compose down
Переменные окружения: задайте `BOT_TOKEN` в `.env`. Переменные окружения: задайте `BOT_TOKEN` в `.env`.
Для ИИ-фич нужен `LLAMA_API_URL`. Для ИИ-фич нужен `LLAMA_API_URL`.
По умолчанию проект настроен на `https://mirror.porno4free.ru/zovos-ai/`.
Если нужен лог reasoning/thinking модели, оставь `LLAMA_LOG_THINKING=1`; чтобы модель не резалась в режим без thinking, задай `LLAMA_FORCE_DISABLE_THINKING=0`.
Для ставок нужен `ODDS_API_KEY` (бесплатно на https://the-odds-api.com). Для ставок нужен `ODDS_API_KEY` (бесплатно на https://the-odds-api.com).
Контейнер хранит состояние в `./db`: Контейнер хранит состояние в `./db`:

View file

@ -12,6 +12,9 @@ services:
CHAT_HISTORY_DB_PATH: /db/chat_history.sqlite3 CHAT_HISTORY_DB_PATH: /db/chat_history.sqlite3
POLYCHAETSI_STATS_PATH: /db/polychaetsi_stats.json POLYCHAETSI_STATS_PATH: /db/polychaetsi_stats.json
BET_DB_PATH: /db/bets.sqlite3 BET_DB_PATH: /db/bets.sqlite3
LLAMA_API_URL: ${LLAMA_API_URL:-https://mirror.porno4free.ru/zovos-ai/}
LLAMA_FORCE_DISABLE_THINKING: ${LLAMA_FORCE_DISABLE_THINKING:-0}
LLAMA_LOG_THINKING: ${LLAMA_LOG_THINKING:-1}
init: true init: true
restart: unless-stopped restart: unless-stopped
@ -30,6 +33,9 @@ services:
POLYCHAETSI_STATS_PATH: /db/polychaetsi_stats.json POLYCHAETSI_STATS_PATH: /db/polychaetsi_stats.json
BET_DB_PATH: /db/bets.sqlite3 BET_DB_PATH: /db/bets.sqlite3
API_PORT: "8080" API_PORT: "8080"
LLAMA_API_URL: ${LLAMA_API_URL:-https://mirror.porno4free.ru/zovos-ai/}
LLAMA_FORCE_DISABLE_THINKING: ${LLAMA_FORCE_DISABLE_THINKING:-0}
LLAMA_LOG_THINKING: ${LLAMA_LOG_THINKING:-1}
restart: unless-stopped restart: unless-stopped
webapp-frontend: webapp-frontend:

View file

@ -408,7 +408,14 @@ async def talk_api(
user: dict = Depends(get_current_user), user: dict = Depends(get_current_user),
): ):
"""Отправить сообщение ИИ.""" """Отправить сообщение ИИ."""
from AI.talk_handler import _generate_response, push_message from AI.talk_handler import (
BOT_MEMORY_NAME,
EMPTY_RESPONSE_TEXT,
SYSTEM_PROMPT,
_generate_response,
_normalize_reply,
push_message,
)
user_id = user["user_id"] user_id = user["user_id"]
user_name = user["first_name"] or "кент" user_name = user["first_name"] or "кент"
@ -417,12 +424,27 @@ async def talk_api(
chat_id = user_id chat_id = user_id
try: try:
response = await _generate_response(chat_id, req.text, user_name) await asyncio.to_thread(push_message, chat_id, "user", user_name, req.text, user_id=user_id)
if not response: response = await _generate_response(
response = "Братуха, чёт базар не клеится." chat_id,
await asyncio.to_thread(push_message, chat_id, "user", user_name, req.text) system_prompt=SYSTEM_PROMPT,
await asyncio.to_thread(push_message, chat_id, "assistant", "бот", response) user_id=user_id,
return {"response": response} max_tokens=220,
temperature=0.8,
top_p=0.9,
)
normalized_response = _normalize_reply(response)
if not normalized_response:
normalized_response = EMPTY_RESPONSE_TEXT
await asyncio.to_thread(
push_message,
chat_id,
"assistant",
BOT_MEMORY_NAME,
normalized_response,
user_id=user_id,
)
return {"response": normalized_response}
except Exception: except Exception:
logger.exception("Talk API failed") logger.exception("Talk API failed")
raise HTTPException(status_code=500, detail="LLM error") raise HTTPException(status_code=500, detail="LLM error")