bvd757 commited on
Commit
aff21a4
·
1 Parent(s): 407e6f0

no false errors

Browse files
Files changed (1) hide show
  1. search_errors_logic.py +32 -3
search_errors_logic.py CHANGED
@@ -2,6 +2,28 @@ import openai
2
  from openai import OpenAI
3
  import difflib
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  prompt_fix_text_gpt = """
6
  Исправь ошибки в данном тексте. Текст в makrdown и должен в результате остаться в markdown.
7
  Жаргонизмы считаются ошибками, приемлим только официальный стиль.
@@ -127,7 +149,7 @@ def get_gpt_response_vsegpt(inp):
127
  return response
128
 
129
 
130
- def get_gpt_response(inp, client_name):
131
  if client_name == "openai":
132
  return get_gpt_response_openai(inp)
133
  elif client_name == "vsegpt":
@@ -223,6 +245,10 @@ def check_text_chat_gpt(text, fixed_text=None, add_errors=False, *args, **kwargs
223
  def check_text_chat_gpt_highlight_mode(text, fixed_text=None, add_errors=False, *args, **kwargs):
224
  if fixed_text is None:
225
  fixed_text = get_gpt_response(prompt_fix_text_gpt.format(text), "vsegpt")
 
 
 
 
226
  changes = find_corrected_positions(text, fixed_text)
227
  bounds_init = []
228
  for change in changes:
@@ -244,8 +270,11 @@ def check_text_chat_gpt_highlight_mode(text, fixed_text=None, add_errors=False,
244
 
245
  errors = []
246
  for bound in bounds_result:
247
- inp = prompt_compare_get_comment.format(text[bound["start_orig"]:bound["end_orig"]],
248
- fixed_text[bound["start_corr"]:bound["end_corr"]])
 
 
 
249
  errors.append({
250
  'start': bound["start_orig"],
251
  'end': bound["end_orig"],
 
2
  from openai import OpenAI
3
  import difflib
4
 
5
+ prompt_is_there_error = """Ты — лингвистический анализатор. Тебе будут даны две текстовые строки:
6
+ 1. Оригинальный текст (точно без ошибок)
7
+ 2. Текст для проверки (может содержать ошибку или альтернативное написание)
8
+
9
+ Задача:
10
+ - Сравни второй текст с оригиналом на предмет наличия ошибок (орфографических, пунктуационных, грамматических)
11
+ - Если во втором тексте есть ошибка (отличается от оригинала и это не допустимый вариант написания) — верни 1
12
+ - Если текст совпадает с оригиналом или отличается только допустимыми вариантами написания (синонимы, альтернативная пунктуация и т.п.) — верни 0
13
+
14
+ Формат ответа — строго JSON:
15
+ ```json
16
+ {
17
+ "result": 0|1
18
+ }
19
+
20
+ Оригинальный текст:
21
+ {}
22
+
23
+ Текст для проверки:
24
+ {}
25
+ """
26
+
27
  prompt_fix_text_gpt = """
28
  Исправь ошибки в данном тексте. Текст в makrdown и должен в результате остаться в markdown.
29
  Жаргонизмы считаются ошибками, приемлим только официальный стиль.
 
149
  return response
150
 
151
 
152
+ def get_gpt_response(inp, client_name="vsegpt"):
153
  if client_name == "openai":
154
  return get_gpt_response_openai(inp)
155
  elif client_name == "vsegpt":
 
245
  def check_text_chat_gpt_highlight_mode(text, fixed_text=None, add_errors=False, *args, **kwargs):
246
  if fixed_text is None:
247
  fixed_text = get_gpt_response(prompt_fix_text_gpt.format(text), "vsegpt")
248
+
249
+ text = text.replace("ё", "е")
250
+ fixed_text = fixed_text.replace("ё", "е")
251
+
252
  changes = find_corrected_positions(text, fixed_text)
253
  bounds_init = []
254
  for change in changes:
 
270
 
271
  errors = []
272
  for bound in bounds_result:
273
+ orig_piece = text[bound["start_orig"]:bound["end_orig"]]
274
+ fixed_piece = fixed_text[bound["start_corr"]:bound["end_corr"]]
275
+ if "0" in get_gpt_response(prompt_is_there_error.format(orig_piece, fixed_piece)):
276
+ continue
277
+ inp = prompt_compare_get_comment.format(orig_piece, fixed_piece)
278
  errors.append({
279
  'start': bound["start_orig"],
280
  'end': bound["end_orig"],