{"id":377878,"date":"2024-06-03T09:00:33","date_gmt":"2024-06-03T09:00:33","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=377878"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2024-06-03T09:00:33","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=377878","title":{"rendered":"<span>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 AI \u0447\u0430\u0442-\u0431\u043e\u0442 Telegram \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Ollama \u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0441\u0442\u0440\u043e\u043a \u043a\u043e\u0434\u0430 \u043d\u0430 Python<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0427\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u0435\u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e \u0447\u0430\u0442-\u0431\u043e\u0442\u0430 \u0434\u043b\u044f Telegram, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043b\u0443\u0447\u0438\u0442 \u043c\u043e\u0449\u044c LLM llama3 \u0432\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0448\u0430\u0433\u043e\u0432. \u0412\u0441\u0435 \u0431\u0443\u0434\u0435\u043c \u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043e\u0434 Ubuntu 22.04 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c GPU NVIDIA (\u043f\u043e\u0434\u043e\u0439\u0434\u0443\u0442 \u043c\u043e\u0434\u0435\u043b\u0438 RTX2xxx \u0438 \u043d\u043e\u0432\u0435\u0435 \u043e\u0442 8 \u0413\u0431 \u0432\u0438\u0434\u0435\u043e\u043f\u0430\u043c\u044f\u0442\u0438). \u0422\u0430\u043a\u0436\u0435 \u0443\u0431\u0435\u0434\u0438\u0442\u0435\u0441\u044c, \u0447\u0442\u043e \u0443 \u0432\u0430\u0441 \u043d\u0430 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0435 \u043c\u0438\u043d\u0438\u043c\u0443\u043c 16 \u0413\u0431 \u041e\u0417\u0423.<\/p>\n<p>\u041f\u0435\u0440\u0435\u0434 \u043d\u0430\u0447\u0430\u043b\u043e\u043c \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u044c\u0442\u0435, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u044b \u043b\u0438 \u0443 \u0432\u0430\u0441 \u0434\u0440\u0430\u0439\u0432\u0435\u0440\u0430 \u043e\u0442 Nvidia \u0438 CUDA \u0432\u043e\u0442\u00a0<a href=\"https:\/\/dzen.ru\/away?to=https%3A%2F%2Fhostkey.ru%2Fdocumentation%2Ftechnical%2Fgpu%2Fnvidia_gpu_linux%2F\">\u043f\u043e \u044d\u0442\u043e\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438<\/a>.<\/p>\n<h3>\u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c Ollama<\/h3>\n<ol>\n<li>\n<p>\u0421\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u0438 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c Ollama<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"bash\">curl -L https:\/\/ollama.com\/download\/ollama-linux-amd64 -o \/usr\/bin\/ollama chmod +x \/usr\/bin\/ollama sudo useradd -r -s \/bin\/false -m -d \/usr\/share\/ollama ollama<\/code><\/pre>\n<ol start=\"2\">\n<li>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c Ollama \u043a\u0430\u043a \u0441\u0435\u0440\u0432\u0438\u0441. \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0430\u0439\u043b \u0441\u0435\u0440\u0432\u0438\u0441\u0430:<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"bash\">tee \/usr\/lib\/systemd\/system\/ollama.service > \/dev\/null &lt;&lt;EOF [Unit] Description=Ollama Service After=network-online.target  [Service] ExecStart=\/usr\/bin\/ollama serve User=ollama Group=ollama Restart=always RestartSec=3 Environment=\"OLLAMA_HOST=0.0.0.0\" Environment=\"OLLAMA_ORIGINS=*\"  [Install] WantedBy=default.target EOF<\/code><\/pre>\n<ol start=\"3\">\n<li>\n<p>\u0412\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0441\u0435\u0440\u0432\u0438\u0441 ollama:<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"bash\">sudo systemctl daemon-reload sudo systemctl enable ollama sudo systemctl start ollama<\/code><\/pre>\n<ol start=\"4\">\n<li>\n<p>\u0421\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u044c\u00a0<strong>llama3:8b<\/strong><\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"bash\">ollama run llama3 | exit<\/code><\/pre>\n<blockquote>\n<p>\u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u043a\u0430\u0447\u0430\u0442\u044c \u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043b\u044e\u0431\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 Ollama, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 Phi3 \u0438\u043b\u0438 Codestral. \u041f\u043e\u043b\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <a href=\"https:\/\/ollama.com\/library\">\u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435<\/a>. \u0410 \u043d\u0430\u0436\u0430\u0432 \u043d\u0430 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c, \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0442\u0430\u043a\u0436\u0435 \u0435\u0435 \u0440\u0430\u0437\u043c\u0435\u0440, \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0438 \u0442\u0438\u043f.<\/p>\n<\/blockquote>\n<ol start=\"5\">\n<li>\n<p>\u041f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0441\u0435\u0440\u0432\u0438\u0441:<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"bash\">ollama run llama3 | exit<\/code><\/pre>\n<h3>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0447\u0430\u0442-\u0431\u043e\u0442<\/h3>\n<p>1. \u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c Python 3.10:<\/p>\n<pre><code class=\"bash\">sudo apt install python3.10<\/code><\/pre>\n<p>2. \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0435 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435:<\/p>\n<pre><code class=\"bash\">python3 -m venv venv<\/code><\/pre>\n<p>3. \u0410\u043a\u0442\u0438\u0432\u0438\u0440\u0443\u0435\u043c \u0434\u0430\u043d\u043d\u043e\u0435 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435:<\/p>\n<pre><code class=\"bash\">source venv\/bin\/activate<\/code><\/pre>\n<p>\u041f\u0440\u0438 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0439 \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u0438 \u0432 \u0441\u0442\u0440\u043e\u043a\u0435 \u043f\u0440\u0438\u0433\u043b\u0430\u0448\u0435\u043d\u0438\u044f \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u0438\u043c\u044f \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u0432 \u0441\u043a\u043e\u0431\u043a\u0430\u0445:<\/p>\n<pre><code class=\"bash\">(venv) user@you_server:~$<\/code><\/pre>\n<p>4. \u0421\u0442\u0430\u0432\u0438\u043c \u0432 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438:<\/p>\n<pre><code class=\"bash\">pip install python-telegram-bot ollama nest_asyncio<\/code><\/pre>\n<p>8. \u0417\u0430\u0445\u043e\u0434\u0438\u043c \u043d\u0430\u00a0<a href=\"https:\/\/dzen.ru\/away?to=https%3A%2F%2Ft.me%2FBotFather\">https:\/\/t.me\/BotFather<\/a>\u00a0, \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0431\u043e\u0442\u0430 \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0435\u0433\u043e \u0442\u043e\u043a\u0435\u043d.<\/p>\n<p>9. \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0430\u0439\u043b\u00a0<em>bot.py<\/em>\u00a0\u0441\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435\u043c (\u043c\u043e\u0436\u043d\u043e \u0432 \u043a\u043e\u0440\u043d\u0435 \u0432\u0430\u0448\u0435\u0439 \u0434\u043e\u043c\u0430\u0448\u043d\u0435\u0439 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438). \u0414\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0447\u0430\u0442-\u0431\u043e\u0442\u0443 \u0432 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435, \u043e\u0431\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u043d\u0430 8 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439:<\/p>\n<pre><code class=\"python\">import logging from telegram import Update from telegram.ext import ApplicationBuilder, CommandHandler, MessageHandler, filters import ollama import nest_asyncio  nest_asyncio.apply()  # \u0412\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0436\u0443\u0440\u043d\u0430\u043b\u0430 logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)  # \u0422\u043e\u043a\u0435\u043d, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u043e\u0442 @BotFather TOKEN = 'YOU_TELEGRAM_BOT_TOKEN'  # Replace with your actual token  # \u0421\u043b\u043e\u0432\u0430\u0440\u044c \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 user_ids = {} context_memory = {}  # \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \/start async def start(update: Update, context) -> None:     await update.message.reply_text('\u041f\u0440\u0438\u0432\u0435\u0442! \u042f \u0447\u0430\u0442-\u0431\u043e\u0442. \u0427\u0435\u043c \u043c\u043e\u0433\u0443 \u043f\u043e\u043c\u043e\u0447\u044c?')  # \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043e\u0431\u044b\u0447\u043d\u044b\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 async def handle_message(update: Update, context):     user_id = update.effective_user.id     if user_id not in user_ids:         user_ids[user_id] = {'last_message': None, 'preferences': {}}         context_memory[user_id] = []      message_text = update.message.text     context_messages = context_memory[user_id]      # \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u043e\u0432\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442     context_messages.append({'role': 'user', 'content': message_text})      # \u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0435\u043c \u0438\u0441\u0442\u043e\u0440\u0438\u044e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c\u0438 8 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f\u043c\u0438     context_memory[user_id] = context_messages[-8:]      try:         # Call the ollama.chat function with the context messages         response = ollama.chat(model='llama3:latest', messages=context_memory[user_id])         # \u041e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u043e\u0442\u0432\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e         await update.message.reply_text(response['message']['content'])     except Exception as e:         logging.error(f\"Error while getting response from ollama: {e}\")         await update.message.reply_text('\u041f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u0430 \u043e\u0448\u0438\u0431\u043a\u0430, \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435 \u043f\u043e\u0437\u0436\u0435.')  # \u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f async def main() -> None:     application = ApplicationBuilder().token(TOKEN).build()      application.add_handler(CommandHandler('start', start))     application.add_handler(MessageHandler(filters.TEXT &amp; ~filters.COMMAND, handle_message))      await application.run_polling()  if __name__ == '__main__':     import asyncio     asyncio.run(main())<\/code><\/pre>\n<p>\u0412 \u0441\u0442\u0440\u043e\u043a\u0443<\/p>\n<pre><code class=\"python\">response = ollama.chat(model='llama3', messages=context_memory[user_id])<\/code><\/pre>\n<p>\u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0438\u043c\u044f \u043d\u0443\u0436\u043d\u043e\u0439 \u0432\u0430\u043c \u043c\u043e\u0434\u0435\u043b\u0438, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043f\u043e \u043a\u043e\u043c\u0430\u043d\u0434\u0435<\/p>\n<pre><code class=\"bash\">ollama list<\/code><\/pre>\n<p>10. \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0443 \u0431\u043e\u0442\u0430, \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0432 \u0435\u0433\u043e \u0432 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u043c \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0438:<\/p>\n<pre><code class=\"bash\">python.\/bot.py<\/code><\/pre>\n<p>\u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0432 \u043e\u0442\u0432\u0435\u0442\u044b \u043d\u0430 \u0432\u0430\u0448\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0438\u0437 \u0431\u043e\u0442\u0430 \u0432 Telegram.<\/p>\n<blockquote>\n<p>\u041a\u043e\u0434 \u043d\u0435 \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u0438 \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0438 \u043d\u0443\u0436\u043d\u043e \u0443\u043b\u0443\u0447\u0448\u0430\u0442\u044c. \u0421\u0430\u043c \u043a\u043e\u0434 \u0431\u044b\u043b \u0441\u043e\u0437\u0434\u0430\u043d \u043d\u0430\u043c\u0438 \u0442\u0430\u043a\u0436\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e LLM-\u043c\u043e\u0434\u0435\u043b\u0438 (\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 llama3-8b-instruct), \u043d\u043e \u0435\u0441\u0442\u044c \u0438\u0434\u0435\u044f \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u0438, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0442\u0438\u043f\u0430 Codestral \u0438\u043b\u0438 Codellama-Python \u0438 \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u0439 \u0438 \u0441 ChatGPT4o.<\/p>\n<\/blockquote>\n<p>11. \u0415\u0441\u043b\u0438 \u0432\u0441\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0438 \u0431\u043e\u0442 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442, \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u0435\u0440\u0432\u0438\u0441 \u0434\u043b\u044f \u0435\u0433\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0435:<\/p>\n<pre><code class=\"bash\">tee \/usr\/lib\/systemd\/system\/bot.service > \/dev\/null &lt;&lt;EOF  [Unit] Description=Chat AI Bot Service After=network-online.target  [Service] Type=idle Restart=always RestartSec=3 User=root WorkingDirectory=\/home\/user\/ ExecStart=\/home\/user\/venv\/bin\/python \/home\/user\/bot.py  [Install] WantedBy=default.target  EOF<\/code><\/pre>\n<p>12. \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0441\u0435\u0440\u0432\u0438\u0441.<\/p>\n<pre><code class=\"bash\">sudo systemctl daemon-reload sudo systemctl enable bot sudo systemctl start bot<\/code><\/pre>\n<h3>\u0427\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c, \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u043d\u0435\u0442 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0430 \u0441 RTX \u043a\u0430\u0440\u0442\u043e\u0439 \u043e\u0442 Nvidia?<\/h3>\n<ol>\n<li>\n<p>\u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c Ollama \u043d\u0430 CPU. \u0411\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432 \u0440\u0430\u0437\u044b \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435, \u0447\u0435\u043c \u043d\u0430 GPU, \u043d\u043e \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u043c\u043e\u0436\u043d\u043e. \u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u043d\u0435\u0442 8 \u0413\u0431 RTX \u0432\u0438\u0434\u0435\u043e\u043a\u0430\u0440\u0442\u044b, \u0432\u044b \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0447\u0430\u0442-\u0431\u043e\u0442, \u043d\u043e ollama \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432 GPU-offload \u0440\u0435\u0436\u0438\u043c\u0435 \u0441 \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u043e\u043c \u0447\u0430\u0441\u0442\u0438 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043d\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440.<\/p>\n<\/li>\n<li>\n<p>C \u043c\u0430\u0440\u0442\u0430 2024 \u0433\u043e\u0434\u0430 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0432\u0435\u0440\u0441\u0438\u044f Ollama \u0434\u043b\u044f GPU \u043e\u0442 AMD. \u041a\u0430\u043a \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u044d\u0442\u0443 \u0432\u0435\u0440\u0441\u0438\u044e \u0438 \u043a\u0430\u043a\u0438\u0435 \u0432\u0438\u0434\u0435\u043e\u043a\u0430\u0440\u0442\u044b \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442\u0441\u044f,\u00a0<a href=\"https:\/\/dzen.ru\/away?to=https%3A%2F%2Follama.com%2Fblog%2Famd-preview\">\u0447\u0438\u0442\u0430\u0439\u0442\u0435 \u043d\u0430 \u044d\u0442\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435<\/a>.<\/p>\n<\/li>\n<li>\n<p>\u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0430\u0440\u0435\u043d\u0434\u043e\u0432\u0430\u0442\u044c \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440 \u0441 GPU\u00a0<a href=\"https:\/\/dzen.ru\/away?to=https%3A%2F%2Fhostkey.com%2Fgpu-dedicated-servers%2Fvm%2F\">\u0443 \u043d\u0430\u0441<\/a>. \u041f\u043e\u0434\u043e\u0439\u0434\u0443\u0442 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0441 GPU \u043e\u0442 Nvidia \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 A4000.<\/p>\n<\/li>\n<\/ol>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/819035\/\"> https:\/\/habr.com\/ru\/articles\/819035\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0427\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u0435\u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e \u0447\u0430\u0442-\u0431\u043e\u0442\u0430 \u0434\u043b\u044f Telegram, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043b\u0443\u0447\u0438\u0442 \u043c\u043e\u0449\u044c LLM llama3 \u0432\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0448\u0430\u0433\u043e\u0432. \u0412\u0441\u0435 \u0431\u0443\u0434\u0435\u043c \u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043e\u0434 Ubuntu 22.04 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c GPU NVIDIA (\u043f\u043e\u0434\u043e\u0439\u0434\u0443\u0442 \u043c\u043e\u0434\u0435\u043b\u0438 RTX2xxx \u0438 \u043d\u043e\u0432\u0435\u0435 \u043e\u0442 8 \u0413\u0431 \u0432\u0438\u0434\u0435\u043e\u043f\u0430\u043c\u044f\u0442\u0438). \u0422\u0430\u043a\u0436\u0435 \u0443\u0431\u0435\u0434\u0438\u0442\u0435\u0441\u044c, \u0447\u0442\u043e \u0443 \u0432\u0430\u0441 \u043d\u0430 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0435 \u043c\u0438\u043d\u0438\u043c\u0443\u043c 16 \u0413\u0431 \u041e\u0417\u0423.<\/p>\n<p>\u041f\u0435\u0440\u0435\u0434 \u043d\u0430\u0447\u0430\u043b\u043e\u043c \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u044c\u0442\u0435, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u044b \u043b\u0438 \u0443 \u0432\u0430\u0441 \u0434\u0440\u0430\u0439\u0432\u0435\u0440\u0430 \u043e\u0442 Nvidia \u0438 CUDA \u0432\u043e\u0442\u00a0<a href=\"https:\/\/dzen.ru\/away?to=https%3A%2F%2Fhostkey.ru%2Fdocumentation%2Ftechnical%2Fgpu%2Fnvidia_gpu_linux%2F\">\u043f\u043e \u044d\u0442\u043e\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438<\/a>.<\/p>\n<h3>\u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c Ollama<\/h3>\n<ol>\n<li>\n<p>\u0421\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u0438 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c Ollama<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"bash\">curl -L https:\/\/ollama.com\/download\/ollama-linux-amd64 -o \/usr\/bin\/ollama chmod +x \/usr\/bin\/ollama sudo useradd -r -s \/bin\/false -m -d \/usr\/share\/ollama ollama<\/code><\/pre>\n<ol start=\"2\">\n<li>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c Ollama \u043a\u0430\u043a \u0441\u0435\u0440\u0432\u0438\u0441. \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0430\u0439\u043b \u0441\u0435\u0440\u0432\u0438\u0441\u0430:<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"bash\">tee \/usr\/lib\/systemd\/system\/ollama.service > \/dev\/null &lt;&lt;EOF [Unit] Description=Ollama Service After=network-online.target  [Service] ExecStart=\/usr\/bin\/ollama serve User=ollama Group=ollama Restart=always RestartSec=3 Environment=\"OLLAMA_HOST=0.0.0.0\" Environment=\"OLLAMA_ORIGINS=*\"  [Install] WantedBy=default.target EOF<\/code><\/pre>\n<ol start=\"3\">\n<li>\n<p>\u0412\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0441\u0435\u0440\u0432\u0438\u0441 ollama:<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"bash\">sudo systemctl daemon-reload sudo systemctl enable ollama sudo systemctl start ollama<\/code><\/pre>\n<ol start=\"4\">\n<li>\n<p>\u0421\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u044c\u00a0<strong>llama3:8b<\/strong><\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"bash\">ollama run llama3 | exit<\/code><\/pre>\n<blockquote>\n<p>\u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u043a\u0430\u0447\u0430\u0442\u044c \u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043b\u044e\u0431\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 Ollama, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 Phi3 \u0438\u043b\u0438 Codestral. \u041f\u043e\u043b\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <a href=\"https:\/\/ollama.com\/library\">\u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435<\/a>. \u0410 \u043d\u0430\u0436\u0430\u0432 \u043d\u0430 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c, \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0442\u0430\u043a\u0436\u0435 \u0435\u0435 \u0440\u0430\u0437\u043c\u0435\u0440, \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0438 \u0442\u0438\u043f.<\/p>\n<\/blockquote>\n<ol start=\"5\">\n<li>\n<p>\u041f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0441\u0435\u0440\u0432\u0438\u0441:<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"bash\">ollama run llama3 | exit<\/code><\/pre>\n<h3>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0447\u0430\u0442-\u0431\u043e\u0442<\/h3>\n<p>1. \u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c Python 3.10:<\/p>\n<pre><code class=\"bash\">sudo apt install python3.10<\/code><\/pre>\n<p>2. \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0435 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435:<\/p>\n<pre><code class=\"bash\">python3 -m venv venv<\/code><\/pre>\n<p>3. \u0410\u043a\u0442\u0438\u0432\u0438\u0440\u0443\u0435\u043c \u0434\u0430\u043d\u043d\u043e\u0435 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435:<\/p>\n<pre><code class=\"bash\">source venv\/bin\/activate<\/code><\/pre>\n<p>\u041f\u0440\u0438 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0439 \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u0438 \u0432 \u0441\u0442\u0440\u043e\u043a\u0435 \u043f\u0440\u0438\u0433\u043b\u0430\u0448\u0435\u043d\u0438\u044f \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u0438\u043c\u044f \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u0432 \u0441\u043a\u043e\u0431\u043a\u0430\u0445:<\/p>\n<pre><code class=\"bash\">(venv) user@you_server:~$<\/code><\/pre>\n<p>4. \u0421\u0442\u0430\u0432\u0438\u043c \u0432 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438:<\/p>\n<pre><code class=\"bash\">pip install python-telegram-bot ollama nest_asyncio<\/code><\/pre>\n<p>8. \u0417\u0430\u0445\u043e\u0434\u0438\u043c \u043d\u0430\u00a0<a href=\"https:\/\/dzen.ru\/away?to=https%3A%2F%2Ft.me%2FBotFather\">https:\/\/t.me\/BotFather<\/a>\u00a0, \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0431\u043e\u0442\u0430 \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0435\u0433\u043e \u0442\u043e\u043a\u0435\u043d.<\/p>\n<p>9. \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0430\u0439\u043b\u00a0<em>bot.py<\/em>\u00a0\u0441\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435\u043c (\u043c\u043e\u0436\u043d\u043e \u0432 \u043a\u043e\u0440\u043d\u0435 \u0432\u0430\u0448\u0435\u0439 \u0434\u043e\u043c\u0430\u0448\u043d\u0435\u0439 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438). \u0414\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0447\u0430\u0442-\u0431\u043e\u0442\u0443 \u0432 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435, \u043e\u0431\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u043d\u0430 8 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439:<\/p>\n<pre><code class=\"python\">import logging from telegram import Update from telegram.ext import ApplicationBuilder, CommandHandler, MessageHandler, filters import ollama import nest_asyncio  nest_asyncio.apply()  # \u0412\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0436\u0443\u0440\u043d\u0430\u043b\u0430 logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)  # \u0422\u043e\u043a\u0435\u043d, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u043e\u0442 @BotFather TOKEN = 'YOU_TELEGRAM_BOT_TOKEN'  # Replace with your actual token  # \u0421\u043b\u043e\u0432\u0430\u0440\u044c \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 user_ids = {} context_memory = {}  # \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \/start async def start(update: Update, context) -> None:     await update.message.reply_text('\u041f\u0440\u0438\u0432\u0435\u0442! \u042f \u0447\u0430\u0442-\u0431\u043e\u0442. \u0427\u0435\u043c \u043c\u043e\u0433\u0443 \u043f\u043e\u043c\u043e\u0447\u044c?')  # \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043e\u0431\u044b\u0447\u043d\u044b\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 async def handle_message(update: Update, context):     user_id = update.effective_user.id     if user_id not in user_ids:         user_ids[user_id] = {'last_message': None, 'preferences': {}}         context_memory[user_id] = []      message_text = update.message.text     context_messages = context_memory[user_id]      # \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u043e\u0432\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442     context_messages.append({'role': 'user', 'content': message_text})      # \u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0435\u043c \u0438\u0441\u0442\u043e\u0440\u0438\u044e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c\u0438 8 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f\u043c\u0438     context_memory[user_id] = context_messages[-8:]      try:         # Call the ollama.chat function with the context messages         response = ollama.chat(model='llama3:latest', messages=context_memory[user_id])         # \u041e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u043e\u0442\u0432\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e         await update.message.reply_text(response['message']['content'])     except Exception as e:         logging.error(f\"Error while getting response from ollama: {e}\")         await update.message.reply_text('\u041f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u0430 \u043e\u0448\u0438\u0431\u043a\u0430, \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435 \u043f\u043e\u0437\u0436\u0435.')  # \u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f async def main() -> None:     application = ApplicationBuilder().token(TOKEN).build()      application.add_handler(CommandHandler('start', start))     application.add_handler(MessageHandler(filters.TEXT &amp; ~filters.COMMAND, handle_message))      await application.run_polling()  if __name__ == '__main__':     import asyncio     asyncio.run(main())<\/code><\/pre>\n<p>\u0412 \u0441\u0442\u0440\u043e\u043a\u0443<\/p>\n<pre><code class=\"python\">response = ollama.chat(model='llama3', messages=context_memory[user_id])<\/code><\/pre>\n<p>\u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0438\u043c\u044f \u043d\u0443\u0436\u043d\u043e\u0439 \u0432\u0430\u043c \u043c\u043e\u0434\u0435\u043b\u0438, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043f\u043e \u043a\u043e\u043c\u0430\u043d\u0434\u0435<\/p>\n<pre><code class=\"bash\">ollama list<\/code><\/pre>\n<p>10. \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0443 \u0431\u043e\u0442\u0430, \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0432 \u0435\u0433\u043e \u0432 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u043c \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0438:<\/p>\n<pre><code class=\"bash\">python.\/bot.py<\/code><\/pre>\n<p>\u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0432 \u043e\u0442\u0432\u0435\u0442\u044b \u043d\u0430 \u0432\u0430\u0448\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0438\u0437 \u0431\u043e\u0442\u0430 \u0432 Telegram.<\/p>\n<blockquote>\n<p>\u041a\u043e\u0434 \u043d\u0435 \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u0438 \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0438 \u043d\u0443\u0436\u043d\u043e \u0443\u043b\u0443\u0447\u0448\u0430\u0442\u044c. \u0421\u0430\u043c \u043a\u043e\u0434 \u0431\u044b\u043b \u0441\u043e\u0437\u0434\u0430\u043d \u043d\u0430\u043c\u0438 \u0442\u0430\u043a\u0436\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e LLM-\u043c\u043e\u0434\u0435\u043b\u0438 (\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 llama3-8b-instruct), \u043d\u043e \u0435\u0441\u0442\u044c \u0438\u0434\u0435\u044f \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u0438, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0442\u0438\u043f\u0430 Codestral \u0438\u043b\u0438 Codellama-Python \u0438 \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u0439 \u0438 \u0441 ChatGPT4o.<\/p>\n<\/blockquote>\n<p>11. \u0415\u0441\u043b\u0438 \u0432\u0441\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0438 \u0431\u043e\u0442 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442, \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u0435\u0440\u0432\u0438\u0441 \u0434\u043b\u044f \u0435\u0433\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0435:<\/p>\n<pre><code class=\"bash\">tee \/usr\/lib\/systemd\/system\/bot.service > \/dev\/null &lt;&lt;EOF  [Unit] Description=Chat AI Bot Service After=network-online.target  [Service] Type=idle Restart=always RestartSec=3 User=root WorkingDirectory=\/home\/user\/ ExecStart=\/home\/user\/venv\/bin\/python \/home\/user\/bot.py  [Install] WantedBy=default.target  EOF<\/code><\/pre>\n<p>12. \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0441\u0435\u0440\u0432\u0438\u0441.<\/p>\n<pre><code class=\"bash\">sudo systemctl daemon-reload sudo systemctl enable bot sudo systemctl start bot<\/code><\/pre>\n<h3>\u0427\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c, \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u043d\u0435\u0442 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0430 \u0441 RTX \u043a\u0430\u0440\u0442\u043e\u0439 \u043e\u0442 Nvidia?<\/h3>\n<ol>\n<li>\n<p>\u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c Ollama \u043d\u0430 CPU. \u0411\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432 \u0440\u0430\u0437\u044b \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435, \u0447\u0435\u043c \u043d\u0430 GPU, \u043d\u043e \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u043c\u043e\u0436\u043d\u043e. \u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u043d\u0435\u0442 8 \u0413\u0431 RTX \u0432\u0438\u0434\u0435\u043e\u043a\u0430\u0440\u0442\u044b, \u0432\u044b \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0447\u0430\u0442-\u0431\u043e\u0442, \u043d\u043e ollama \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432 GPU-offload \u0440\u0435\u0436\u0438\u043c\u0435 \u0441 \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u043e\u043c \u0447\u0430\u0441\u0442\u0438 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043d\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440.<\/p>\n<\/li>\n<li>\n<p>C \u043c\u0430\u0440\u0442\u0430 2024 \u0433\u043e\u0434\u0430 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0432\u0435\u0440\u0441\u0438\u044f Ollama \u0434\u043b\u044f GPU \u043e\u0442 AMD. \u041a\u0430\u043a \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u044d\u0442\u0443 \u0432\u0435\u0440\u0441\u0438\u044e \u0438 \u043a\u0430\u043a\u0438\u0435 \u0432\u0438\u0434\u0435\u043e\u043a\u0430\u0440\u0442\u044b \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442\u0441\u044f,\u00a0<a href=\"https:\/\/dzen.ru\/away?to=https%3A%2F%2Follama.com%2Fblog%2Famd-preview\">\u0447\u0438\u0442\u0430\u0439\u0442\u0435 \u043d\u0430 \u044d\u0442\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435<\/a>.<\/p>\n<\/li>\n<li>\n<p>\u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0430\u0440\u0435\u043d\u0434\u043e\u0432\u0430\u0442\u044c \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440 \u0441 GPU\u00a0<a href=\"https:\/\/dzen.ru\/away?to=https%3A%2F%2Fhostkey.com%2Fgpu-dedicated-servers%2Fvm%2F\">\u0443 \u043d\u0430\u0441<\/a>. \u041f\u043e\u0434\u043e\u0439\u0434\u0443\u0442 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0441 GPU \u043e\u0442 Nvidia \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 A4000.<\/p>\n<\/li>\n<\/ol>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/819035\/\"> https:\/\/habr.com\/ru\/articles\/819035\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-377878","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/377878","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=377878"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/377878\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=377878"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=377878"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=377878"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}