ShiwenNi commited on
Commit
8619cac
1 Parent(s): 8c348ec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -3
app.py CHANGED
@@ -14,8 +14,9 @@ import gradio
14
  # 定义Response类
15
  class Response:
16
  # 初始化方法,设置属性
17
- def __init__(self, api, comment, language):
18
  self.api = api
 
19
  self.comment = comment
20
  self.language = language
21
  self.max_token_num = 14096
@@ -27,6 +28,7 @@ class Response:
27
  reraise=True)
28
  def chat_response(self, comment):
29
  openai.api_key = self.api
 
30
  response_prompt_token = 1000
31
  text_token = len(self.encoding.encode(comment))
32
  input_text_index = int(len(comment)*(self.max_token_num-response_prompt_token)/text_token)
@@ -82,12 +84,12 @@ class Response:
82
 
83
 
84
 
85
- def main(api, comment, language):
86
  start_time = time.time()
87
  if not api or not comment:
88
  return "请输入API-key以及审稿意见!"
89
  else:
90
- Response1 = Response(api, comment, language)
91
  # 开始判断是路径还是文件:
92
  response, total_token_used = Response1.chat_response(comment)
93
  time_used = time.time() - start_time
@@ -118,6 +120,8 @@ description = '''<div align='left'>
118
  inp = [gradio.inputs.Textbox(label="请输入你的API-key(sk开头的字符串)",
119
  default="",
120
  type='password'),
 
 
121
  gradio.inputs.Textbox(lines=5,
122
  label="请输入要回复的审稿意见",
123
  default=""
 
14
  # 定义Response类
15
  class Response:
16
  # 初始化方法,设置属性
17
+ def __init__(self, api, api_base, comment, language):
18
  self.api = api
19
+ self.api_base = api_base
20
  self.comment = comment
21
  self.language = language
22
  self.max_token_num = 14096
 
28
  reraise=True)
29
  def chat_response(self, comment):
30
  openai.api_key = self.api
31
+ openai.api_base = self.api_base
32
  response_prompt_token = 1000
33
  text_token = len(self.encoding.encode(comment))
34
  input_text_index = int(len(comment)*(self.max_token_num-response_prompt_token)/text_token)
 
84
 
85
 
86
 
87
+ def main(api, api_base, comment, language):
88
  start_time = time.time()
89
  if not api or not comment:
90
  return "请输入API-key以及审稿意见!"
91
  else:
92
+ Response1 = Response(api,api_base, comment, language)
93
  # 开始判断是路径还是文件:
94
  response, total_token_used = Response1.chat_response(comment)
95
  time_used = time.time() - start_time
 
120
  inp = [gradio.inputs.Textbox(label="请输入你的API-key(sk开头的字符串)",
121
  default="",
122
  type='password'),
123
+ gradio.inputs.Textbox(label="请输入第三方中转网址(以/v1结尾,使用原始OpenAI的API请跳过这里)",
124
+ default="https://api.openai.com/v1"),
125
  gradio.inputs.Textbox(lines=5,
126
  label="请输入要回复的审稿意见",
127
  default=""