mirror of
https://github.com/JefferyHcool/BiliNote.git
synced 2026-06-12 03:00:09 +08:00
- whisper: model.bin 截断/损坏时删目录重下重试一次,修「Unable to
open file model.bin」死循环;mlx 同样按 config.json 判完整性
- /generate_note 加就绪门禁:本地转写引擎模型没下好直接拦截,返回
reason=transcriber_model_not_ready,不让任务静默卡在首次下载
- 全局代理:新增 ProxyConfigManager(JSON 配置 + HTTP_PROXY env 兜底)
+ build_openai_client,统一注入代理到 LLM/Groq 客户端;yt-dlp 与
youtube-transcript-api 也走代理
- build_openai_client 校验 api_key 非空,空 key 给「xxx 的 API Key
未配置」而不是天书般的 Illegal header value b'Bearer '
- universal_gpt: 模型拒绝自定义 temperature(o1/o3/gpt-5 系列)时
就地去掉参数重试,不消耗重试预算
- connect_test 改用真实 chat completion 而非 /v1/models 探测
- main.py: lifespan 拆 [startup 1/5..5/5] 分段日志 + 异常清晰定位
- /sys_health 重构为结构化返回 {backend,ffmpeg,db,whisper_model}
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
60 lines
2.1 KiB
Python
60 lines
2.1 KiB
Python
from typing import List
|
|
from app.gpt.base import GPT
|
|
from app.utils.openai_client import build_openai_client
|
|
from app.gpt.prompt import BASE_PROMPT, AI_SUM, SCREENSHOT
|
|
from app.gpt.utils import fix_markdown
|
|
from app.models.gpt_model import GPTSource
|
|
from app.models.transcriber_model import TranscriptSegment
|
|
from datetime import timedelta
|
|
|
|
|
|
class DeepSeekGPT(GPT):
|
|
def __init__(self):
|
|
from os import getenv
|
|
self.api_key = getenv("DEEP_SEEK_API_KEY")
|
|
self.base_url = getenv("DEEP_SEEK_API_BASE_URL")
|
|
self.model=getenv('DEEP_SEEK_MODEL')
|
|
print(self.model)
|
|
self.client = build_openai_client(self.api_key, self.base_url, key_label="DeepSeek 的 API Key")
|
|
self.screenshot = False
|
|
|
|
def _format_time(self, seconds: float) -> str:
|
|
return str(timedelta(seconds=int(seconds)))[2:] # e.g., 03:15
|
|
|
|
def _build_segment_text(self, segments: List[TranscriptSegment]) -> str:
|
|
return "\n".join(
|
|
f"{self._format_time(seg.start)} - {seg.text.strip()}"
|
|
for seg in segments
|
|
)
|
|
|
|
def ensure_segments_type(self, segments) -> List[TranscriptSegment]:
|
|
return [
|
|
TranscriptSegment(**seg) if isinstance(seg, dict) else seg
|
|
for seg in segments
|
|
]
|
|
|
|
def create_messages(self, segments: List[TranscriptSegment], title: str,tags:str):
|
|
content = BASE_PROMPT.format(
|
|
video_title=title,
|
|
segment_text=self._build_segment_text(segments),
|
|
tags=tags
|
|
)
|
|
if self.screenshot:
|
|
print(":需要截图")
|
|
content += SCREENSHOT
|
|
print(content)
|
|
return [{"role": "user", "content": content + AI_SUM}]
|
|
|
|
def summarize(self, source: GPTSource) -> str:
|
|
self.screenshot = source.screenshot
|
|
source.segment = self.ensure_segments_type(source.segment)
|
|
messages = self.create_messages(source.segment, source.title,source.tags)
|
|
response = self.client.chat.completions.create(
|
|
model=self.model,
|
|
messages=messages,
|
|
temperature=0.7
|
|
)
|
|
return response.choices[0].message.content.strip()
|
|
|
|
|