Three / app.py
Lisych's picture
Update app.py
64f6c6a verified
Raw History Blame Contribute Delete
1.15 kB
import telebot
import requests
from flask import Flask
import threading
# ТВОИ ДАННЫЕ
TOKEN = '8321909394:AAFE6XFSnCRCLByhJZNieWHGwQF0f5VOGqE'
GROQ_KEY = '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'
bot = telebot.TeleBot(TOKEN)
def get_llama_response(text):
url = "https://api.groq.com/openai/v1/chat/completions"
headers = {"Authorization": f"Bearer {GROQ_KEY}", "Content-Type": "application/json"}
data = {
"model": "llama3-8b-8192",
"messages": [{"role": "user", "content": text}]
}
response = requests.post(url, headers=headers, json=data)
return response.json()['choices'][0]['message']['content']
@bot.message_handler(func=lambda message: True)
def handle(message):
try:
answer = get_llama_response(message.text)
bot.reply_to(message, answer)
except Exception as e:
bot.reply_to(message, f"Ошибка: {e}")
app = Flask(__name__)
@app.route('/')
def index(): return "Бот на Llama 3 запущен!"
if __name__ == "__main__":
threading.Thread(target=bot.infinity_polling, daemon=True).start()
app.run(host='0.0.0.0', port=7860)