Browse Source

1.增加一些校验

xie 15 hours ago
parent
commit
868fdb4087
3 changed files with 11 additions and 8 deletions
  1. 9 7
      gpt/chatgpt.py
  2. 1 1
      gpt/get_article2.py
  3. 1 0
      tools/audio.py

+ 9 - 7
gpt/chatgpt.py

@@ -132,28 +132,30 @@ def get_article_gpt_pydantic(question, real_ip="localhost", demo_name="无", mod
                
                 check_result = check_fucn(str(answer))
                 if not check_result: 
-                    logger.error(answer)
-                    raise Exception(f"忽略,第{num_count + 1}次共3次,GPT的校验没有通过,校验函数:{check_fucn.__name__}")
+                    logger.warning(answer)
+                    raise ValidationError(f"忽略,第{num_count + 1}次共3次,GPT的校验没有通过,校验函数:{check_fucn.__name__}")
 
 
             simple_logger.info(f"问题日志task_id:{task_id},exercise_id:{exercise_id}\n回答日志:\n{r_json}")
             return r_json
 
         except ValidationError as e:
-            logger.error(f"gpt回复校验失败task_id:{task_id},exercise_id:{exercise_id}:")
-            logger.error(answer)
+            logger.warning(f"gpt回复校验失败task_id:{task_id},exercise_id:{exercise_id}:")
+            logger.warning(answer)
 
         except requests.exceptions.RequestException as e:
-            logger.error(f"HTTP请求错误task_id:{task_id},exercise_id:{exercise_id}: {str(e)}")
-            time.sleep(1)
+            logger.warning(f"HTTP请求错误task_id:{task_id},exercise_id:{exercise_id}: {str(e)}")
+            time.sleep(3**num_count)
 
         except json.decoder.JSONDecodeError as e:
             if 'response' in locals() and response is not None: 
-                logger.error(f"json格式化错误task_id:{task_id},exercise_id:{exercise_id}:{response.text}")
+                logger.warning(f"json格式化错误task_id:{task_id},exercise_id:{exercise_id}:{response.text}")
 
         except Exception as e:
             log_err_e(e,f"其他错误task_id:{task_id},exercise_id:{exercise_id}")
 
+    logger.critical(f"严重错误,3次后未获得正确答案")
+
 def get_annotation_gpt_pydantic(question, real_ip="localhost", demo_name="无", model="gpt-4.1", max_tokens=3500, temperature:float=0, n=1,
                         check_fucn=None, sys_prompt=None,task_id=0,exercise_id=0):
     """

+ 1 - 1
gpt/get_article2.py

@@ -274,7 +274,7 @@ class GetArticle:
         shuffle(core_words)
         core_words_meaning_str = "; ".join([f"[{i['meaning_id']}  {i['spell']} {i['meaning']}]" for i in core_words])
 
-        sys_prompt = "你是一个专业的英语老师,擅长根据用户提供的词汇生成对应的英语文章和中文翻译和4个配套选择题。"
+        sys_prompt = "你是一个专业的英语老师,擅长根据用户提供的词汇生成对应的英语文章和中文翻译和4个配套选择题。中文用utf-8格式,不要用Unicode编码。"
 
         q = f"""下面我会为你提供一组数据,[单词组](里面包含词义id,英语单词,中文词义),请根据这些单词的中文词义,\
 生成一篇带中文翻译的考场英语文章,英语文章和中文翻译要有[标题]。特别注意这个单词有多个词义时,生成的英语文章一定要用提供的中文词义,例如我提供单词[change 零钱],就不要使用[变化]的词义。

+ 1 - 0
tools/audio.py

@@ -10,6 +10,7 @@ from cachetools import TTLCache
 from hashlib import md5
 
 from core.respone_format import *
+from make_docx_demo.check_test_table.baidu_ocr import access_token
 from tools.new_mysql import MySQLUploader
 from tools.loglog import logger
 from tools.thread_pool_manager import pool_executor