From b05ba61ac1a799afbe91e0fd11b3db57969f42e8 Mon Sep 17 00:00:00 2001 From: koziavin Date: Sat, 7 Jun 2025 21:21:59 +0400 Subject: [PATCH] chore: update index.js --- index.js | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/index.js b/index.js index ecd50e6..b02e52d 100644 --- a/index.js +++ b/index.js @@ -1,37 +1,35 @@ import { Telegraf } from "telegraf"; import axios from "axios"; -const botToken = "7745542423:AAHc3JM1kvO-Z_1OBp1L95T9QWr4jRrbfpY"; +const botToken = "7745542423:AAHc3JM1kvO-Z_1OBp1L95T9QWr4jRrbfpY"; // замени на свой const bot = new Telegraf(botToken); -const MODEL_URL = "https://llm.miduway.space/generate"; -bot.start((ctx) => ctx.reply("Привет! Я — RuGPT-бот. Напиши что-нибудь.")); +// Новый API Ollama +const OLLAMA_URL = "http://localhost:11434/api/generate"; + +bot.start((ctx) => + ctx.reply("Привет! Я — Mistral-бoт через Ollama. Напиши что-нибудь.") +); bot.on("text", async (ctx) => { const input = ctx.message.text; ctx.sendChatAction("typing"); try { - const res = await axios.post(MODEL_URL, { - inputs: input, - parameters: { - do_sample: true, - top_k: 50, - top_p: 0.95, - temperature: 1, - }, + const response = await axios.post(OLLAMA_URL, { + model: "mistral:instruct", + prompt: input, + stream: false, }); const generated = - res.data.generated_text || - res.data.generated_texts?.[0] || - "Не удалось сгенерировать."; - ctx.reply(generated); + response.data.response || "Не удалось сгенерировать ответ."; + ctx.reply(generated.trim()); } catch (err) { - console.error("Ошибка при запросе к модели:", err.message); + console.error("Ошибка при запросе к Ollama:", err.message); ctx.reply("Произошла ошибка при генерации текста."); } }); bot.launch(); -console.log("🤖 Бот запущен и использует модель от Сбербанка."); +console.log("🤖 Бот запущен и использует Ollama + Mistral.");