From 935c6a9eb167789e5fb7b6263a1a9f71b00a7ce7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E8=82=A5=E7=BE=8A?= <1048382248@qq.com> Date: Tue, 26 Nov 2024 11:47:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E5=90=8E=E9=87=8D=E8=AF=95=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Pages/VideoTaskPage.razor | 4 +- VideoAnalysis/appsettings.Production.json | 2 +- .../AICore/ChatGPT/KIMI/MoonshotClient.cs | 20 +++++++++- .../AICore/FFMPGE/FFMPGEHandle.cs | 4 +- VideoAnalysisCore/Common/RedisExpand.cs | 38 ++++++++++--------- 5 files changed, 44 insertions(+), 24 deletions(-) diff --git a/VideoAnalysis/Components/Pages/VideoTaskPage.razor b/VideoAnalysis/Components/Pages/VideoTaskPage.razor index 6cb4c50..fc4f140 100644 --- a/VideoAnalysis/Components/Pages/VideoTaskPage.razor +++ b/VideoAnalysis/Components/Pages/VideoTaskPage.razor @@ -21,9 +21,9 @@ - + - + diff --git a/VideoAnalysis/appsettings.Production.json b/VideoAnalysis/appsettings.Production.json index 216e7d8..afd83dc 100644 --- a/VideoAnalysis/appsettings.Production.json +++ b/VideoAnalysis/appsettings.Production.json @@ -15,7 +15,7 @@ "DB": { "ConnectionString": "AllowLoadLocalInfile=true;Server=10.255.255.3;Port=3306;Database=learn.videoanalysis;User ID=marking;Password=qwe123!@#;CharSet=utf8mb4;pooling=true;SslMode=None", "SqlType": "MySql", - "UpdateTable": true + "UpdateTable": false } } } diff --git a/VideoAnalysisCore/AICore/ChatGPT/KIMI/MoonshotClient.cs b/VideoAnalysisCore/AICore/ChatGPT/KIMI/MoonshotClient.cs index 6cceda1..a515e44 100644 --- a/VideoAnalysisCore/AICore/ChatGPT/KIMI/MoonshotClient.cs +++ b/VideoAnalysisCore/AICore/ChatGPT/KIMI/MoonshotClient.cs @@ -7,6 +7,7 @@ using System.Net.Http; using Newtonsoft.Json; using System.Net.Http.Json; using AntDesign; +using OneOf.Types; /// /// https://platform.moonshot.cn/docs/api-reference @@ -185,8 +186,23 @@ namespace VideoAnalysisCore.AICore.ChatGPT.KIMI var client = _httpClientFactory.CreateClient(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", ApiKey); var request = ToHttpRequest(path); - request.Content = new StringContent(json, Encoding.UTF8, "application/json"); - return await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead); + var maxRestart = 4; + var errorMSG = new Exception[maxRestart]; + for (int i = 0; i < maxRestart; i++) + { + try + { + request.Content = new StringContent(json, Encoding.UTF8, "application/json"); + return await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead); + } + catch (Exception e) + { + errorMSG[i] = e; + } + Thread.Sleep(1000); + } + string error = string.Join('\r', errorMSG.Select(s => "\r\n"+ s.Message + "\r\n" + s.StackTrace + "\r\n >>>>>>>>")); + throw new Exception("重试后仍旧失败!\r\n" + error); } private HttpRequestMessage ToHttpRequest(string path) diff --git a/VideoAnalysisCore/AICore/FFMPGE/FFMPGEHandle.cs b/VideoAnalysisCore/AICore/FFMPGE/FFMPGEHandle.cs index 8e36eb3..987d5e9 100644 --- a/VideoAnalysisCore/AICore/FFMPGE/FFMPGEHandle.cs +++ b/VideoAnalysisCore/AICore/FFMPGE/FFMPGEHandle.cs @@ -36,8 +36,8 @@ namespace VideoAnalysisCore.AICore.FFMPGE var outputFile = new OutputFile(Path.Combine(task.LocalPath(), Path.GetFileNameWithoutExtension(filePath) + ".wav")); var ffmpeg = new Engine(FFmpegPath); - ffmpeg.Progress += OnProgress; - ffmpeg.Data += OnData; + //ffmpeg.Progress += OnProgress; + //ffmpeg.Data += OnData; ffmpeg.Complete += OnComplete; ffmpeg.Error += (sender, e) => { diff --git a/VideoAnalysisCore/Common/RedisExpand.cs b/VideoAnalysisCore/Common/RedisExpand.cs index 92485d9..fe9b1d7 100644 --- a/VideoAnalysisCore/Common/RedisExpand.cs +++ b/VideoAnalysisCore/Common/RedisExpand.cs @@ -100,10 +100,10 @@ namespace VideoAnalysisCore.Common } /// - /// 获取任务进度 + /// 缓存GPT任务缓存 /// /// - public static void SetTaskGPTCached(object taskId, object data) + public static void SetTaskGPTCached(object taskId, object? data) { Redis.Set(RedisExpandKey.TaskGPT(taskId), data, 3600); } @@ -281,24 +281,28 @@ namespace VideoAnalysisCore.Common { if (taskId is null) return; var tID = long.Parse(taskId); - Console.WriteLine(DateTime.Now.ToString("HH:mm:ss") + "-> " + key + " " + taskId); if (action is not null) { - try + for (int i = 0; i < 3; i++) { - Redis.HMSet(RedisExpandKey.Task(taskId), "LastEnum", key); - Redis.HMSet(RedisExpandKey.Task(taskId), "Progress", 0); - await DbScoped.SugarScope.Updateable() - .SetColumns(it => it.LastEnum == key) - .Where(it => it.Id == tID) - .ExecuteCommandAsync(); - - await action(taskId); - } - catch (Exception ex) - { - await SetTaskErrorMessage(tID, ex) - .ConfigureAwait(false);//不切回上下文 + Console.WriteLine(DateTime.Now.ToString("HH:mm:ss") + "-> 开始执行 " + key + " " + taskId); + try + { + Redis.HMSet(RedisExpandKey.Task(taskId), "LastEnum", key); + Redis.HMSet(RedisExpandKey.Task(taskId), "Progress", 0); + await DbScoped.SugarScope.Updateable() + .SetColumns(it => it.LastEnum == key) + .Where(it => it.Id == tID) + .ExecuteCommandAsync(); + await action(taskId); + return; + } + catch (Exception ex) + { + Thread.Sleep(1000); + Console.WriteLine(DateTime.Now.ToString("HH:mm:ss") + "-> 稍后后重试." + key + " " + taskId ); + await SetTaskErrorMessage(tID, ex); + } } } else