2024-03-08 02:15:03 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log/slog"
|
|
|
|
"os"
|
2024-03-10 01:51:01 +00:00
|
|
|
"telegram-ollama-reply-bot/bot"
|
|
|
|
"telegram-ollama-reply-bot/extractor"
|
|
|
|
"telegram-ollama-reply-bot/llm"
|
2024-03-08 02:15:03 +00:00
|
|
|
|
|
|
|
tg "github.com/mymmrac/telego"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2024-08-16 00:47:07 +00:00
|
|
|
apiToken := os.Getenv("OPENAI_API_TOKEN")
|
|
|
|
apiBaseUrl := os.Getenv("OPENAI_API_BASE_URL")
|
|
|
|
|
|
|
|
models := bot.ModelSelection{
|
|
|
|
TextRequestModel: os.Getenv("MODEL_TEXT_REQUEST"),
|
|
|
|
SummarizeModel: os.Getenv("MODEL_SUMMARIZE_REQUEST"),
|
|
|
|
}
|
|
|
|
|
|
|
|
slog.Info("Selected", "models", models)
|
2024-03-08 02:15:03 +00:00
|
|
|
|
|
|
|
telegramToken := os.Getenv("TELEGRAM_TOKEN")
|
|
|
|
|
2024-08-16 00:47:07 +00:00
|
|
|
llmc := llm.NewConnector(apiBaseUrl, apiToken)
|
|
|
|
|
|
|
|
slog.Info("Checking models availability")
|
|
|
|
|
|
|
|
for _, model := range []string{models.TextRequestModel, models.SummarizeModel} {
|
|
|
|
if !llmc.HasModel(model) {
|
|
|
|
slog.Error("Model not unavailable", "model", model)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
slog.Info("All needed models are available")
|
|
|
|
|
2024-03-10 01:51:01 +00:00
|
|
|
ext := extractor.NewExtractor()
|
2024-03-08 02:15:03 +00:00
|
|
|
|
2024-03-12 20:05:52 +00:00
|
|
|
telegramApi, err := tg.NewBot(telegramToken, tg.WithLogger(bot.NewLogger("telego: ")))
|
2024-03-08 02:15:03 +00:00
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
2024-08-16 00:47:07 +00:00
|
|
|
botService := bot.NewBot(telegramApi, llmc, ext, models)
|
2024-03-08 02:15:03 +00:00
|
|
|
|
2024-03-10 01:51:01 +00:00
|
|
|
err = botService.Run()
|
|
|
|
if err != nil {
|
2024-03-12 19:06:40 +00:00
|
|
|
slog.Error("Running bot finished with an error", "error", err)
|
2024-03-10 01:51:01 +00:00
|
|
|
os.Exit(1)
|
2024-03-08 02:15:03 +00:00
|
|
|
}
|
|
|
|
}
|