From b4f37844a62f594d3e1cb05b9d36ad2aa924c036 Mon Sep 17 00:00:00 2001 From: mula Date: Mon, 26 Jan 2026 04:05:01 +0000 Subject: [PATCH 1/2] =?UTF-8?q?=E5=B0=86=E4=B8=8A=E4=BC=A0=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=A4=A7=E5=B0=8F=E6=89=A9=E5=B1=95=E5=88=B0500M?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/nginx.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/nginx.conf b/frontend/nginx.conf index acd9a68..5abc93e 100644 --- a/frontend/nginx.conf +++ b/frontend/nginx.conf @@ -13,7 +13,7 @@ server { gzip_disable "MSIE [1-6]\."; # 增加上传文件大小限制 - client_max_body_size 200M; + client_max_body_size 500M; location / { try_files $uri $uri/ /index.html; From 37d291ed434925a819bf0f6bef646a452e027744 Mon Sep 17 00:00:00 2001 From: "mula.liu" Date: Thu, 29 Jan 2026 18:38:47 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E8=BD=BD=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/services/llm_service.py | 57 ++++++----------- backend/app/services/system_config_service.py | 64 +++++++++++++++---- 2 files changed, 73 insertions(+), 48 deletions(-) diff --git a/backend/app/services/llm_service.py b/backend/app/services/llm_service.py index 1f8429f..d0831f5 100644 --- a/backend/app/services/llm_service.py +++ b/backend/app/services/llm_service.py @@ -14,31 +14,19 @@ class LLMService: # 设置dashscope API key dashscope.api_key = config_module.QWEN_API_KEY - @property - def model_name(self): - """动态获取模型名称""" - return SystemConfigService.get_llm_model_name(default="qwen-plus") + def _get_llm_call_params(self) -> Dict[str, Any]: + """ + 获取 dashscope.Generation.call() 所需的参数字典 - @property - def system_prompt(self): - """动态获取系统提示词(fallback,优先使用prompts表)""" - # 保留config中的system_prompt作为后备 - return config_module.LLM_CONFIG.get("system_prompt", "请根据提供的内容进行总结和分析。") - - @property - def time_out(self): - """动态获取超时时间""" - return SystemConfigService.get_llm_timeout(default=120) - - @property - def temperature(self): - """动态获取temperature""" - return SystemConfigService.get_llm_temperature(default=0.7) - - @property - def top_p(self): - """动态获取top_p""" - return SystemConfigService.get_llm_top_p(default=0.9) + Returns: + Dict: 包含 model、timeout、temperature、top_p 的参数字典 + """ + return { + 'model': SystemConfigService.get_llm_model_name(), + 'timeout': SystemConfigService.get_llm_timeout(), + 'temperature': SystemConfigService.get_llm_temperature(), + 'top_p': SystemConfigService.get_llm_top_p(), + } def get_task_prompt(self, task_type: str, cursor=None, prompt_id: Optional[int] = None) -> str: """ @@ -91,23 +79,21 @@ class LLMService: def _get_default_prompt(self, task_name: str) -> str: """获取默认提示词""" + system_prompt = config_module.LLM_CONFIG.get("system_prompt", "请根据提供的内容进行总结和分析。") default_prompts = { - 'MEETING_TASK': self.system_prompt, # 使用配置文件中的系统提示词 + 'MEETING_TASK': system_prompt, 'KNOWLEDGE_TASK': "请根据提供的信息生成知识库文章。", } return default_prompts.get(task_name, "请根据提供的内容进行总结和分析。") def _call_llm_api_stream(self, prompt: str) -> Generator[str, None, None]: - """流式调用阿里Qwen3大模型API""" + """流式调用阿里Qwen大模型API""" try: responses = dashscope.Generation.call( - model=self.model_name, + **self._get_llm_call_params(), prompt=prompt, stream=True, - timeout=self.time_out, - temperature=self.temperature, - top_p=self.top_p, - incremental_output=True # 开启增量输出模式 + incremental_output=True ) for response in responses: @@ -128,14 +114,11 @@ class LLMService: yield f"error: {error_msg}" def _call_llm_api(self, prompt: str) -> Optional[str]: - """调用阿里Qwen3大模型API(非流式)""" + """调用阿里Qwen大模型API(非流式)""" try: response = dashscope.Generation.call( - model=self.model_name, - prompt=prompt, - timeout=self.time_out, - temperature=self.temperature, - top_p=self.top_p + **self._get_llm_call_params(), + prompt=prompt ) if response.status_code == HTTPStatus.OK: diff --git a/backend/app/services/system_config_service.py b/backend/app/services/system_config_service.py index d9c80ad..ecc6e80 100644 --- a/backend/app/services/system_config_service.py +++ b/backend/app/services/system_config_service.py @@ -65,6 +65,47 @@ class SystemConfigService: print(f"Error getting config {dict_code}: {e}") return default_value + @classmethod + def get_config_attribute(cls, dict_code: str, attr_name: str, default_value: Any = None) -> Any: + """ + 从指定配置记录的扩展属性中读取指定属性值 + + 此方法用于处理扩展属性为复杂JSON的配置记录(如llm_model、voiceprint等) + + Args: + dict_code: 配置项编码 (如 'llm_model', 'voiceprint') + attr_name: 扩展属性中的属性名 (如 'time_out', 'channels', 'template_text') + default_value: 默认值,如果配置或属性不存在则返回此值 + + Returns: + 属性值 + """ + try: + with get_db_connection() as conn: + cursor = conn.cursor(dictionary=True) + query = """ + SELECT extension_attr + FROM dict_data + WHERE dict_type = %s AND dict_code = %s AND status = 1 + LIMIT 1 + """ + cursor.execute(query, (cls.DICT_TYPE, dict_code)) + result = cursor.fetchone() + cursor.close() + + if result and result['extension_attr']: + try: + ext_attr = json.loads(result['extension_attr']) if isinstance(result['extension_attr'], str) else result['extension_attr'] + return ext_attr.get(attr_name, default_value) + except (json.JSONDecodeError, AttributeError): + pass + + return default_value + + except Exception as e: + print(f"Error getting config attribute {dict_code}.{attr_name}: {e}") + return default_value + @classmethod def set_config(cls, dict_code: str, value: Any, label_cn: str = None) -> bool: """ @@ -181,15 +222,16 @@ class SystemConfigService: """获取ASR热词字典ID""" return cls.get_config(cls.ASR_VOCABULARY_ID) + # 声纹配置获取方法(直接使用通用方法) @classmethod def get_voiceprint_template(cls, default: str = "我正在进行声纹采集,这段语音将用于身份识别和验证。\n\n声纹技术能够准确识别每个人独特的声音特征。") -> str: """获取声纹采集模版""" - return cls.get_config(cls.VOICEPRINT_TEMPLATE_TEXT, default) + return cls.get_config_attribute('voiceprint', 'template_text', default) @classmethod def get_voiceprint_max_size(cls, default: int = 5242880) -> int: """获取声纹文件大小限制 (bytes), 默认5MB""" - value = cls.get_config(cls.VOICEPRINT_MAX_SIZE, default) + value = cls.get_config_attribute('voiceprint', 'voiceprint_max_size', default) try: return int(value) except (ValueError, TypeError): @@ -198,7 +240,7 @@ class SystemConfigService: @classmethod def get_voiceprint_duration(cls, default: int = 12) -> int: """获取声纹采集最短时长 (秒)""" - value = cls.get_config(cls.VOICEPRINT_DURATION, default) + value = cls.get_config_attribute('voiceprint', 'duration_seconds', default) try: return int(value) except (ValueError, TypeError): @@ -207,7 +249,7 @@ class SystemConfigService: @classmethod def get_voiceprint_sample_rate(cls, default: int = 16000) -> int: """获取声纹采样率""" - value = cls.get_config(cls.VOICEPRINT_SAMPLE_RATE, default) + value = cls.get_config_attribute('voiceprint', 'sample_rate', default) try: return int(value) except (ValueError, TypeError): @@ -216,7 +258,7 @@ class SystemConfigService: @classmethod def get_voiceprint_channels(cls, default: int = 1) -> int: """获取声纹通道数""" - value = cls.get_config(cls.VOICEPRINT_CHANNELS, default) + value = cls.get_config_attribute('voiceprint', 'channels', default) try: return int(value) except (ValueError, TypeError): @@ -245,16 +287,16 @@ class SystemConfigService: except (ValueError, TypeError): return default - # LLM模型配置获取方法 + # LLM模型配置获取方法(直接使用通用方法) @classmethod def get_llm_model_name(cls, default: str = "qwen-plus") -> str: """获取LLM模型名称""" - return cls.get_config(cls.LLM_MODEL_NAME, default) + return cls.get_config_attribute('llm_model', 'model_name', default) @classmethod - def get_llm_timeout(cls, default: int = 120) -> int: + def get_llm_timeout(cls, default: int = 300) -> int: """获取LLM超时时间(秒)""" - value = cls.get_config(cls.LLM_TIMEOUT, str(default)) + value = cls.get_config_attribute('llm_model', 'time_out', default) try: return int(value) except (ValueError, TypeError): @@ -263,7 +305,7 @@ class SystemConfigService: @classmethod def get_llm_temperature(cls, default: float = 0.7) -> float: """获取LLM temperature参数""" - value = cls.get_config(cls.LLM_TEMPERATURE, str(default)) + value = cls.get_config_attribute('llm_model', 'temperature', default) try: return float(value) except (ValueError, TypeError): @@ -272,7 +314,7 @@ class SystemConfigService: @classmethod def get_llm_top_p(cls, default: float = 0.9) -> float: """获取LLM top_p参数""" - value = cls.get_config(cls.LLM_TOP_P, str(default)) + value = cls.get_config_attribute('llm_model', 'top_p', default) try: return float(value) except (ValueError, TypeError):