Spaces:
Sleeping
Sleeping
Update main.py
Browse files12345678910114 unmodified lines16171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576import httpxfrom fastapi import FastAPI, Requestfrom fastapi.middleware.cors import CORSMiddlewareimport requestsimport timeimport osclient = httpx.AsyncClient()app = FastAPI()app.add_middleware(4 unmodified linesallow_headers=["*"],)#https://api.telegram.org/bot6907051705:AAHZtYuiFTkQBNNw6m3cBVns8BPUw5mvxgU/setWebhook?url=https://matteoscript-TelegramBotSimple.hf.space/@app.on_event("startup")def on_startup():print('start up')response = client.get(os.getenv('telegramUrlBot') + '/setWebhook?url=https://matteoscript-TelegramBotSimple.hf.space/OLD')response = client.get(os.getenv('telegramUrlBot') + '/setWebhook?url=https://matteoscript-TelegramBotSimple.hf.space/')print('webhook settato')@app.post("/")async def RispondiMessaggio(data: dict):print(data)if data['message']['chat']['type'] == "group" or data['message']['chat']['type'] == "supergroup":chat_id = data['message']['chat']['id']else:chat_id = data['message']['from']['id']text = data['message']['text']systemContent = "Tu sei un bot che esegue quello che deve eseguire"systemStyle = "Utilizza molte EMOJI; Le parole IMPORTANTI mettile tra * (per esempio: *parola in grassetto*); Le CITAZIONI mettile tra _ (per esempio: _citazione in corsivo_). Usa l'ITALIANO!"instruction = ""temperature = 0.8max_new_tokens = 100numeroGenerazioni = 1payload = {'input': text,'systemRole': systemContent,'systemStyle': systemStyle,'instruction': instruction,'temperature': temperature,'max_new_tokens': max_new_tokens,'asincrono': True,'NumeroGenerazioni': numeroGenerazioni,'StringaSplit': "&&",'telegramChatId': chat_id,'telegramUrlBot': os.getenv('telegramUrlBot'),'telegramUrlPost': os.getenv('telegramUrlPost')}headers = {'Content-Type': 'application/json','Authorization': 'Bearer ' + os.getenv('tokenAPI')}response = requests.post(os.getenv('urlAPI'), json=payload, headers=headers)print("Response Content:", response.text)#await client.get("https://script.google.com/macros/s/AKfycbxa8wXSr1ynlEONQ99s3WF5a9OTHSYWH7NkKsYI9Z2SeWRoU5c0-WzjY5Gn2iDhSgj5/exec")#await client.get("https://script.google.com/macros/s/AKfycbxa8wXSr1ynlEONQ99s3WF5a9OTHSYWH7NkKsYI9Z2SeWRoU5c0-WzjY5Gn2iDhSgj5/exec")#requests.get("https://script.google.com/macros/s/AKfycbxa8wXSr1ynlEONQ99s3WF5a9OTHSYWH7NkKsYI9Z2SeWRoU5c0-WzjY5Gn2iDhSgj5/exec")#requests.get("http://api.telegram.org/bot6770617809:AAEhytQUOl3uZOFINVE7-o0KkIoAz8perGU/sendMessage?chat_id=1738997897&text=Come_Stai_Vez")#chat_id = data['message']['chat']['id']#text = data['message']['text']#resp = requests.get("https://api.telegram.org/bot6770617809:AAEhytQUOl3uZOFINVE7-o0KkIoAz8perGU/sendMessage?chat_id=1738997897&text=Come_Stai_Vez")#resp = requests.get(f"{BASE_URL}/sendMessage?chat_id={chat_id}&text={text}")#print(resp)#await client.get(f"{BASE_URL}/sendMessage?chat_id={chat_id}&text={text}")return {"response": "ok"}@app.get("/")def read_general():return {"response": "Started"}1234564 unmodified lines11121314151617181920212223242526from fastapi import FastAPI, Requestfrom fastapi.middleware.cors import CORSMiddlewareimport requestsapp = FastAPI()app.add_middleware(4 unmodified linesallow_headers=["*"],)@app.post("/")async def webhook(data: dict):print(data)headers = {'Content-Type': 'application/json','Authorization': 'Bearer ' + os.getenv('tokenAPI')}response = requests.post(os.getenv('urlAPI'), json=data, headers=headers)print("Response Content:", response.text)@app.get("/")def read_general():return {"response": "Webhook Started"}
main.py+3-53