-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
33 lines (25 loc) · 917 Bytes
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from telegram import Update
from telegram.ext import ContextTypes
from ollama import chat, ChatResponse
from config import Config
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""
This handler sends response to /start command.
"""
await update.message.reply_text("Let's get started!")
async def help(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""
This handler sends response to /help command.
"""
await update.message.reply_text("No help :D")
async def reply(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""
This handler sends generated llama response to any text.
"""
response: ChatResponse = chat(model=Config.llama_model, messages=[
{
"role": "user",
"content": update.message.text
}
])
await update.message.reply_text(response.message.content)