Files
bot-tg-assistent/index.js
koziavin b05ba61ac1
Some checks failed
Deploy Bot / build-and-deploy (push) Failing after 10s
chore: update index.js
2025-06-07 21:21:59 +04:00

36 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { Telegraf } from "telegraf";
import axios from "axios";
const botToken = "7745542423:AAHc3JM1kvO-Z_1OBp1L95T9QWr4jRrbfpY"; // замени на свой
const bot = new Telegraf(botToken);
// Новый 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 response = await axios.post(OLLAMA_URL, {
model: "mistral:instruct",
prompt: input,
stream: false,
});
const generated =
response.data.response || "Не удалось сгенерировать ответ.";
ctx.reply(generated.trim());
} catch (err) {
console.error("Ошибка при запросе к Ollama:", err.message);
ctx.reply("Произошла ошибка при генерации текста.");
}
});
bot.launch();
console.log("🤖 Бот запущен и использует Ollama + Mistral.");