소스 검색

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

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 = ''