bvd757 commited on
Commit
9919e6f
·
1 Parent(s): 2c0b608

new key and other

Browse files
Files changed (2) hide show
  1. app.py +1 -1
  2. search_errors_logic.py +17 -13
app.py CHANGED
@@ -66,7 +66,7 @@ def install_java():
66
 
67
  @st.cache_resource
68
  def load_assets():
69
- openai.api_key = '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'
70
  install_java()
71
  tool = language_tool_python.LanguageTool('ru-RU',
72
  language_tool_download_version="6.1")
 
66
 
67
  @st.cache_resource
68
  def load_assets():
69
+ openai.api_key = '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'
70
  install_java()
71
  tool = language_tool_python.LanguageTool('ru-RU',
72
  language_tool_download_version="6.1")
search_errors_logic.py CHANGED
@@ -4,14 +4,15 @@ import difflib
4
 
5
  prompt_fix_text_gpt = """
6
  Исправь ошибки в данном тексте. Жаргонизмы считаются ошибками, приемлим только официальный стиль.
 
7
  Верни только текст, никаких комментариев от себя не оставляй
8
 
9
  ### Пример 1:
10
  input text:
11
- досвиданя кошак
12
 
13
  Твой ответ:
14
- До свидания, кошка
15
 
16
 
17
  Теперь твоя очередь:
@@ -111,8 +112,8 @@ def get_gpt_response_openai(inp):
111
 
112
  def get_gpt_response_vsegpt(inp):
113
  client = OpenAI(
114
- api_key='sk-or-vv-44ca318747a45e810149bf769e9dfbe5f42046695875efd7c9121cca590d6906',
115
- base_url='https://api.vsegpt.ru/v1'
116
  )
117
  response = client.chat.completions.create(
118
  model="gpt-4o-mini",
@@ -160,7 +161,7 @@ def get_piece_of_text_bounds(s, start, end):
160
  return start, end
161
 
162
 
163
- def add_comments_to_text(text, errors):
164
  errors = sorted(errors, key=lambda x: x['end'])
165
 
166
  shift = 0
@@ -168,21 +169,24 @@ def add_comments_to_text(text, errors):
168
  error['start'] += shift
169
  error['end'] += shift
170
  inp = f"({i})"
 
 
171
  text = text[:error['end']] + inp + text[error['end']:]
172
  shift += len(inp)
173
 
174
  return text.replace("\n", " ")
175
 
176
 
177
- def check_text(text, tool, mode):
178
  if mode == "tool":
179
- return check_text_with_tool(text, tool)
180
  else:
181
- return check_text_chat_gpt(text)
182
 
183
 
184
- def check_text_chat_gpt(text, *args, **kwargs):
185
- fixed_text = get_gpt_response(prompt_fix_text_gpt.format(text), "vsegpt")
 
186
  changes = find_corrected_positions(text, fixed_text)
187
  errors = []
188
  for change in changes:
@@ -195,11 +199,11 @@ def check_text_chat_gpt(text, *args, **kwargs):
195
  'message': get_gpt_response(inp, client_name="vsegpt"),
196
  })
197
 
198
- text_with_comments = add_comments_to_text(text, errors)
199
  return text_with_comments, errors
200
 
201
 
202
- def check_text_with_tool(text, tool):
203
  matches = tool.check(text)
204
  errors = []
205
  for match in matches:
@@ -212,5 +216,5 @@ def check_text_with_tool(text, tool):
212
  }
213
  errors.append(error_info)
214
 
215
- text_with_comments = add_comments_to_text(text, errors)
216
  return text_with_comments, errors
 
4
 
5
  prompt_fix_text_gpt = """
6
  Исправь ошибки в данном тексте. Жаргонизмы считаются ошибками, приемлим только официальный стиль.
7
+ Обязательно проверяй, не заменена ли где-то буква "ё" на букву "е". Это считается грубой ошибкой.
8
  Верни только текст, никаких комментариев от себя не оставляй
9
 
10
  ### Пример 1:
11
  input text:
12
+ досвиданя кошак, это твое
13
 
14
  Твой ответ:
15
+ До свидания, кошка, это твоё
16
 
17
 
18
  Теперь твоя очередь:
 
112
 
113
  def get_gpt_response_vsegpt(inp):
114
  client = OpenAI(
115
+ api_key='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',
116
+ base_url='https://openrouter.ai/api/v1'
117
  )
118
  response = client.chat.completions.create(
119
  model="gpt-4o-mini",
 
161
  return start, end
162
 
163
 
164
+ def add_comments_to_text(text, errors, add_errors=False):
165
  errors = sorted(errors, key=lambda x: x['end'])
166
 
167
  shift = 0
 
169
  error['start'] += shift
170
  error['end'] += shift
171
  inp = f"({i})"
172
+ if add_errors:
173
+ inp = inp[:-1] + ' - ' + error['message'] + ')'
174
  text = text[:error['end']] + inp + text[error['end']:]
175
  shift += len(inp)
176
 
177
  return text.replace("\n", " ")
178
 
179
 
180
+ def check_text(text, tool, mode="chat_gpt", add_errors=False):
181
  if mode == "tool":
182
+ return check_text_with_tool(text, tool, add_errors=add_errors)
183
  else:
184
+ return check_text_chat_gpt(text, add_errors=add_errors)
185
 
186
 
187
+ def check_text_chat_gpt(text, fixed_text=None, add_errors=False, *args, **kwargs):
188
+ if fixed_text is None:
189
+ fixed_text = get_gpt_response(prompt_fix_text_gpt.format(text), "vsegpt")
190
  changes = find_corrected_positions(text, fixed_text)
191
  errors = []
192
  for change in changes:
 
199
  'message': get_gpt_response(inp, client_name="vsegpt"),
200
  })
201
 
202
+ text_with_comments = add_comments_to_text(text, errors, add_errors=add_errors)
203
  return text_with_comments, errors
204
 
205
 
206
+ def check_text_with_tool(text, tool, add_errors=False):
207
  matches = tool.check(text)
208
  errors = []
209
  for match in matches:
 
216
  }
217
  errors.append(error_info)
218
 
219
+ text_with_comments = add_comments_to_text(text, errors, add_errors=add_errors)
220
  return text_with_comments, errors