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 aiohttp # برای درخواستهای async3from telegram import Update4from telegram.ext import ApplicationBuilder, MessageHandler, ContextTypes, filters5import logging6 7# تنظیمات8BOT_TOKEN = ""9LLAMA_API_URL = "http://127.0.0.1:8080/completion"10 11# لاگگیری12logging.basicConfig(13 format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO14)15 16# گرفتن پاسخ از llama.cpp به صورت async17async def get_llama_response(prompt: str) -> str:18 system_prompt = f"User: {prompt}\nAssistant:"19 payload = {20 "prompt": system_prompt,21 "max_tokens": 64,22 "temperature": 0.7,23 "stop": ["</s>", "User:"]24 }25 try:26 async with aiohttp.ClientSession() as session:27 async with session.post(LLAMA_API_URL, json=payload, timeout=60) as resp:28 if resp.status == 200:29 data = await resp.json()30 return data.get("content", "").strip()31 else:32 logging.error(f"LLaMA API Error: {resp.status}")33 return "❌ خطا در دریافت پاسخ از مدل زبان."34 except asyncio.TimeoutError:35 return "⏱️ مدل دیر پاسخ داد. لطفاً دوباره تلاش کنید."36 except Exception as e:37 logging.exception("خطا در ارتباط با مدل:")38 return "⚠️ خطا در پردازش درخواست شما."39 40# هندل کردن پیامهای دستوری41async def handle_command(update: Update, context: ContextTypes.DEFAULT_TYPE):42 message = update.message43 if message and message.text:44 user_input = message.text.lstrip('/')45 await message.chat.send_action("typing")46 response = await get_llama_response(user_input)47 await message.reply_text(response)48 49# راهاندازی ربات50def main():51 app = ApplicationBuilder().token(BOT_TOKEN).build()52 app.add_handler(MessageHandler(filters.COMMAND, handle_command))53 app.run_polling()54 55if __name__ == "__main__":56 main()57 