doco: LLM提供方从DeepSeek切换到小米MiMo 2.5 Pro
环境变量名 DEEPSEEK_* → LLM_*(通用化),默认模型改为 mimo-v2.5-pro。 涉及 llm.py / term_extract.py / video_split.py 三文件,纯重命名,逻辑不变。 API已验证连通。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -24,9 +24,9 @@ try:
|
|||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
DEEPSEEK_API_KEY = os.environ.get("DEEPSEEK_API_KEY", "").strip()
|
LLM_API_KEY = os.environ.get("LLM_API_KEY", "").strip()
|
||||||
DEEPSEEK_BASE_URL = os.environ.get("DEEPSEEK_BASE_URL", "https://api.deepseek.com").strip()
|
LLM_BASE_URL = os.environ.get("LLM_BASE_URL", "https://api.xiaomimimo.com/v1").strip()
|
||||||
DEEPSEEK_MODEL = os.environ.get("DEEPSEEK_MODEL", "deepseek-v4-pro").strip()
|
LLM_MODEL = os.environ.get("LLM_MODEL", "mimo-v2.5-pro").strip()
|
||||||
|
|
||||||
|
|
||||||
class LLMConfigError(Exception):
|
class LLMConfigError(Exception):
|
||||||
@@ -37,15 +37,15 @@ class LLMConfigError(Exception):
|
|||||||
|
|
||||||
def _get_client():
|
def _get_client():
|
||||||
"""内部:创建并返回 openai.OpenAI 客户端实例。key 缺失时抛 LLMConfigError。"""
|
"""内部:创建并返回 openai.OpenAI 客户端实例。key 缺失时抛 LLMConfigError。"""
|
||||||
if not DEEPSEEK_API_KEY:
|
if not LLM_API_KEY:
|
||||||
raise LLMConfigError("DEEPSEEK_API_KEY 未配置或为空")
|
raise LLMConfigError("LLM_API_KEY 未配置或为空")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from openai import OpenAI
|
from openai import OpenAI
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise LLMConfigError("openai 库未安装,请执行 pip install openai")
|
raise LLMConfigError("openai 库未安装,请执行 pip install openai")
|
||||||
|
|
||||||
return OpenAI(api_key=DEEPSEEK_API_KEY, base_url=DEEPSEEK_BASE_URL)
|
return OpenAI(api_key=LLM_API_KEY, base_url=LLM_BASE_URL)
|
||||||
|
|
||||||
|
|
||||||
def chat(
|
def chat(
|
||||||
@@ -62,7 +62,7 @@ def chat(
|
|||||||
|
|
||||||
参数:
|
参数:
|
||||||
messages: 标准 messages 列表 [{"role": "user", "content": ...}]
|
messages: 标准 messages 列表 [{"role": "user", "content": ...}]
|
||||||
model: 模型名,默认从 DEEPSEEK_MODEL 环境变量读取(未设置则 deepseek-v4-pro)
|
model: 模型名,默认从 LLM_MODEL 环境变量读取(未设置则 mimo-v2.5-pro)
|
||||||
temperature: 温度,默认 0.0
|
temperature: 温度,默认 0.0
|
||||||
max_tokens: 最大输出 token 数,默认 4096
|
max_tokens: 最大输出 token 数,默认 4096
|
||||||
thinking: None=不传(默认行为),True=开启,False=传 extra_body 关闭 thinking
|
thinking: None=不传(默认行为),True=开启,False=传 extra_body 关闭 thinking
|
||||||
@@ -76,7 +76,7 @@ def chat(
|
|||||||
openai 库自身的认证/网络/API 异常 — 打印原始响应后重新上抛,不吞错
|
openai 库自身的认证/网络/API 异常 — 打印原始响应后重新上抛,不吞错
|
||||||
"""
|
"""
|
||||||
if model is None:
|
if model is None:
|
||||||
model = DEEPSEEK_MODEL
|
model = LLM_MODEL
|
||||||
|
|
||||||
client = _get_client()
|
client = _get_client()
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ from typing import Dict, List, Set, Tuple, Optional
|
|||||||
# ====================================================================
|
# ====================================================================
|
||||||
# 统一 LLM 客户端(DeepSeek,OpenAI 兼容协议)
|
# 统一 LLM 客户端(DeepSeek,OpenAI 兼容协议)
|
||||||
# ====================================================================
|
# ====================================================================
|
||||||
from .llm import chat as llm_chat, LLMConfigError, DEEPSEEK_MODEL
|
from .llm import chat as llm_chat, LLMConfigError, LLM_MODEL
|
||||||
|
|
||||||
|
|
||||||
# ====================================================================
|
# ====================================================================
|
||||||
@@ -163,7 +163,7 @@ def extract_rules(text: str) -> List[Dict]:
|
|||||||
# B) AI 层(DeepSeek)
|
# B) AI 层(DeepSeek)
|
||||||
# ====================================================================
|
# ====================================================================
|
||||||
|
|
||||||
DEEPSEEK_TERM_PROMPT = """你是一名军事科技编辑,请从以下节目文稿中提取专有名词,用于构建术语词典。
|
LLM_TERM_PROMPT = """你是一名军事科技编辑,请从以下节目文稿中提取专有名词,用于构建术语词典。
|
||||||
|
|
||||||
任务要求:
|
任务要求:
|
||||||
1. 提取所有武器/装备名称、型号/番号、单位/部队番号、人物(主持人/专家)、组织机构、技术概念
|
1. 提取所有武器/装备名称、型号/番号、单位/部队番号、人物(主持人/专家)、组织机构、技术概念
|
||||||
@@ -186,11 +186,11 @@ DEEPSEEK_TERM_PROMPT = """你是一名军事科技编辑,请从以下节目文
|
|||||||
|
|
||||||
def call_llm(text: str) -> List[Dict]:
|
def call_llm(text: str) -> List[Dict]:
|
||||||
"""调 DeepSeek API(通过统一 LLM 客户端)提取术语"""
|
"""调 DeepSeek API(通过统一 LLM 客户端)提取术语"""
|
||||||
model = DEEPSEEK_MODEL # 从 doco/.env 读取,默认 deepseek-v4-pro
|
model = LLM_MODEL
|
||||||
print(f"[C1] 调用模型: {model}", file=sys.stderr)
|
print(f"[C1] 调用模型: {model}", file=sys.stderr)
|
||||||
try:
|
try:
|
||||||
raw = llm_chat(
|
raw = llm_chat(
|
||||||
messages=[{"role": "user", "content": DEEPSEEK_TERM_PROMPT.format(text=text[:32000])}],
|
messages=[{"role": "user", "content": LLM_TERM_PROMPT.format(text=text[:32000])}],
|
||||||
model=model,
|
model=model,
|
||||||
temperature=0.0,
|
temperature=0.0,
|
||||||
max_tokens=4000,
|
max_tokens=4000,
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import imagehash
|
|||||||
# 凭证(从环境变量读取,供 OCR 调用 DeepSeek Vision)
|
# 凭证(从环境变量读取,供 OCR 调用 DeepSeek Vision)
|
||||||
# ========================================================================
|
# ========================================================================
|
||||||
|
|
||||||
DEEPSEEK_API_KEY = os.environ.get("DEEPSEEK_API_KEY", "").strip()
|
LLM_API_KEY = os.environ.get("LLM_API_KEY", "").strip()
|
||||||
|
|
||||||
|
|
||||||
# ========================================================================
|
# ========================================================================
|
||||||
@@ -398,7 +398,7 @@ def ocr_frame(image_path: Path) -> str:
|
|||||||
P1: 返回占位文本
|
P1: 返回占位文本
|
||||||
P2: 调用 DeepSeek Vision API
|
P2: 调用 DeepSeek Vision API
|
||||||
"""
|
"""
|
||||||
if not DEEPSEEK_API_KEY:
|
if not LLM_API_KEY:
|
||||||
return f"[OCR待填充 frame={image_path.name}]"
|
return f"[OCR待填充 frame={image_path.name}]"
|
||||||
return f"[OCR待填充 frame={image_path.name}]"
|
return f"[OCR待填充 frame={image_path.name}]"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user