ShiwenNi commited on
Commit
7fef2b8
1 Parent(s): 9778459

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -12
app.py CHANGED
@@ -72,23 +72,31 @@ class Reviewer:
72
  def chat_review(self, text):
73
  openai.api_key = self.api # 读取api
74
  review_prompt_token = 1000
75
- text_token = len(self.encoding.encode(text))
 
 
 
76
  input_text_index = int(len(text)*(self.max_token_num-review_prompt_token)/(text_token+1))
77
  input_text = "This is the paper for your review:" + text[:input_text_index]
78
  messages=[
79
  {"role": "system", "content": "You are a professional reviewer. Now I will give you a paper. You need to give a complete review opinion according to the following requirements and format:"+ self.review_format + "Be sure to use {} answers".format(self.language)} ,
80
  {"role": "user", "content": input_text + " Translate the output into {}.".format(self.language)},
81
  ]
82
-
83
- response = openai.ChatCompletion.create(
84
- model="gpt-3.5-turbo",
85
- messages=messages,
86
- )
87
- result = ''
88
- for choice in response.choices:
89
- result += choice.message.content
90
- result = insert_sentence(result, '**Generated by ChatGPT, no copying allowed!**', 30)
91
- result += "\n\n⚠伦理声明/Ethics statement:\n--禁止直接复制生成的评论用于任何论文审稿工作!\n--Direct copying of generated comments for any paper review work is prohibited!"
 
 
 
 
 
92
  print("********"*10)
93
  print(result)
94
  print("********"*10)
@@ -97,7 +105,7 @@ class Reviewer:
97
  print("total_token_used:", response.usage.total_tokens)
98
  print("response_time:", response.response_ms/1000.0, 's')
99
 
100
- return result, response.usage.total_tokens
101
 
102
 
103
 
 
72
  def chat_review(self, text):
73
  openai.api_key = self.api # 读取api
74
  review_prompt_token = 1000
75
+ try:
76
+ text_token = len(self.encoding.encode(text))
77
+ except:
78
+ text_token = 3000
79
  input_text_index = int(len(text)*(self.max_token_num-review_prompt_token)/(text_token+1))
80
  input_text = "This is the paper for your review:" + text[:input_text_index]
81
  messages=[
82
  {"role": "system", "content": "You are a professional reviewer. Now I will give you a paper. You need to give a complete review opinion according to the following requirements and format:"+ self.review_format + "Be sure to use {} answers".format(self.language)} ,
83
  {"role": "user", "content": input_text + " Translate the output into {}.".format(self.language)},
84
  ]
85
+ try:
86
+ response = openai.ChatCompletion.create(
87
+ model="gpt-3.5-turbo",
88
+ messages=messages,
89
+ )
90
+ result = ''
91
+ for choice in response.choices:
92
+ result += choice.message.content
93
+ result = insert_sentence(result, '**Generated by ChatGPT, no copying allowed!**', 50)
94
+ result += "\n\n⚠伦理声明/Ethics statement:\n--禁止直接复制生成的评论用于任何论文审稿工作!\n--Direct copying of generated comments for any paper review work is prohibited!"
95
+ usage = response.usage.total_tokens
96
+ except Exception as e:
97
+ # 处理其他的异常
98
+ result = str(e))
99
+ usage = str(e))
100
  print("********"*10)
101
  print(result)
102
  print("********"*10)
 
105
  print("total_token_used:", response.usage.total_tokens)
106
  print("response_time:", response.response_ms/1000.0, 's')
107
 
108
+ return result, usage
109
 
110
 
111