fruitpicker01 commited on
Commit
2f69a4f
1 Parent(s): 5282526

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +94 -18
app.py CHANGED
@@ -33,7 +33,9 @@ token = os.getenv('GITHUB_TOKEN')
33
  client_mistral_generate = Mistral(api_key=MISTRAL_API_KEY)
34
 
35
  # Клиент для выполнения проверок
36
- client_mistral_check = Mistral(api_key=MISTRAL_API_KEY)
 
 
37
 
38
  morph = pymorphy3.MorphAnalyzer()
39
 
@@ -267,6 +269,80 @@ async def generate_message_mistral_check(prompt, max_retries=5):
267
  print("Failed to get response from Mistral after maximum retries.")
268
  return None
269
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
270
  #def generate_check_gigachat_pro(prompt):
271
  # try:
272
  # messages = [SystemMessage(content=prompt)]
@@ -1398,7 +1474,7 @@ async def check_abstract_claims(message, description, benefits):
1398
 
1399
  **Не добавляй никакого дополнительного текста. Перед ответом убедись, что отвечаешь только в формате JSON с закрывающими кавычками и скобками.**'''
1400
 
1401
- response = await generate_message_mistral_check(prompt)
1402
  # await asyncio.sleep(3)
1403
  print("Mistral response:", response)
1404
  result = parse_json_response(response)
@@ -1477,7 +1553,7 @@ async def check_offensive_phrases(message):
1477
  return None
1478
 
1479
  # 28. Проверка на речевые клише, рекламные штампы и канцеляризмы
1480
- async def check_cliches_and_bureaucratese(message, description, benefits):
1481
  print()
1482
  print("Проверка 28: Проверка на речевые клише, рекламные штампы и канцеляризмы")
1483
  print()
@@ -1625,43 +1701,43 @@ async def perform_checks(message, description, key_message, product_name, benefi
1625
 
1626
  # 2. Morphological checks using pymorphy3
1627
  morphological_checks = [
 
1628
  ("forbidden_words", check_forbidden_words),
1629
- ("client_addressing", check_no_greeting),
1630
- ("promises", check_no_promises),
1631
  ("double_verbs", check_no_double_verbs),
1632
- ("participles", check_no_participles),
1633
  ("adverbial_participles", check_no_adverbial_participles),
 
 
 
 
1634
  ("superlative_adjectives", check_no_superlative_adjectives),
 
 
 
 
1635
  ("passive_voice", check_no_passive_voice),
1636
  ("written_out_ordinals", check_no_written_out_ordinals),
1637
  ("subordinate_clauses_chain", check_no_subordinate_clauses_chain),
1638
  ("repeating_conjunctions", check_no_repeating_conjunctions),
1639
- ("introductory_phrases", check_no_introductory_phrases),
1640
- ("amplifiers", check_no_amplifiers),
1641
  ("time_parasites", check_no_time_parasites),
1642
- ("multiple_nouns", check_no_multiple_nouns),
1643
- ("derived_prepositions", check_no_derived_prepositions),
1644
- ("compound_sentences", check_no_compound_sentences),
1645
  ("dates_written_out", check_no_dates_written_out),
1646
- ("no_word_repetitions", check_no_word_repetitions),
1647
  ]
1648
 
1649
  # 3. LLM checks: check_clickbait_phrases, check_abstract_claims, check_cliches_and_bureaucratese
1650
  llm_checks_group1 = [
1651
- ("product_name_consistency", check_product_name_consistency),
1652
  ("no_contradictions", check_no_contradictions),
1653
- ("clickbait_phrases", check_clickbait_phrases),
1654
  ("abstract_claims", check_abstract_claims),
1655
  ("cliches_and_bureaucratese", check_cliches_and_bureaucratese),
1656
- ("contains_key_message", check_contains_key_message)
 
 
 
1657
  ]
1658
 
1659
  # 4. Remaining LLM checks
1660
  llm_checks_group2 = [
1661
- ("disconnected_sentences", check_disconnected_sentences),
1662
- ("synonymous_members", check_synonymous_members),
1663
- ("specialized_terms", check_specialized_terms),
1664
  ("offensive_phrases", check_offensive_phrases),
 
 
1665
  ]
1666
 
1667
  # Perform morphological checks
 
33
  client_mistral_generate = Mistral(api_key=MISTRAL_API_KEY)
34
 
35
  # Клиент для выполнения проверок
36
+ client_mistral_check = Mistral(api_key=MISTRAL_API_KEY_2)
37
+ client_mistral_check_2 = Mistral(api_key=MISTRAL_API_KEY_3)
38
+ client_mistral_check_3 = Mistral(api_key=MISTRAL_API_KEY_4)
39
 
40
  morph = pymorphy3.MorphAnalyzer()
41
 
 
269
  print("Failed to get response from Mistral after maximum retries.")
270
  return None
271
 
272
+ async def generate_message_mistral_check_2(prompt, max_retries=5):
273
+ #def generate_message_mistral_check(prompt):
274
+ # try:
275
+ # messages = [SystemMessage(content=prompt)]
276
+ # res2 = chat_pro_check(messages)
277
+ # cleaned_message = clean_message(res2.content.strip())
278
+ # return cleaned_message
279
+ # except Exception as e:
280
+ # return f"Ошибка при обращении к GigaChat-Pro: {e}"
281
+ retries = 0
282
+ while retries < max_retries:
283
+ try:
284
+ chat_response = await client_mistral_check_2.chat.complete_async(
285
+ model="mistral-large-latest",
286
+ temperature=0.2,
287
+ messages=[
288
+ {
289
+ "role": "user",
290
+ "content": prompt
291
+ },
292
+ ]
293
+ )
294
+ cleaned_message = clean_message(chat_response.choices[0].message.content.strip())
295
+ return cleaned_message
296
+ except Exception as e:
297
+ error_message = str(e)
298
+ if "Status 429" in error_message or "Server disconnected without sending a response" in error_message:
299
+ wait_time = 3
300
+ print(f"Rate limit exceeded or server did not respond. Waiting {wait_time} seconds before retrying...")
301
+ await asyncio.sleep(wait_time)
302
+ retries += 1
303
+ else:
304
+ print(f"Error calling Mistral: {e}")
305
+ return None
306
+ print("Failed to get response from Mistral after maximum retries.")
307
+ return None
308
+
309
+ async def generate_message_mistral_check_3(prompt, max_retries=5):
310
+ #def generate_message_mistral_check(prompt):
311
+ # try:
312
+ # messages = [SystemMessage(content=prompt)]
313
+ # res2 = chat_pro_check(messages)
314
+ # cleaned_message = clean_message(res2.content.strip())
315
+ # return cleaned_message
316
+ # except Exception as e:
317
+ # return f"Ошибка при обращении к GigaChat-Pro: {e}"
318
+ retries = 0
319
+ while retries < max_retries:
320
+ try:
321
+ chat_response = await client_mistral_check_3.chat.complete_async(
322
+ model="mistral-large-latest",
323
+ temperature=0.2,
324
+ messages=[
325
+ {
326
+ "role": "user",
327
+ "content": prompt
328
+ },
329
+ ]
330
+ )
331
+ cleaned_message = clean_message(chat_response.choices[0].message.content.strip())
332
+ return cleaned_message
333
+ except Exception as e:
334
+ error_message = str(e)
335
+ if "Status 429" in error_message or "Server disconnected without sending a response" in error_message:
336
+ wait_time = 3
337
+ print(f"Rate limit exceeded or server did not respond. Waiting {wait_time} seconds before retrying...")
338
+ await asyncio.sleep(wait_time)
339
+ retries += 1
340
+ else:
341
+ print(f"Error calling Mistral: {e}")
342
+ return None
343
+ print("Failed to get response from Mistral after maximum retries.")
344
+ return None
345
+
346
  #def generate_check_gigachat_pro(prompt):
347
  # try:
348
  # messages = [SystemMessage(content=prompt)]
 
1474
 
1475
  **Не добавляй никакого дополнительного текста. Перед ответом убедись, что отвечаешь только в формате JSON с закрывающими кавычками и скобками.**'''
1476
 
1477
+ response = await generate_message_mistral_check_2(prompt)
1478
  # await asyncio.sleep(3)
1479
  print("Mistral response:", response)
1480
  result = parse_json_response(response)
 
1553
  return None
1554
 
1555
  # 28. Проверка на речевые клише, рекламные штампы и канцеляризмы
1556
+ async def check_cliches_and_bureaucratese_3(message, description, benefits):
1557
  print()
1558
  print("Проверка 28: Проверка на речевые клише, рекламные штампы и канцеляризмы")
1559
  print()
 
1701
 
1702
  # 2. Morphological checks using pymorphy3
1703
  morphological_checks = [
1704
+ ("no_word_repetitions", check_no_word_repetitions),
1705
  ("forbidden_words", check_forbidden_words),
 
 
1706
  ("double_verbs", check_no_double_verbs),
 
1707
  ("adverbial_participles", check_no_adverbial_participles),
1708
+ ("derived_prepositions", check_no_derived_prepositions),
1709
+ ("multiple_nouns", check_no_multiple_nouns),
1710
+ ("introductory_phrases", check_no_introductory_phrases),
1711
+ ("compound_sentences", check_no_compound_sentences),
1712
  ("superlative_adjectives", check_no_superlative_adjectives),
1713
+ ("client_addressing", check_no_greeting),
1714
+ ("promises", check_no_promises),
1715
+ ("amplifiers", check_no_amplifiers),
1716
+ ("participles", check_no_participles),
1717
  ("passive_voice", check_no_passive_voice),
1718
  ("written_out_ordinals", check_no_written_out_ordinals),
1719
  ("subordinate_clauses_chain", check_no_subordinate_clauses_chain),
1720
  ("repeating_conjunctions", check_no_repeating_conjunctions),
 
 
1721
  ("time_parasites", check_no_time_parasites),
 
 
 
1722
  ("dates_written_out", check_no_dates_written_out),
 
1723
  ]
1724
 
1725
  # 3. LLM checks: check_clickbait_phrases, check_abstract_claims, check_cliches_and_bureaucratese
1726
  llm_checks_group1 = [
 
1727
  ("no_contradictions", check_no_contradictions),
 
1728
  ("abstract_claims", check_abstract_claims),
1729
  ("cliches_and_bureaucratese", check_cliches_and_bureaucratese),
1730
+ ("clickbait_phrases", check_clickbait_phrases),
1731
+ ("contains_key_message", check_contains_key_message),
1732
+ ("synonymous_members", check_synonymous_members),
1733
+ ("product_name_consistency", check_product_name_consistency)
1734
  ]
1735
 
1736
  # 4. Remaining LLM checks
1737
  llm_checks_group2 = [
 
 
 
1738
  ("offensive_phrases", check_offensive_phrases),
1739
+ ("disconnected_sentences", check_disconnected_sentences),
1740
+ ("specialized_terms", check_specialized_terms)
1741
  ]
1742
 
1743
  # Perform morphological checks