Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -42,6 +42,9 @@ class InputData(BaseModel):
|
|
| 42 |
NumeroCaratteriSplitInstruction: int = 30000
|
| 43 |
EliminaRisposteNonPertinenti: bool = False
|
| 44 |
UnificaRispostaPertinente: bool = False
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
class InputDataAsync(InputData):
|
| 47 |
test: str = ''
|
|
@@ -72,7 +75,8 @@ def generate_text(request: Request, input_data: InputData):
|
|
| 72 |
max_new_tokens = min(max_new_tokens, 29500 - len(input_text))
|
| 73 |
history = []
|
| 74 |
generated_response = generate(input_text, history, temperature, max_new_tokens, top_p, repetition_penalty)
|
| 75 |
-
|
|
|
|
| 76 |
LoggaTesto("RISPOSTA", {"response": generated_response})
|
| 77 |
return {"response": generated_response}
|
| 78 |
else:
|
|
@@ -95,7 +99,17 @@ def generate_text(request: Request, input_data: InputData):
|
|
| 95 |
#result_data = result_data.replace('"', '')
|
| 96 |
LoggaTesto("RISPOSTA ASINCRONA UNIFICATA", {"response": result_data})
|
| 97 |
return {"response": result_data}
|
| 98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
def generate_input_text(input_data):
|
| 100 |
if input_data.instruction.startswith("http"):
|
| 101 |
try:
|
|
|
|
| 42 |
NumeroCaratteriSplitInstruction: int = 30000
|
| 43 |
EliminaRisposteNonPertinenti: bool = False
|
| 44 |
UnificaRispostaPertinente: bool = False
|
| 45 |
+
telegramChatId: str = ''
|
| 46 |
+
telegramUrlBot: str = ''
|
| 47 |
+
telegramUrlPost: str = ''
|
| 48 |
|
| 49 |
class InputDataAsync(InputData):
|
| 50 |
test: str = ''
|
|
|
|
| 75 |
max_new_tokens = min(max_new_tokens, 29500 - len(input_text))
|
| 76 |
history = []
|
| 77 |
generated_response = generate(input_text, history, temperature, max_new_tokens, top_p, repetition_penalty)
|
| 78 |
+
if input_data.telegramChatId != '' && input_data.telegramUrlBot != '' && input_data.telegramUrlPost != '':
|
| 79 |
+
call_telegram_api(input_data, generated_response)
|
| 80 |
LoggaTesto("RISPOSTA", {"response": generated_response})
|
| 81 |
return {"response": generated_response}
|
| 82 |
else:
|
|
|
|
| 99 |
#result_data = result_data.replace('"', '')
|
| 100 |
LoggaTesto("RISPOSTA ASINCRONA UNIFICATA", {"response": result_data})
|
| 101 |
return {"response": result_data}
|
| 102 |
+
|
| 103 |
+
def call_telegram_api(input_data, generated_response):
|
| 104 |
+
payload = {
|
| 105 |
+
"chat_id": input_data.telegramChatId,
|
| 106 |
+
"text": generated_response",
|
| 107 |
+
"telegramUrl": input_data.telegramUrlBot
|
| 108 |
+
}
|
| 109 |
+
response = requests.post(input_data.telegramUrlPost, json=payload)
|
| 110 |
+
if response.status_code != 200:
|
| 111 |
+
print("Errore nella richiesta POST. Codice di stato:", response.status_code)
|
| 112 |
+
|
| 113 |
def generate_input_text(input_data):
|
| 114 |
if input_data.instruction.startswith("http"):
|
| 115 |
try:
|