MatteoScript commited on
Commit
1547f88
·
verified ·
1 Parent(s): 1b41c98

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +12 -2
main.py CHANGED
@@ -76,7 +76,7 @@ def generate_text(request: Request, input_data: InputData):
76
  history = []
77
  generated_response = generate(input_text, history, temperature, max_new_tokens, top_p, repetition_penalty)
78
  if input_data.telegramChatId != '' and input_data.telegramUrlBot != '' and input_data.telegramUrlPost != '':
79
- call_telegram_api(input_data, generated_response)
80
  LoggaTesto("RISPOSTA", {"response": generated_response})
81
  return {"response": generated_response}
82
  else:
@@ -100,7 +100,7 @@ def generate_text(request: Request, input_data: InputData):
100
  LoggaTesto("RISPOSTA ASINCRONA UNIFICATA", {"response": result_data})
101
  return {"response": result_data}
102
 
103
- def call_telegram_api(input_data, text):
104
  payload = {
105
  "chat_id": input_data.telegramChatId,
106
  "text": text,
@@ -112,6 +112,16 @@ def call_telegram_api(input_data, text):
112
  else:
113
  print("Errore nella richiesta POST. Codice di stato:", response.status_code)
114
 
 
 
 
 
 
 
 
 
 
 
115
  def generate_input_text(input_data):
116
  if input_data.instruction.startswith("http"):
117
  try:
 
76
  history = []
77
  generated_response = generate(input_text, history, temperature, max_new_tokens, top_p, repetition_penalty)
78
  if input_data.telegramChatId != '' and input_data.telegramUrlBot != '' and input_data.telegramUrlPost != '':
79
+ asyncio.run(call_telegram_api(input_data, generated_response))
80
  LoggaTesto("RISPOSTA", {"response": generated_response})
81
  return {"response": generated_response}
82
  else:
 
100
  LoggaTesto("RISPOSTA ASINCRONA UNIFICATA", {"response": result_data})
101
  return {"response": result_data}
102
 
103
+ def call_telegram_api_OLD(input_data, text):
104
  payload = {
105
  "chat_id": input_data.telegramChatId,
106
  "text": text,
 
112
  else:
113
  print("Errore nella richiesta POST. Codice di stato:", response.status_code)
114
 
115
+ async def call_telegram_api(input_data, text):
116
+ payload = {
117
+ "chat_id": input_data.telegramChatId,
118
+ "text": text,
119
+ "telegramUrl": input_data.telegramUrlBot
120
+ }
121
+ async with aiohttp.ClientSession() as session:
122
+ async with session.post(input_data.telegramUrlPost, json=payload) as response:
123
+ print(await response.text())
124
+
125
  def generate_input_text(input_data):
126
  if input_data.instruction.startswith("http"):
127
  try: