From 7188f8ab71b71e51f8002b30dc22a45eff9b01c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E8=82=A5=E7=BE=8A?= <1048382248@qq.com> Date: Fri, 6 Mar 2026 18:00:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E5=85=A5=20bset=E7=9A=84Deepseek?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VideoAnalysisCore/AICore/GPT/BserGPT.cs | 1 + VideoAnalysisCore/AICore/GPT/ChatGPTType.cs | 2 + .../GPT/DeepSeek/BSET_DeepSeekGPTClient.cs | 64 +++++++++++++++++ .../AICore/GPT/GTP_Analysis_1.cs | 8 ++- .../AICore/SherpaOnnx/SherpaVad.cs | 2 +- .../Common/Expand/TidySlideExpand.cs | 72 +++++++++++++++++-- VideoAnalysisCore/Common/RedisExpand.cs | 2 +- 7 files changed, 143 insertions(+), 8 deletions(-) create mode 100644 VideoAnalysisCore/AICore/GPT/DeepSeek/BSET_DeepSeekGPTClient.cs diff --git a/VideoAnalysisCore/AICore/GPT/BserGPT.cs b/VideoAnalysisCore/AICore/GPT/BserGPT.cs index 3da3c16..890d984 100644 --- a/VideoAnalysisCore/AICore/GPT/BserGPT.cs +++ b/VideoAnalysisCore/AICore/GPT/BserGPT.cs @@ -185,6 +185,7 @@ namespace VideoAnalysisCore.AICore.GPT public static void AddGPTService(this IServiceCollection services) { services.AddSingleton(); + services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); diff --git a/VideoAnalysisCore/AICore/GPT/ChatGPTType.cs b/VideoAnalysisCore/AICore/GPT/ChatGPTType.cs index e4eb4f6..4e34c31 100644 --- a/VideoAnalysisCore/AICore/GPT/ChatGPTType.cs +++ b/VideoAnalysisCore/AICore/GPT/ChatGPTType.cs @@ -13,6 +13,8 @@ namespace VideoAnalysisCore.AICore.GPT public const string Deepseek_Reasoner = "deepseek-reasoner"; public const string Deepseek_Chat = "deepseek-chat"; + public const string Deepseek_v32 = "deepseek-v3.2"; + public const string Deepseek_v32_thinking = "deepseek-v3.2-thinking"; //渠道限制没有并发 //public const string Gemini_3_Chat_thinking = "gemini-3-pro-preview-thinking"; diff --git a/VideoAnalysisCore/AICore/GPT/DeepSeek/BSET_DeepSeekGPTClient.cs b/VideoAnalysisCore/AICore/GPT/DeepSeek/BSET_DeepSeekGPTClient.cs new file mode 100644 index 0000000..fa8f0a2 --- /dev/null +++ b/VideoAnalysisCore/AICore/GPT/DeepSeek/BSET_DeepSeekGPTClient.cs @@ -0,0 +1,64 @@ +using VideoAnalysisCore.Common; +using System.Net.Http.Headers; +using System.Text; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json.Linq; +using System.Net.Http; +using Newtonsoft.Json; +using System.Net.Http.Json; +using System.Net; +using System.Text.Json; + + +namespace VideoAnalysisCore.AICore.GPT.DeepSeek +{ + + public class BSET_DeepSeekGPTClient : GPTClient + { + + public override GptConfig Config { get; set; } = AppCommon.Config.ChatGpt.ChatGpt; + private readonly IHttpClientFactory _httpClientFactory; + private readonly RedisManager redisManager; + + public BSET_DeepSeekGPTClient(IHttpClientFactory httpClientFactory, RedisManager redisManager, VideoSliceWorkflowManager workflowManager) + : base(httpClientFactory, redisManager, workflowManager) + { + _httpClientFactory = httpClientFactory; + this.redisManager = redisManager; + } + + + /// + /// 请求AI + /// + /// 返回JSON类型 + /// 任务id + /// 提示词 + /// 任务类型 + /// GPT版本 + /// 最大token 不设置默认最大值 16000/8000 + /// + /// + public override async Task ChatAsync(string task, string postMessages, string title, string model = ChatGPTType.Deepseek_v32, int max_tokens = 8000) + { + Message[] messageArr = [ + new Message(postMessages,"user"), + ]; + messageArr = messageArr.Where(s => s != null).ToArray(); + if (max_tokens > 8000 && (model is null || model == ChatGPTType.Deepseek_v32)) + max_tokens = 8000; + var chatReq = new ChatRequest + { + taskId = task, + title = title, + model = model ?? ChatGPTType.Deepseek_v32_thinking, + max_tokens = model == ChatGPTType.Deepseek_v32_thinking ? 32000 : max_tokens, + stream = true, + messages = messageArr + }; + chatReq.modalities = null; + return await ChatAsync(chatReq); + } + + } +} \ No newline at end of file diff --git a/VideoAnalysisCore/AICore/GPT/GTP_Analysis_1.cs b/VideoAnalysisCore/AICore/GPT/GTP_Analysis_1.cs index ec8eced..f7a35b4 100644 --- a/VideoAnalysisCore/AICore/GPT/GTP_Analysis_1.cs +++ b/VideoAnalysisCore/AICore/GPT/GTP_Analysis_1.cs @@ -1,4 +1,4 @@ -using VideoAnalysisCore.Common; +using VideoAnalysisCore.Common; using System.Text.Json; using VideoAnalysisCore.Model; using System.Text; @@ -37,6 +37,7 @@ namespace VideoAnalysisCore.AICore.GPT { private readonly GeminiGPTClient geminiClient; private readonly DeepSeekGPTClient deepSeekClient; + private readonly BSET_DeepSeekGPTClient bset_deepSeekClient; private readonly BestAIClient chatGPTClient; private readonly Repository criteriaDB; private readonly RedisManager redisManager; @@ -56,7 +57,7 @@ namespace VideoAnalysisCore.AICore.GPT /// public GTP_Analysis_1(DeepSeekGPTClient moonshotClient, Repository criteria, Repository videoTaskDB, Repository knowledgeInfoDB, Repository videoKonwPointDB, SimpLetexClient simpLetexClient, - Repository videoQuestionDB, OssClient ossClient, Repository videoQuestionKonwDB, RedisManager redisManager, VideoSliceWorkflowManager workflowManager, BestAIClient chatGPTClient, GeminiGPTClient geminiClient, Repository videoTaskStageDB) + Repository videoQuestionDB, OssClient ossClient, Repository videoQuestionKonwDB, RedisManager redisManager, VideoSliceWorkflowManager workflowManager, BestAIClient chatGPTClient, GeminiGPTClient geminiClient, Repository videoTaskStageDB, BSET_DeepSeekGPTClient bset_deepSeekClient) { deepSeekClient = moonshotClient; criteriaDB = criteria; @@ -72,6 +73,7 @@ namespace VideoAnalysisCore.AICore.GPT this.chatGPTClient = chatGPTClient; this.geminiClient = geminiClient; this.videoTaskStageDB = videoTaskStageDB; + this.bset_deepSeekClient = bset_deepSeekClient; } /// /// 获取分段内容对应的章节知识点 @@ -303,6 +305,8 @@ namespace VideoAnalysisCore.AICore.GPT Func>>[] chatClentArr = [ + async (m)=>await bset_deepSeekClient + .ChatAsync>(taskInfo.Id.ToString(), m, "优化字幕",ChatGPTType.Deepseek_v32,8_000), async (m)=>await deepSeekClient .ChatAsync>(taskInfo.Id.ToString(), m, "优化字幕",ChatGPTType.Deepseek_Chat,8_000), async (m)=>await chatGPTClient diff --git a/VideoAnalysisCore/AICore/SherpaOnnx/SherpaVad.cs b/VideoAnalysisCore/AICore/SherpaOnnx/SherpaVad.cs index 20c436a..378054a 100644 --- a/VideoAnalysisCore/AICore/SherpaOnnx/SherpaVad.cs +++ b/VideoAnalysisCore/AICore/SherpaOnnx/SherpaVad.cs @@ -1,4 +1,4 @@ -using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using SherpaOnnx; using SqlSugar; diff --git a/VideoAnalysisCore/Common/Expand/TidySlideExpand.cs b/VideoAnalysisCore/Common/Expand/TidySlideExpand.cs index e288326..8c49179 100644 --- a/VideoAnalysisCore/Common/Expand/TidySlideExpand.cs +++ b/VideoAnalysisCore/Common/Expand/TidySlideExpand.cs @@ -131,8 +131,31 @@ namespace VideoAnalysisCore.Common.Expand var fileName = Path.GetFileName(tsFile); var tsObjectKey = ossPrefix + fileName; - using var fs = File.OpenRead(tsFile); - ossClient.PutObject(bucket, tsObjectKey, fs); + var tsRetryCount = 0; + var tsMaxRetries = 10; + while (true) + { + try + { + using var fs = File.OpenRead(tsFile); + ossClient.PutObject(bucket, tsObjectKey, fs); + break; // Upload successful, break retry loop + } + catch (Exception ex) + { + tsRetryCount++; + if (tsRetryCount >= tsMaxRetries) + { + await _workflowManager.AddTaskLog(task, $"上传 TS 切片 {fileName} 失败,已重试 {tsMaxRetries} 次: {ex.Message}"); + throw; // Re-throw exception to stop the process + } + else + { + await _workflowManager.AddTaskLog(task, $"上传 TS 切片 {fileName} 失败 (第 {tsRetryCount} 次重试): {ex.Message},1秒后重试..."); + await Task.Delay(1000); + } + } + } // 更新上传进度 if (i % 5 == 0) // 每5个文件更新一次进度 @@ -145,9 +168,33 @@ namespace VideoAnalysisCore.Common.Expand // B. 上传 m3u8 索引文件 // 必须使用 VOD 指定的 objectName await _workflowManager.AddTaskLog(task, "开始上传 m3u8 索引文件..."); - using (var fs = File.OpenRead(m3u8Path)) + + var m3u8RetryCount = 0; + var m3u8MaxRetries = 3; + while (true) { - ossClient.PutObject(bucket, objectName, fs); + try + { + using (var fs = File.OpenRead(m3u8Path)) + { + ossClient.PutObject(bucket, objectName, fs); + } + break; // Upload successful + } + catch (Exception ex) + { + m3u8RetryCount++; + if (m3u8RetryCount >= m3u8MaxRetries) + { + await _workflowManager.AddTaskLog(task, $"上传 m3u8 文件失败,已重试 {m3u8MaxRetries} 次: {ex.Message}"); + throw; + } + else + { + await _workflowManager.AddTaskLog(task, $"上传 m3u8 文件失败 (第 {m3u8RetryCount} 次重试): {ex.Message},1秒后重试..."); + await Task.Delay(1000); + } + } } await _workflowManager.AddTaskLog(task, "上传成功"); @@ -167,6 +214,23 @@ namespace VideoAnalysisCore.Common.Expand catch (Exception ex) { await _workflowManager.AddTaskLog(task, $"上传 VOD OSS 异常: {ex.Message}"); + + // 如果已获取 VideoId 但上传失败,则删除 VOD 记录 + if (!string.IsNullOrEmpty(videoId)) + { + try + { + await _workflowManager.AddTaskLog(task, $"正在回滚删除 VOD 视频记录 (VideoId: {videoId})..."); + var deleteRequest = new DeleteVideoRequest { VideoIds = videoId }; + await _vodClient.DeleteVideoAsync(deleteRequest); + await _workflowManager.AddTaskLog(task, "VOD 视频记录删除成功"); + } + catch (Exception deleteEx) + { + await _workflowManager.AddTaskLog(task, $"回滚删除 VOD 视频记录失败: {deleteEx.Message}"); + } + } + throw; } } diff --git a/VideoAnalysisCore/Common/RedisExpand.cs b/VideoAnalysisCore/Common/RedisExpand.cs index 7897be7..bc90fdc 100644 --- a/VideoAnalysisCore/Common/RedisExpand.cs +++ b/VideoAnalysisCore/Common/RedisExpand.cs @@ -1,4 +1,4 @@ -using FreeRedis; +using FreeRedis; using FreeRedis.Internal; using Microsoft.Extensions.DependencyInjection; using Microsoft.IdentityModel.Tokens;