ShiwenNi commited on
Commit
2d19928
1 Parent(s): 4b2f709

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -17
app.py CHANGED
@@ -61,22 +61,22 @@ class Response:
61
  },
62
  {"role": "user", "content": input_text},
63
  ]
64
-
65
- response = openai.ChatCompletion.create(
66
- model="gpt-3.5-turbo",
67
- messages=messages,
68
- )
69
- result = ''
70
- for choice in response.choices:
71
- result += choice.message.content
 
 
 
 
72
  print("********"*10)
73
  print(result)
74
- print("********"*10)
75
- print("prompt_token_used:", response.usage.prompt_tokens)
76
- print("completion_token_used:", response.usage.completion_tokens)
77
- print("total_token_used:", response.usage.total_tokens)
78
- print("response_time:", response.response_ms/1000.0, 's')
79
- return result, response.usage.total_tokens
80
 
81
 
82
 
@@ -107,9 +107,9 @@ description = '''<div align='left'>
107
 
108
  如果觉得很卡,可以点击右上角的Duplicate this Space,把ChatResponse复制到你自己的Space中!
109
 
110
- 本项目的[Github](https://github.com/nishiwen1214/ChatReviewer),欢迎Star和Fork,也欢迎大佬赞助让本项目快速成长!💗([获取Api Key]
111
 
112
- **很多人留言没有ChatGPT的API-key…不会申请API的可以加我微信"Shiwen_Ni"(注:本人不卖号,真不会的可以找我,备注api)**
113
  </div>
114
  '''
115
 
@@ -121,7 +121,7 @@ inp = [gradio.inputs.Textbox(label="请输入你的API-key(sk开头的字符串)
121
  label="请输入要回复的审稿意见",
122
  default=""
123
  ),
124
- gradio.inputs.Radio(choices=["English", "Chinese"],
125
  default="English",
126
  label="选择输出语言"),
127
  ]
 
61
  },
62
  {"role": "user", "content": input_text},
63
  ]
64
+ try:
65
+ response = openai.ChatCompletion.create(
66
+ model="gpt-3.5-turbo",
67
+ messages=messages,
68
+ )
69
+ result = ''
70
+ for choice in response.choices:
71
+ result += choice.message.content
72
+ except Exception as e:
73
+ # 处理其他的异常
74
+ result = "非常抱歉>_<,生了一个错误:"+ str(e)
75
+ usage = 'xxxxx'
76
  print("********"*10)
77
  print(result)
78
+ print("********"*10)
79
+ return result, usage
 
 
 
 
80
 
81
 
82
 
 
107
 
108
  如果觉得很卡,可以点击右上角的Duplicate this Space,把ChatResponse复制到你自己的Space中!
109
 
110
+ 本项目的[Github](https://github.com/nishiwen1214/ChatReviewer),欢迎Star和Fork,也欢迎大佬赞助让本项目快速成长!💗
111
 
112
+ **很多人留言没有ChatGPT的API-key…不会申请API的可以加我微信"Shiwen_Ni"(备注api)**
113
  </div>
114
  '''
115
 
 
121
  label="请输入要回复的审稿意见",
122
  default=""
123
  ),
124
+ gradio.inputs.Radio(choices=["English", "Chinese", "French", "German","Japenese"],
125
  default="English",
126
  label="选择输出语言"),
127
  ]