YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
import requests from telegram.ext import Updater, MessageHandler, Filters
Hugging Face API and Telegram API keys
hf_api_url = 'https://api-inference.huggingface.co/models/EleutherAI/gpt-j-6B' hf_api_key = 'your_huggingface_api_key' telegram_token = 'your_telegram_bot_token'
headers = {"Authorization": f"Bearer {hf_api_key}"}
def hf_response(update, context): user_message = update.message.text payload = {"inputs": user_message} response = requests.post(hf_api_url, headers=headers, json=payload) generated_text = response.json()[0]["generated_text"] update.message.reply_text(generated_text)
def main(): updater = Updater(telegram_token, use_context=True) dp = updater.dispatcher dp.add_handler(MessageHandler(Filters.text, hf_response)) updater.start_polling() updater.idle()
if name == 'main': main()