forked from zovos/bot_tg
update fronted and fix llm
This commit is contained in:
parent
90977abda7
commit
783b26003a
5 changed files with 49 additions and 8 deletions
3
.env
3
.env
|
|
@ -1,3 +1,6 @@
|
|||
BOT_TOKEN=8156642467:AAEalekr-33lFS3tTTkXIEiaawfDzR6lBJc
|
||||
TZ=Europe/Moscow
|
||||
ODDS_API_KEY=c29bc26dee8aa9d95a5ce8d14ea63923
|
||||
LLAMA_API_URL=https://mirror.porno4free.ru/zovos-ai/
|
||||
LLAMA_FORCE_DISABLE_THINKING=0
|
||||
LLAMA_LOG_THINKING=1
|
||||
|
|
|
|||
|
|
@ -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", "бот")
|
||||
SKIP_TOKEN = "<skip>"
|
||||
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
|
||||
SUMMARY_TRIGGER_MESSAGES = 24
|
||||
|
|
@ -614,6 +615,13 @@ async def _call_llm(
|
|||
content = message.get("content", "")
|
||||
reasoning_content = (message.get("reasoning_content") or "").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:
|
||||
retry_max_tokens = min(max(max_tokens * 2, RETRY_MIN_MAX_TOKENS), RETRY_MAX_MAX_TOKENS)
|
||||
logger.warning(
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@ docker compose down
|
|||
|
||||
Переменные окружения: задайте `BOT_TOKEN` в `.env`.
|
||||
Для ИИ-фич нужен `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).
|
||||
|
||||
Контейнер хранит состояние в `./db`:
|
||||
|
|
|
|||
|
|
@ -12,6 +12,9 @@ services:
|
|||
CHAT_HISTORY_DB_PATH: /db/chat_history.sqlite3
|
||||
POLYCHAETSI_STATS_PATH: /db/polychaetsi_stats.json
|
||||
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
|
||||
restart: unless-stopped
|
||||
|
||||
|
|
@ -30,6 +33,9 @@ services:
|
|||
POLYCHAETSI_STATS_PATH: /db/polychaetsi_stats.json
|
||||
BET_DB_PATH: /db/bets.sqlite3
|
||||
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
|
||||
|
||||
webapp-frontend:
|
||||
|
|
|
|||
|
|
@ -408,7 +408,14 @@ async def talk_api(
|
|||
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_name = user["first_name"] or "кент"
|
||||
|
|
@ -417,12 +424,27 @@ async def talk_api(
|
|||
chat_id = user_id
|
||||
|
||||
try:
|
||||
response = await _generate_response(chat_id, req.text, user_name)
|
||||
if not response:
|
||||
response = "Братуха, чёт базар не клеится."
|
||||
await asyncio.to_thread(push_message, chat_id, "user", user_name, req.text)
|
||||
await asyncio.to_thread(push_message, chat_id, "assistant", "бот", response)
|
||||
return {"response": response}
|
||||
await asyncio.to_thread(push_message, chat_id, "user", user_name, req.text, user_id=user_id)
|
||||
response = await _generate_response(
|
||||
chat_id,
|
||||
system_prompt=SYSTEM_PROMPT,
|
||||
user_id=user_id,
|
||||
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:
|
||||
logger.exception("Talk API failed")
|
||||
raise HTTPException(status_code=500, detail="LLM error")
|
||||
|
|
|
|||
Loading…
Reference in a new issue