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; } } }