From 43599fea1ddd218976f31bc68cf92873c7bfd724 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E8=82=A5=E7=BE=8A?= <1048382248@qq.com> Date: Thu, 26 Feb 2026 17:41:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20=E8=AE=BE=E5=A4=87id?= =?UTF-8?q?=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VideoAnalysis/Expand/CoravelExpand.cs | 4 ++-- VideoAnalysisCore/AICore/GPT/GPTClient.cs | 20 +++++++++++++++----- VideoAnalysisCore/Common/RedisExpand.cs | 3 ++- VideoAnalysisCore/Model/TaskLog.cs | 5 +++++ 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/VideoAnalysis/Expand/CoravelExpand.cs b/VideoAnalysis/Expand/CoravelExpand.cs index 6dbee8a..b82db7a 100644 --- a/VideoAnalysis/Expand/CoravelExpand.cs +++ b/VideoAnalysis/Expand/CoravelExpand.cs @@ -29,10 +29,10 @@ namespace Learn.VideoAnalysis.Expand provider.ApplicationServices.UseScheduler(scheduler => { //任务缓存清理 - // scheduler.Schedule().HourlyAt(10); + scheduler.Schedule().HourlyAt(10); //强制清理所有缓存内容 //scheduler.Schedule().Hourly(); - scheduler.Schedule().EverySeconds(40); + //scheduler.Schedule().EverySeconds(40); }); } } diff --git a/VideoAnalysisCore/AICore/GPT/GPTClient.cs b/VideoAnalysisCore/AICore/GPT/GPTClient.cs index f176707..102ee8e 100644 --- a/VideoAnalysisCore/AICore/GPT/GPTClient.cs +++ b/VideoAnalysisCore/AICore/GPT/GPTClient.cs @@ -80,9 +80,9 @@ namespace VideoAnalysisCore.AICore.GPT } goto PostJsonStream; } - using var stream = chatResp.Content.ReadAsStream(); + using var stream = await chatResp.Content.ReadAsStreamAsync(); using var reader = new StreamReader(stream, Encoding.UTF8); - string line; + string? line; var messageBuilder = new StringBuilder(); var messageBuilder1 = new StringBuilder(); var lastChat = new ChatResSSE(); @@ -94,13 +94,23 @@ namespace VideoAnalysisCore.AICore.GPT //最长分析分析时间1.5小时 或者重试读取 1w次 while (maxLoop > 0 && DateTime.Now < endTime) { - line = reader.ReadLine(); - if (line is null || string.IsNullOrEmpty(line) || line.StartsWith(": keep-alive")) + try { - Thread.Sleep(50); + using var cts = new CancellationTokenSource(TimeSpan.FromMinutes(3)); + line = await reader.ReadLineAsync(cts.Token); + } + catch (OperationCanceledException) + { + await redisManager.AddTaskLog(chatReq.taskId, "==>流式响应超时(3分钟),尝试重新读取..."); maxLoop--; continue; } + if (line is null || string.IsNullOrWhiteSpace(line) || line.StartsWith(": keep-alive")) + { + await Task.Delay(50); + maxLoop--; + continue; + } else if (line.EndsWith("[DONE]")) { // 表示一条消息结束 diff --git a/VideoAnalysisCore/Common/RedisExpand.cs b/VideoAnalysisCore/Common/RedisExpand.cs index 86ace77..165be0d 100644 --- a/VideoAnalysisCore/Common/RedisExpand.cs +++ b/VideoAnalysisCore/Common/RedisExpand.cs @@ -236,7 +236,8 @@ namespace VideoAnalysisCore.Common { VideoTaskId = long.Parse(taskId.ToString()), CreateTime = DateTime.Now, - Message = msg + Message = msg, + DeviceId = AppCommon.Config.ID }); var count = 50; lock (RedisExpandKey.TaskLog) diff --git a/VideoAnalysisCore/Model/TaskLog.cs b/VideoAnalysisCore/Model/TaskLog.cs index ca57001..9ee6e79 100644 --- a/VideoAnalysisCore/Model/TaskLog.cs +++ b/VideoAnalysisCore/Model/TaskLog.cs @@ -35,5 +35,10 @@ namespace VideoAnalysisCore.Model /// [SugarColumn(ColumnDataType ="text",IsNullable = true)] public string? Message { get; set; } + /// + /// 设备id + /// + [SugarColumn(IsNullable = true)] + public int? DeviceId { get; set; } } }