ashokpoudel commited on
Commit
f031242
·
1 Parent(s): 2fa63a8
SynonymEditor.py CHANGED
@@ -15,19 +15,21 @@ class SynonymEditor:
15
 
16
  # Play with the prompts here and change the return index to change and see the effect of the prompt on the output quality
17
  # Note that the longer the prompt, higher the token used and hence the billing
18
- def _get_prompt(self, sentence):
19
- if "__QUOTE__" in sentence:
20
- return "Replace exactly one word with a synonym while preserving __QUOTE__ in the following sentence:\n"+sentence+"\n"
 
 
 
21
  else:
22
- return "Replace exactly one word with a synonym in the following sentence:\n"+sentence+"\n"
 
23
 
24
  # Call the OpenAI API here
25
 
26
  def __call_ai(self, sentence, few_shots):
27
- if (few_shots):
28
- prompt = few_shots + "\nInput:" + sentence + " Output:"
29
- else:
30
- prompt = self._get_prompt(sentence)
31
  response = openai.Completion.create(
32
  model=self.model_engine,
33
  prompt=prompt,
@@ -40,8 +42,9 @@ class SynonymEditor:
40
  return self._post_process_sentence(response.choices[0].text.strip())
41
 
42
  # Split the paragraph to preserve quotation marks
43
- def _split_into_sentences(self, text):
44
- text = text.replace('"', '__QUOTE__')
 
45
  text = re.sub(r'\s+', ' ', text)
46
  text = text.strip()
47
  sentences = sent_tokenize(text)
@@ -56,7 +59,7 @@ class SynonymEditor:
56
  paragraphs = text.split("\n\n")
57
  edited_paragraphs = []
58
  for paragraph in paragraphs:
59
- sentences = self._split_into_sentences(paragraph)
60
  edited_sentences = []
61
  for sentence in sentences:
62
  new_sentence = self.__call_ai(sentence, few_shots)
 
15
 
16
  # Play with the prompts here and change the return index to change and see the effect of the prompt on the output quality
17
  # Note that the longer the prompt, higher the token used and hence the billing
18
+ def _get_prompt(self, sentence, few_shots):
19
+ if (few_shots):
20
+ prompt = "Replace exactly one word with a synonym while preserving the overall sentence structure and meaning.\n" + \
21
+ few_shots + "\nInput:" + sentence + " Output:"
22
+ elif "__QUOTE__" in sentence:
23
+ prompt = "Replace exactly one word with a synonym while preserving __QUOTE__ in the following sentence:\n"+sentence+"\n"
24
  else:
25
+ prompt = "Replace exactly one word with a synonym in the following sentence:\n"+sentence+"\n"
26
+ return prompt
27
 
28
  # Call the OpenAI API here
29
 
30
  def __call_ai(self, sentence, few_shots):
31
+ prompt = self._get_prompt(sentence, few_shots)
32
+ print(prompt)
 
 
33
  response = openai.Completion.create(
34
  model=self.model_engine,
35
  prompt=prompt,
 
42
  return self._post_process_sentence(response.choices[0].text.strip())
43
 
44
  # Split the paragraph to preserve quotation marks
45
+ def _split_into_sentences(self, text, few_shots):
46
+ if (few_shots == False):
47
+ text = text.replace('"', '__QUOTE__')
48
  text = re.sub(r'\s+', ' ', text)
49
  text = text.strip()
50
  sentences = sent_tokenize(text)
 
59
  paragraphs = text.split("\n\n")
60
  edited_paragraphs = []
61
  for paragraph in paragraphs:
62
+ sentences = self._split_into_sentences(paragraph, few_shots)
63
  edited_sentences = []
64
  for sentence in sentences:
65
  new_sentence = self.__call_ai(sentence, few_shots)
__pycache__/SynonymEditor.cpython-39.pyc CHANGED
Binary files a/__pycache__/SynonymEditor.cpython-39.pyc and b/__pycache__/SynonymEditor.cpython-39.pyc differ
 
__pycache__/app.cpython-39.pyc CHANGED
Binary files a/__pycache__/app.cpython-39.pyc and b/__pycache__/app.cpython-39.pyc differ