Spaces:
Paused
Paused
Upload 2 files
Browse files447 unmodified lines44844945045145245345469 unmodified lines5245255265275285295305 unmodified lines536537538539540541542543544545546547548549550551552553447 unmodified linestry:response = requests.post(url, headers=headers, json=data, stream=True)response.raise_for_status() # This will raise an HTTPError for bad responsesif stream:return 1, response69 unmodified linescontinueelif success == 1 and response is None:continueelif success == 1 and isinstance(response, Response):return Response(stream_with_context(generate_stream(response)),mimetype='text/event-stream'5 unmodified linescompletion_tokens = response.candidates_token_counttotal_tokens = response.total_token_countfinish_reason = response.finish_reason# json_dumps = response.json_dumps# logger.info(f"AI响应处理成功↓\n{json_dumps}")if text_content == '':logger.error(f"生成内容失败↙\n{response}")continueif is_thinking and show_thoughts:text_content = response.thoughts + '\n' + text_contentexcept AttributeError:logger.error(f"生成内容失败↙\n{response}")continueexcept (StopCandidateException, BlockedPromptException) as e:logger.error(f"生成内容失败↙\n{e}")continueresponse_data = {447 unmodified lines44844945045145245345469 unmodified lines5245255265275285295305 unmodified lines536537538539540541542543544545546547548549550551552553554555556557558559560561562447 unmodified linestry:response = requests.post(url, headers=headers, json=data, stream=True)response.raise_for_status()if stream:return 1, response69 unmodified linescontinueelif success == 1 and response is None:continueelif success == 1 and stream:return Response(stream_with_context(generate_stream(response)),mimetype='text/event-stream'5 unmodified linescompletion_tokens = response.candidates_token_counttotal_tokens = response.total_token_countfinish_reason = response.finish_reasonif text_content == '':error_message = Noneif response._data and 'error' in response._data:error_message = response._data['error'].get('message')if error_message:logger.error(f"生成内容失败,API 返回错误: {error_message}")else:logger.error(f"生成内容失败: text_content 为空")continueif is_thinking and show_thoughts:text_content = response.thoughts + '\n' + text_contentexcept AttributeError as e:logger.error(f"处理响应失败,缺少必要的属性: {e}")logger.error(f"原始响应: {response._data}")continueexcept Exception as e:logger.error(f"处理响应失败: {e}")continueresponse_data = {
app.py+18-9