Update app.py
Browse files
app.py
CHANGED
|
@@ -93,31 +93,30 @@ def ask_image(text,image,api_token=openai_api_key):
|
|
| 93 |
max_retry = 3
|
| 94 |
|
| 95 |
for i in range(max_retry):
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
|
| 109 |
-
except Exception as e:
|
| 110 |
-
# 如果已经达到最大重试次数,那么返回空值
|
| 111 |
-
if i == max_retry - 1:
|
| 112 |
-
print(f'重试次数已达上限,仍未能成功获取数据,错误信息:{e}')
|
| 113 |
-
response_content = ''
|
| 114 |
-
usage = {}
|
| 115 |
-
return response_content
|
| 116 |
-
else:
|
| 117 |
-
# 如果未达到最大重试次数,打印错误信息,并继续下一次循环
|
| 118 |
-
print(f'第{i+1}次请求失败,错误信息:{e},准备进行第{i+2}次尝试')
|
| 119 |
-
|
| 120 |
-
supabase_insert_ask_image(text,public_url,response_content)
|
| 121 |
|
| 122 |
|
| 123 |
# gradio demo
|
|
|
|
| 93 |
max_retry = 3
|
| 94 |
|
| 95 |
for i in range(max_retry):
|
| 96 |
+
try:
|
| 97 |
+
# 发送请求
|
| 98 |
+
response = requests.post('https://burn.hair/v1/chat/completions', headers=headers, json=data)
|
| 99 |
+
|
| 100 |
+
# 解析响应内容
|
| 101 |
+
response_data = response.json()
|
| 102 |
+
response_content = response_data['choices'][0]['message']['content']
|
| 103 |
+
usage = response_data['usage']
|
| 104 |
+
|
| 105 |
+
supabase_insert_ask_image(text,public_url,response_content)
|
| 106 |
+
return response_content
|
| 107 |
+
|
| 108 |
+
except Exception as e:
|
| 109 |
+
# 如果已经达到最大重试次数,那么返回空值
|
| 110 |
+
if i == max_retry - 1:
|
| 111 |
+
print(f'重试次数已达上限,仍未能成功获取数据,错误信息:{e}')
|
| 112 |
+
response_content = ''
|
| 113 |
+
usage = {}
|
| 114 |
+
return response_content
|
| 115 |
+
else:
|
| 116 |
+
# 如果未达到最大重试次数,打印错误信息,并继续下一次循环
|
| 117 |
+
print(f'第{i+1}次请求失败,错误信息:{e},准备进行第{i+2}次尝试')
|
| 118 |
+
|
| 119 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
|
| 121 |
|
| 122 |
# gradio demo
|