Преглед изворни кода

延长超时时间,翻译异常返回空字符串

locky пре 4 месеци
родитељ
комит
76032246d7
1 измењених фајлова са 10 додато и 9 уклоњено
  1. 10 9
      controller/LangArea.py

+ 10 - 9
controller/LangArea.py

@@ -280,17 +280,18 @@ class LangAreaView(TemplateView):
             # 控制采样随机性的浮点数,值较低时模型更具确定性,值较高时模型更具创造性。"0"表示贪婪取样。默认为0.6。
             "temperature": 0.6
         }
+        content = ''
         # 延迟请求
         time.sleep(1.1)
-        response = requests.post(url, headers=headers, data=json.dumps(data), verify=False, timeout=10)
-        text = json.loads(response.text)
-        choices = text.get('choices')
-        content = ''
-        if choices is None:
-            print(text)
-        else:
-            content = choices[0]['message']['content']
-        return content
+        try:
+            response = requests.post(url, headers=headers, data=json.dumps(data), verify=False, timeout=60)
+            text = json.loads(response.text)
+            choices = text.get('choices')
+            if choices is not None:
+                content = choices[0]['message']['content']
+            return content
+        except Exception as e:
+            return content
 
     def do_download_avss(self, id):
         content = ''