deeme commited on
Commit
02ad3b5
·
verified ·
1 Parent(s): 8247a3a

Upload free_ask_internet.py

Browse files
Files changed (1) hide show
  1. free_ask_internet.py +13 -0
free_ask_internet.py CHANGED
@@ -218,6 +218,19 @@ def summary_gpt(message, model:str, debug=False):
218
  'Authorization': 'Bearer {}'.format(pooltoken),
219
  }
220
  response = requests.post( apiurl + '/chat/completions', headers=headers, json=json_data )
 
 
 
 
 
 
 
 
 
 
 
 
 
221
  res = json.loads(response.text)['choices'][0]['message']['content']
222
  #print(res)
223
  return res
 
218
  'Authorization': 'Bearer {}'.format(pooltoken),
219
  }
220
  response = requests.post( apiurl + '/chat/completions', headers=headers, json=json_data )
221
+
222
+ response_json = response.json()
223
+
224
+ # 检查响应中是否有 choices 字段,并且至少有一个元素
225
+ if 'choices' in response_json and response_json['choices']:
226
+ # 检查 choices 中的第一个元素是否有 message 字段
227
+ if 'message' in response_json['choices'][0]:
228
+ res = response_json['choices'][0]['message'].get('content', '')
229
+ else:
230
+ res = ''
231
+ else:
232
+ res = ''
233
+
234
  res = json.loads(response.text)['choices'][0]['message']['content']
235
  #print(res)
236
  return res