fix(deep-analyzer, srt): correct Zhipu API thinking parameter and fix metadata handling
Root cause: 1. thinking.type="disabled" caused ASR correction accuracy degradation 2. SRTProcessor didn't flatten nested metadata structure 3. Low-quality auto-generated summary section 4. duration field type handling issue Changes: - DeepAnalyzer: Remove thinking.type="disabled" to enable default thinking mode - SRTProcessor: Add metadata flattening for nested structures - SRTProcessor: Remove low-quality summary section generation - SRTProcessor: Add duration type checking (string or int) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -95,28 +95,30 @@ class SimpleAIClient:
|
||||
base_url = base_url or "https://open.bigmodel.cn/api/coding/paas/v4"
|
||||
url = f"{base_url}/chat/completions"
|
||||
headers = {"Authorization": f"Bearer {api_key}"}
|
||||
# GLM-4.5/4.6/4.7/5 默认启用thinking mode,使用 thinking.type 参数禁用
|
||||
# GLM-4.5/4.6/4.7/5 默认启用thinking mode
|
||||
# 移除 thinking.type="disabled",让AI使用默认思考模式以提高准确性
|
||||
payload = {
|
||||
"model": model,
|
||||
"messages": [{"role": "user", "content": prompt}],
|
||||
"max_tokens": max_tokens,
|
||||
"thinking": {
|
||||
"type": "disabled" # 禁用思考模式,获取直接响应
|
||||
}
|
||||
"max_tokens": max_tokens
|
||||
}
|
||||
response = requests.post(url, headers=headers, json=payload, timeout=600)
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
message = data.get('choices', [{}])[0].get('message', {})
|
||||
|
||||
# 优先返回 content 字段
|
||||
content = message.get('content', '')
|
||||
|
||||
# 如果 content 为空但有 reasoning_content,使用 reasoning_content
|
||||
if not content:
|
||||
# 如果仍然为空,检查是否有reasoning_content(用于调试)
|
||||
reasoning = message.get('reasoning_content', '')
|
||||
if reasoning:
|
||||
print(f"[DEBUG] Zhipu API返回空的content,但有reasoning_content。", file=sys.stderr)
|
||||
print(f"[DEBUG] 这可能表示thinking.type参数未生效或模型不支持。", file=sys.stderr)
|
||||
print(f"[DEBUG] Zhipu API返回空的content,使用reasoning_content。", file=sys.stderr)
|
||||
print(f"[DEBUG] reasoning_content前200字符: {reasoning[:200]}", file=sys.stderr)
|
||||
content = reasoning
|
||||
|
||||
if not content:
|
||||
raise ValueError(f"Zhipu API返回空内容。请检查API配置和模型参数。响应数据: {data}")
|
||||
|
||||
return content
|
||||
|
||||
@@ -166,7 +166,7 @@ class SRTProcessor(BaseProcessor):
|
||||
metadata_file: 元数据文件路径
|
||||
|
||||
Returns:
|
||||
元数据字典
|
||||
元数据字典(扁平化后的)
|
||||
"""
|
||||
path = Path(metadata_file)
|
||||
if not path.exists():
|
||||
@@ -174,7 +174,21 @@ class SRTProcessor(BaseProcessor):
|
||||
return {}
|
||||
|
||||
with open(path, 'r', encoding='utf-8') as f:
|
||||
return json.load(f)
|
||||
raw_metadata = json.load(f)
|
||||
|
||||
# 扁平化嵌套结构(与 AnalyzeProcessor._normalize_metadata 一致)
|
||||
if not raw_metadata:
|
||||
return {}
|
||||
|
||||
# 如果已经是扁平结构(顶层有 title)
|
||||
if 'title' in raw_metadata:
|
||||
return raw_metadata
|
||||
|
||||
# 处理嵌套结构 {metadata: {...}, stats: {...}}
|
||||
if 'metadata' in raw_metadata:
|
||||
return raw_metadata['metadata'].copy()
|
||||
|
||||
return raw_metadata
|
||||
|
||||
def _extract_tags(self, paragraphs: List[str]) -> List[str]:
|
||||
"""从段落中提取标签
|
||||
@@ -216,16 +230,7 @@ class SRTProcessor(BaseProcessor):
|
||||
# 构建内容
|
||||
content_parts = [frontmatter, ""]
|
||||
|
||||
# 添加摘要(可选)
|
||||
if paragraphs:
|
||||
content_parts.append("## 摘要")
|
||||
content_parts.append("")
|
||||
# 使用第一段作为简单摘要
|
||||
first_para = paragraphs[0][:200] if len(paragraphs[0]) > 200 else paragraphs[0]
|
||||
content_parts.append(first_para + ("..." if len(paragraphs[0]) > 200 else ""))
|
||||
content_parts.append("")
|
||||
|
||||
# 添加内容
|
||||
# 直接添加内容,不生成摘要部分
|
||||
content_parts.append("## 内容")
|
||||
content_parts.append("")
|
||||
for para in paragraphs:
|
||||
@@ -271,7 +276,12 @@ class SRTProcessor(BaseProcessor):
|
||||
# 时长(视频)
|
||||
duration = metadata.get('duration', 0)
|
||||
if duration:
|
||||
duration_str = self._format_duration(duration)
|
||||
# 如果 duration 已经是字符串格式(如 "05:42"),直接使用
|
||||
# 否则(整数秒数)调用 _format_duration 转换
|
||||
if isinstance(duration, str):
|
||||
duration_str = duration
|
||||
else:
|
||||
duration_str = self._format_duration(duration)
|
||||
lines.append(f'duration: {duration_str}')
|
||||
|
||||
# BVID
|
||||
|
||||
Reference in New Issue
Block a user