ysn-rfd/text-dataset-tiny-code-script-py-format
USED of tahamajs/medicine_ds_persian for .parquet file USED of Alijafarixcs2/persian-it-llama2-2k for .parquet file USED of Abirate/english_quotes for .jsonl file NEW FILES (05/12/2025) NEW FILES (12/26/2025) NEW FILES (02/15/2026)
31.6k
1import asyncio2import aiohttp3from telegram import Update4from telegram.ext import ApplicationBuilder, MessageHandler, ContextTypes, filters5import logging6 7BOT_TOKEN = ""8LLAMA_API_URL = "http://127.0.0.1:8080/completion"9 10logging.basicConfig(11 format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO12)13 14async def get_llama_response(prompt: str) -> str:15 system_prompt = f"User: {prompt}\nAssistant:"16 payload = {17 "prompt": system_prompt,18 "max_tokens": 100,19 "temperature": 0.7,20 "stop": ["</s>", "User:"]21 }22 try:23 timeout = aiohttp.ClientTimeout(total=60)24 async with aiohttp.ClientSession(timeout=timeout) as session:25 async with session.post(LLAMA_API_URL, json=payload) as resp:26 if resp.status == 200:27 data = await resp.json()28 return data.get("content", "").strip() or "❔ مدل پاسخی نداد."29 else:30 text = await resp.text()31 logging.error(f"خطای مدل: {resp.status} - {text}")32 return f"❌ خطا از مدل ({resp.status}):\n{text}"33 except asyncio.TimeoutError:34 return "⏱️ مدل دیر پاسخ داد."35 except aiohttp.ClientConnectionError:36 return "🔌 اتصال به مدل برقرار نشد."37 except Exception as e:38 logging.exception("خطای کلی:")39 return f"⚠️ خطای غیرمنتظره: {str(e)}"40 41async def handle_gemma(update: Update, context: ContextTypes.DEFAULT_TYPE):42 message = update.message43 if message and message.text and "/gemma" in message.text.lower():44 prompt = message.text.replace("/gemma", "").strip()45 await message.chat.send_action("typing")46 response = await get_llama_response(prompt)47 await message.reply_text(response)48 49def main():50 app = ApplicationBuilder().token(BOT_TOKEN).build()51 app.add_handler(MessageHandler(filters.TEXT & (~filters.COMMAND), handle_gemma))52 app.run_polling()53 54if __name__ == "__main__":55 main()56 