fruitpicker01 commited on
Commit
fa1155c
·
verified ·
1 Parent(s): e932ff5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +73 -73
app.py CHANGED
@@ -4,7 +4,7 @@ import os
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
@@ -181,79 +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
- 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:
 
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
 
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: