Spaces:
Sleeping
Sleeping
fruitpicker01
commited on
Commit
•
ffa4a05
1
Parent(s):
d85bd91
Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,7 @@ import os
|
|
4 |
import pandas as pd
|
5 |
import time
|
6 |
from langchain.schema import SystemMessage
|
7 |
-
|
8 |
from openpyxl import load_workbook
|
9 |
import plotly.graph_objects as go
|
10 |
import random
|
@@ -29,25 +29,25 @@ client_mistral_check = Mistral(api_key=MISTRAL_API_KEY)
|
|
29 |
morph = pymorphy3.MorphAnalyzer()
|
30 |
|
31 |
# Авторизация в GigaChat Pro
|
32 |
-
|
33 |
-
#chat_pro = GigaChat(credentials=gc_key, model='GigaChat', max_tokens=68, temperature=1.15, verify_ssl_certs=False)
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
|
52 |
approach_stats = {
|
53 |
"Начни сообщение с призыва к действию с продуктом.": {"failed_checks": defaultdict(int), "total_attempts": 0},
|
@@ -181,62 +181,79 @@ def clean_message(message):
|
|
181 |
# except Exception as e:
|
182 |
# return f"Ошибка при обращении к GigaChat-Pro: {e}"
|
183 |
|
184 |
-
def generate_message_mistral_generate(prompt, max_retries=5):
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
240 |
|
241 |
#def generate_check_gigachat_pro(prompt):
|
242 |
# try:
|
|
|
4 |
import pandas as pd
|
5 |
import time
|
6 |
from langchain.schema import SystemMessage
|
7 |
+
from langchain_community.chat_models.gigachat import GigaChat
|
8 |
from openpyxl import load_workbook
|
9 |
import plotly.graph_objects as go
|
10 |
import random
|
|
|
29 |
morph = pymorphy3.MorphAnalyzer()
|
30 |
|
31 |
# Авторизация в GigaChat Pro
|
32 |
+
gc_key = os.getenv('GC_KEY')
|
33 |
+
# chat_pro = GigaChat(credentials=gc_key, model='GigaChat', max_tokens=68, temperature=1.15, verify_ssl_certs=False)
|
34 |
+
chat_pro = GigaChat(
|
35 |
+
credentials=gc_key,
|
36 |
+
model='GigaChat-Pro-preview',
|
37 |
+
base_url='https://gigachat-preview.devices.sberbank.ru/api/v1/',
|
38 |
+
max_tokens=68,
|
39 |
+
temperature=1.15,
|
40 |
+
verify_ssl_certs=False
|
41 |
+
)
|
42 |
+
|
43 |
+
chat_pro_check = GigaChat(
|
44 |
+
credentials=gc_key,
|
45 |
+
model='GigaChat-Pro-preview',
|
46 |
+
base_url='https://gigachat-preview.devices.sberbank.ru/api/v1/',
|
47 |
+
max_tokens=3000,
|
48 |
+
temperature=0.8,
|
49 |
+
verify_ssl_certs=False
|
50 |
+
)
|
51 |
|
52 |
approach_stats = {
|
53 |
"Начни сообщение с призыва к действию с продуктом.": {"failed_checks": defaultdict(int), "total_attempts": 0},
|
|
|
181 |
# except Exception as e:
|
182 |
# return f"Ошибка при обращении к GigaChat-Pro: {e}"
|
183 |
|
184 |
+
#def generate_message_mistral_generate(prompt, max_retries=5):
|
185 |
+
def generate_message_mistral_generate(prompt):
|
186 |
+
try:
|
187 |
+
messages = [SystemMessage(content=prompt)]
|
188 |
+
res = chat_pro(messages)
|
189 |
+
cleaned_message = clean_message(res.content.strip())
|
190 |
+
return cleaned_message
|
191 |
+
except Exception as e:
|
192 |
+
return f"Ошибка при обращении к GigaChat-Pro: {e}"
|
193 |
+
|
194 |
+
# retries = 0
|
195 |
+
# while retries < max_retries:
|
196 |
+
# try:
|
197 |
+
# chat_response = client_mistral_generate.chat.complete(
|
198 |
+
# model="mistral-large-latest",
|
199 |
+
# temperature=1.0,
|
200 |
+
# min_tokens=81,
|
201 |
+
# max_tokens=108,
|
202 |
+
# messages=[
|
203 |
+
# {
|
204 |
+
# "role": "user",
|
205 |
+
# "content": prompt
|
206 |
+
# },
|
207 |
+
# ]
|
208 |
+
# )
|
209 |
+
# cleaned_message = clean_message(chat_response.choices[0].message.content.strip())
|
210 |
+
# return cleaned_message
|
211 |
+
# except Exception as e:
|
212 |
+
# error_message = str(e)
|
213 |
+
# if "Status 429" in error_message or "Server disconnected without sending a response" in error_message:
|
214 |
+
# wait_time = 3
|
215 |
+
# print(f"Превышен лимит запросов или сервер не ответил. Ожидание {wait_time} секунд перед повторной попыткой...")
|
216 |
+
# time.sleep(wait_time)
|
217 |
+
# retries += 1
|
218 |
+
# else:
|
219 |
+
# print(f"Ошибка при обращении к Mistral: {e}")
|
220 |
+
# return None
|
221 |
+
# print("Не удалось получить ответ от Mistral после максимального числа попыток.")
|
222 |
+
# return None
|
223 |
+
|
224 |
+
#def generate_message_mistral_check(prompt, max_retries=5):
|
225 |
+
def generate_message_mistral_check(prompt)
|
226 |
+
try:
|
227 |
+
messages = [SystemMessage(content=prompt)]
|
228 |
+
res2 = chat_pro_check(messages)
|
229 |
+
cleaned_message = clean_message(res2.content.strip())
|
230 |
+
return cleaned_message
|
231 |
+
except Exception as e:
|
232 |
+
return f"Ошибка при обращении к GigaChat-Pro: {e}"
|
233 |
+
# retries = 0
|
234 |
+
# while retries < max_retries:
|
235 |
+
# try:
|
236 |
+
# chat_response = client_mistral_check.chat.complete(
|
237 |
+
# model="mistral-large-latest",
|
238 |
+
# temperature=0.2,
|
239 |
+
# messages=[
|
240 |
+
# {
|
241 |
+
# "role": "user",
|
242 |
+
# "content": prompt
|
243 |
+
# },
|
244 |
+
# ]
|
245 |
+
# )
|
246 |
+
# cleaned_message = clean_message(chat_response.choices[0].message.content.strip())
|
247 |
+
# return cleaned_message
|
248 |
+
# except Exception as e:
|
249 |
+
# if "Status 429" in str(e) or "Server disconnected without sending a response" in str(e):
|
250 |
+
# wait_time = 3 # Можно установить фиксированную задержку
|
251 |
+
# print(f"Превышен лимит запросов. Ожидание {wait_time} секунд перед повторной попыткой...")
|
252 |
+
# time.sleep(wait_time)
|
253 |
+
# retries += 1
|
254 |
+
# else:
|
255 |
+
# print(f"Ошибка при обращении к Mistral: {e}")
|
256 |
+
# return None
|
257 |
|
258 |
#def generate_check_gigachat_pro(prompt):
|
259 |
# try:
|