Spaces:
Running
Running
File size: 3,469 Bytes
cc2c495 002fca8 eadded2 70dc730 fe8c789 d707be1 cc2c495 11c5c73 23d7e0d eadded2 6159237 891cabc 09a8c2d 863cde7 b32b0d3 863cde7 f0b1c50 863cde7 dc2d37c cc2c495 2d87fd7 ce65594 13a597c ce65594 13a597c 01ff0c1 09a8c2d 79f7735 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
import httpx
from fastapi import FastAPI, Request
from fastapi.middleware.cors import CORSMiddleware # Importa il middleware CORS
import requests
import time
client = httpx.AsyncClient()
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
#https://api.telegram.org/bot6907051705:AAHZtYuiFTkQBNNw6m3cBVns8BPUw5mvxgU/setWebhook?url=https://matteoscript-TelegramBotSimple.hf.space/
@app.on_event("startup")
async def on_startup():
try:
response = await client.get(os.getenv('telegramUrlBot') + '/setWebhook?url=https://matteoscript-TelegramBotSimple.hf.space/OLD')
response = await client.get(os.getenv('telegramUrlBot') + '/setWebhook?url=https://matteoscript-TelegramBotSimple.hf.space/')
response.raise_for_status()
print("Webhook set successfully")
except httpx.HTTPError as e:
print(f"Error setting webhook: {e}")
@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.8
max_new_tokens = 100
numeroGenerazioni = 1
payload = {
'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"} |