PHP Classes

Ollama Artificial Intelligence PHP Telegram Bot: Telegram bot to interact with Ollama AI models

Recommend this page to a friend!
  Info   View files Example   View files View files (39)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog (1)    
Last Updated Ratings Unique User Downloads Download Rankings
2024-01-02 (4 days ago) RSS 2.0 feedNot yet rated by the usersTotal: 22 This week: 22All time: 11,094 This week: 4Up
Version License PHP version Categories
ollama-bot 1.0MIT/X Consortium ...7Web services, Chat, Artificial intell..., P...
Description 

Author

This package implements a Telegram bot that can interact with Ollama AI models.

It implements new commands for a Telegram bot that can use the Ollama artificial intelligence models to interact with users.

This package can use the Ollama API to send user queries entered in Telegram and return the Ollama API query responses.




Telegram bot to interact with llama models

ImplemeTelegram bot to interact with ollama models

Picture of Mateo
  Performance   Level  
Innovation award
Innovation award
Nominee: 7x

Winner: 1x

 

Example

<?php

use Mateodioev\OllamaBot\Cache\UserCache;
use
Mateodioev\OllamaBot\Db\MysqlDatabase;
use
Mateodioev\OllamaBot\Events\{CancellCompletation, Chat, PrivateTextListener, SetModel, Start, ViewCompletionDetails};
use
Mateodioev\OllamaBot\Repository\MysqlUserRepository;
use
Mateodioev\TgHandler\{Bot, Log};

use function
Mateodioev\OllamaBot\env;

require
__DIR__ . '/vendor/autoload.php';

\
Dotenv\Dotenv::createImmutable(__DIR__)->load();

// Create logger
$logStreams = new Log\BulkStream(
    new
Log\TerminalStream(),
   
// (new Log\PhpNativeStream())->activate(env('LOG_DIR', __DIR__))
);
$logger = new Log\Logger($logStreams);

// Create bot
$bot = new Bot(env('BOT_TOKEN'), $logger);
$logStreams->add(new Log\BotApiStream($bot->getApi(), (int) env('BOT_LOG_CHANNEL_ID')));

$bot->onEvent(Start::get())
    ->
onEvent(Chat::get())
    ->
onEvent(SetModel::get())
    ->
onEvent(CancellCompletation::get())
    ->
onEvent(new PrivateTextListener())
    ->
onEvent(new ViewCompletionDetails());

$db = new MysqlDatabase('mysql:host=' . env('DB_HOST') . ';dbname=' . env('DB_NAME') . ';charset=utf8mb4', env('DB_USER'), env('DB_PASS'));
UserCache::setRepo(new MysqlUserRepository($db));

$bot->longPolling(
    (int)
env('BOT_POLLING_TIMEOUT', 60),
    (bool)
env('BOT_POLLING_IGNORE_OLD_UPDATES', false),
    (bool)
env('BOT_ASYNC', true)
);


Details

Ollama telegram bot

This bot helps you to interact with ollama models

https://github.com/Mateodioev/ollama-bot/assets/68271130/6cbec742-994b-4f79-85cf-804ec95663ad

Commands

If you want to generate a completion just send a private message to the bot or if you want to use in a public group use the command /chat followed by the text of your choice. Other commands:

  • `/setmodel` Change your current model
  • `/start`

Installation

Requirements:

  • \>= PHP 8.2
  • Mysql
  • Access to ollama api

Steps

  1. Clone this repository
    git clone https://github.com/Mateodioev/ollama-bot.git
    cd ollama-bot
    
  2. Install dependencies
    composer install --optimize-autoloader --no-interaction --no-dev
    
  3. Setup your database mysql with file `db/main.sql`
  4. Create an edit .env file
    cp .env.example .env
    vim .env # Or use your favorite editor
    
  5. Run the bot
    php index.php
    

Note > If your default model is diferent to codellama for example llama2, edit the file src/Events/Middlewares.php line 13

See ollama docs in https://github.com/jmorganca/ollama


  Files folder image Files  
File Role Description
Files folder imagedb (1 file)
Files folder imagesrc (1 file, 7 directories)
Files folder imagetest (2 files)
Accessible without login Plain text file .dockerignore Data Auxiliary data
Accessible without login Plain text file .editorconfig Data Auxiliary data
Accessible without login Plain text file .env.example Data Auxiliary data
Accessible without login Plain text file .php-cs-fixer.dist.php Example Example script
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file index.php Example Example script
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file readme.md Doc. Documentation

 Version Control Unique User Downloads Download Rankings  
 100%
Total:22
This week:22
All time:11,094
This week:4Up