Spaces:
Sleeping
Sleeping
fruitpicker01
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -20,7 +20,9 @@ from transformers import AutoTokenizer, AutoModel
|
|
20 |
from utils import best_text_choice
|
21 |
|
22 |
import httpx
|
|
|
23 |
import asyncio
|
|
|
24 |
|
25 |
tokenizer = AutoTokenizer.from_pretrained("Sergeyzh/rubert-tiny-turbo")
|
26 |
model = AutoModel.from_pretrained("Sergeyzh/rubert-tiny-turbo")
|
@@ -194,22 +196,30 @@ def clean_message(message):
|
|
194 |
#def generate_message_mistral_generate(prompt, max_retries=5):
|
195 |
async def generate_message_mistral_generate(prompt):
|
196 |
try:
|
197 |
-
|
198 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
199 |
"https://gigachat-preview.devices.sberbank.ru/api/v1/",
|
200 |
headers={
|
201 |
"Authorization": f"Bearer {gc_key}",
|
202 |
"Content-Type": "application/json"
|
203 |
},
|
204 |
json={"messages": [{"role": "system", "content": prompt}]},
|
205 |
-
|
206 |
-
)
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
|
|
|
|
211 |
except Exception as e:
|
212 |
-
return f"
|
213 |
|
214 |
# retries = 0
|
215 |
# while retries < max_retries:
|
@@ -244,22 +254,28 @@ async def generate_message_mistral_generate(prompt):
|
|
244 |
#def generate_message_mistral_check(prompt, max_retries=5):
|
245 |
async def generate_message_mistral_check(prompt):
|
246 |
try:
|
247 |
-
|
248 |
-
|
|
|
|
|
|
|
|
|
249 |
"https://gigachat-preview.devices.sberbank.ru/api/v1/",
|
250 |
headers={
|
251 |
"Authorization": f"Bearer {gc_key}",
|
252 |
"Content-Type": "application/json"
|
253 |
},
|
254 |
json={"messages": [{"role": "system", "content": prompt}]},
|
255 |
-
|
256 |
-
)
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
|
|
|
|
261 |
except Exception as e:
|
262 |
-
return f"
|
263 |
# retries = 0
|
264 |
# while retries < max_retries:
|
265 |
# try:
|
|
|
20 |
from utils import best_text_choice
|
21 |
|
22 |
import httpx
|
23 |
+
import aiohttp
|
24 |
import asyncio
|
25 |
+
import ssl
|
26 |
|
27 |
tokenizer = AutoTokenizer.from_pretrained("Sergeyzh/rubert-tiny-turbo")
|
28 |
model = AutoModel.from_pretrained("Sergeyzh/rubert-tiny-turbo")
|
|
|
196 |
#def generate_message_mistral_generate(prompt, max_retries=5):
|
197 |
async def generate_message_mistral_generate(prompt):
|
198 |
try:
|
199 |
+
# Создаём SSL-контекст для отключения проверки сертификатов
|
200 |
+
# В продакшн-среде НЕ РЕКОМЕНДУЕТСЯ использовать verify=False
|
201 |
+
ssl_context = ssl.create_default_context()
|
202 |
+
ssl_context.check_hostname = False
|
203 |
+
ssl_context.verify_mode = ssl.CERT_NONE
|
204 |
+
|
205 |
+
async with aiohttp.ClientSession() as session:
|
206 |
+
async with session.post(
|
207 |
"https://gigachat-preview.devices.sberbank.ru/api/v1/",
|
208 |
headers={
|
209 |
"Authorization": f"Bearer {gc_key}",
|
210 |
"Content-Type": "application/json"
|
211 |
},
|
212 |
json={"messages": [{"role": "system", "content": prompt}]},
|
213 |
+
ssl=ssl_context # Используем ssl=ssl_context для отключения проверки
|
214 |
+
) as response:
|
215 |
+
response.raise_for_status()
|
216 |
+
res = await response.json()
|
217 |
+
cleaned_message = clean_message(res.get("content", "").strip())
|
218 |
+
return cleaned_message
|
219 |
+
except aiohttp.ClientError as e:
|
220 |
+
return f"HTTP ошибка при обращении к GigaChat-Pro: {e}"
|
221 |
except Exception as e:
|
222 |
+
return f"Неизвестная ошибка при обращении к GigaChat-Pro: {e}"
|
223 |
|
224 |
# retries = 0
|
225 |
# while retries < max_retries:
|
|
|
254 |
#def generate_message_mistral_check(prompt, max_retries=5):
|
255 |
async def generate_message_mistral_check(prompt):
|
256 |
try:
|
257 |
+
ssl_context = ssl.create_default_context()
|
258 |
+
ssl_context.check_hostname = False
|
259 |
+
ssl_context.verify_mode = ssl.CERT_NONE
|
260 |
+
|
261 |
+
async with aiohttp.ClientSession() as session:
|
262 |
+
async with session.post(
|
263 |
"https://gigachat-preview.devices.sberbank.ru/api/v1/",
|
264 |
headers={
|
265 |
"Authorization": f"Bearer {gc_key}",
|
266 |
"Content-Type": "application/json"
|
267 |
},
|
268 |
json={"messages": [{"role": "system", "content": prompt}]},
|
269 |
+
ssl=ssl_context
|
270 |
+
) as response:
|
271 |
+
response.raise_for_status()
|
272 |
+
res2 = await response.json()
|
273 |
+
cleaned_message = clean_message(res2.get("content", "").strip())
|
274 |
+
return cleaned_message
|
275 |
+
except aiohttp.ClientError as e:
|
276 |
+
return f"HTTP ошибка при обращении к GigaChat-Pro: {e}"
|
277 |
except Exception as e:
|
278 |
+
return f"Неизвестная ошибка при обращении к GigaChat-Pro: {e}"
|
279 |
# retries = 0
|
280 |
# while retries < max_retries:
|
281 |
# try:
|