diff --git a/VideoAnalysis/Components/Pages/VideoTaskShow.razor.css b/VideoAnalysis/Components/Pages/VideoTaskShow.razor.css index 837542b..17c3cb8 100644 --- a/VideoAnalysis/Components/Pages/VideoTaskShow.razor.css +++ b/VideoAnalysis/Components/Pages/VideoTaskShow.razor.css @@ -49,7 +49,7 @@ video { display: flex; flex-direction: column; width: 400px; - height: 850px; + height: 750px; gap: 10px; overflow: hidden; overflow-y: scroll; diff --git a/VideoAnalysis/Program.cs b/VideoAnalysis/Program.cs index 2c6ae30..75f8d39 100644 --- a/VideoAnalysis/Program.cs +++ b/VideoAnalysis/Program.cs @@ -9,6 +9,7 @@ using VideoAnalysisCore.AICore.GPT.KIMI; using VideoAnalysisCore.AICore.GPT.ChatGPT; using Microsoft.Extensions.FileProviders; using VideoAnalysisCore.AICore.GPT.DeepSeek; +using Microsoft.Extensions.DependencyInjection; @@ -24,10 +25,16 @@ namespace Learn.VideoAnalysis // Add services to the container. builder.Services.AddRazorComponents() .AddInteractiveServerComponents(); - //.AddInteractiveWebAssemblyComponents(); + //.AddInteractiveWebAssemblyComponents(); builder.Services.AddHttpContextAccessor(); + builder.Services.AddLogging(loggingBuilder => + { + loggingBuilder.ClearProviders(); // 清除默认的日志提供程序 + loggingBuilder.AddConsole(); // 添加控制台日志提供程序 + loggingBuilder.SetMinimumLevel(LogLevel.Warning); // 设置最小日志级别为 Warning + }); builder.Services.AddControllers(); diff --git a/VideoAnalysis/appsettings.json b/VideoAnalysis/appsettings.json index 5e07b13..dc6ee59 100644 --- a/VideoAnalysis/appsettings.json +++ b/VideoAnalysis/appsettings.json @@ -1,7 +1,7 @@ { "Logging": { "LogLevel": { - "Default": "Information", + "Default": "Warning", "Microsoft.AspNetCore": "Warning" } }, @@ -43,7 +43,7 @@ "DB": { "ConnectionString": "AllowLoadLocalInfile=true;Server=192.168.2.9;User ID=root;Password=qwe123!@#;Port=3306;Database=learn.videoanalysis;CharSet=utf8mb4;pooling=true;SslMode=None", "SqlType": "MySql", - "UpdateTable": true + "UpdateTable": false }, "KnowsDB": { "ConnectionString": "Server=47.109.35.116;Database=ResourceBank;UID=live;Password=Woshiren^&*();MultipleActiveResultSets=true;Encrypt=True;TrustServerCertificate=True;", diff --git a/VideoAnalysisCore/AICore/GPT/DeepSeek/DeepSeekClient.cs b/VideoAnalysisCore/AICore/GPT/DeepSeek/DeepSeekClient.cs index 9cb2b7b..db4a1bb 100644 --- a/VideoAnalysisCore/AICore/GPT/DeepSeek/DeepSeekClient.cs +++ b/VideoAnalysisCore/AICore/GPT/DeepSeek/DeepSeekClient.cs @@ -140,9 +140,13 @@ namespace VideoAnalysisCore.AICore.GPT.DeepSeek public async Task<(Usage u, string res, string reasoning)?> ChatSSE(ChatRequest chatReq) { var requestBody = System.Text.Json.JsonSerializer.Serialize(chatReq); + PostJsonStream: var chatResp = PostJsonStream(string.Empty, requestBody); - if (!chatResp.IsSuccessStatusCode) - throw new Exception("GPT璇锋眰鐘舵佸紓甯=>"+ chatResp.StatusCode); + if (!chatResp.IsSuccessStatusCode) + { + Console.WriteLine(DateTime.Now + "=>璇锋眰GPT鏈嶅姟鍣ㄥ紓甯 " + chatResp?.StatusCode); + goto PostJsonStream; + } using var stream = chatResp.Content.ReadAsStream(); using var reader = new StreamReader(stream, Encoding.UTF8); string line; @@ -150,7 +154,8 @@ namespace VideoAnalysisCore.AICore.GPT.DeepSeek var messageBuilder1 = new StringBuilder(); var lastChat = new ChatResSSE(); var splitCount = "data:".Length; - var maxLoop = 60*100; + var maxLoop = 60*1000; + int threshold = 50; while (maxLoop>0) { line = reader.ReadLine(); @@ -187,6 +192,12 @@ namespace VideoAnalysisCore.AICore.GPT.DeepSeek messageBuilder.Append(str); if (!string.IsNullOrEmpty(strReasoning)) messageBuilder1.Append(strReasoning); + var steamCount = messageBuilder.Length + messageBuilder1.Length; + if (steamCount> threshold) + { + threshold += threshold; + Console.WriteLine(DateTime.Now + "=>鎺ユ敹鍒版祦 " + steamCount); + } } catch (Exception e) { diff --git a/VideoAnalysisCore/AICore/GPT/DeepSeek/DeepSeek_GPT.cs b/VideoAnalysisCore/AICore/GPT/DeepSeek/DeepSeek_GPT.cs index 9071b39..1d975d6 100644 --- a/VideoAnalysisCore/AICore/GPT/DeepSeek/DeepSeek_GPT.cs +++ b/VideoAnalysisCore/AICore/GPT/DeepSeek/DeepSeek_GPT.cs @@ -76,37 +76,61 @@ namespace VideoAnalysisCore.AICore.GPT.DeepSeek .OrderBy(s=>s.Id) .GroupBy(s=>s.Name) .ToDictionary(s => s.First().Name, s => s.First().Id); - var postMessages = - $"浣犵殑浠诲姟鏄垎鏋愯棰戝瓧骞曞唴瀹瑰苟鎻愬彇鍑轰腑鍥介珮鑰冭冭瘯璇曢鏂规硶鐐,鐒跺悗鏍规嵁姝ラ鍒嗘瀽鍑虹煡璇嗙墖娈" + - $"鎸変互涓嬫楠ゅ畬鎴:" + - $"1.璇嗗埆鏂规硶鐐:鎻愬彇瀛楀箷鍐呭涓笌{subject}鑰冭瘯灞炰簬{fileNameInfoRes.鎺堣绔犺妭}绔犺妭鐩稿叧鐨勬柟娉曠偣銆" + - $"2.鍏宠仈鍚堝苟鐭ヨ瘑鍐呭鐩镐技鐨勭煡璇嗙偣鏉ュ悎骞朵负鐭ヨ瘑鐗囨銆傚鏋滅煡璇嗙墖娈垫椂闀胯秴杩12鍒嗛挓鍒欒冭檻鎷嗗皝涓2涓洿鍔犵粏寰创鍒囩殑鐭ヨ瘑鐗囨" + - $"3.鍒嗛厤绌轰綑鏈娇鐢ㄧ殑鏃堕棿娈靛埌鍐呭鐩歌繎鐨勭煡璇嗙墖娈垫椂闂村尯闂存潵鑾峰彇鏇村姞璇︾粏鐨勪笂涓嬫枃,浣嗘槸璇烽伩鍏嶇煡璇嗙墖娈典箣闂存椂闂撮噸鍚堛" + - $"4.鍒嗘瀽鎬荤粨:鍩轰簬鎻愬彇鍑虹殑鐭ヨ瘑鐗囨鍐呭绉版潵鍖归厤鎴戞彁渚涚殑鐭ヨ瘑鐐,鏉ヤ綔涓虹墖娈电殑鐭ヨ瘑鐐(璇风‘淇濆尮閰嶇殑鐭ヨ瘑鐐规槸鎴戞彁渚涚殑,鍚﹁呯墖娈电煡璇嗙偣鍊间负绌哄瓧绗︿覆)" + - $"鎻愪緵鐨勬柟娉曠偣鍚嶇О({knows})銆 鏍煎紡 (鏂规硶鐐笽d|鏂规硶鐐瑰悕绉) 濡傛灉涓涓煡璇嗙墖娈靛嚭鐜板涓煡璇嗙偣閭d箞鐭ヨ瘑鐐笽d涓庣煡璇嗙偣鍚嶇О閮界敤閫楀彿','鍒嗗壊" + - $"杈撳叆锛氬寘鍚椂闂存埑鐨勮棰戝瓧骞曟枃鏈" + - $"浠ヤ笅鏄寘鍚椂闂寸殑瑙嗛瀛楀箷鏂囨湰銆" + - $"瀛楀箷鏍煎紡(璇磋瘽浜:寮濮嬬:缁撴潫绉:鍐呭|涓嬩竴娈靛瓧骞).瀛楀箷鍒楄〃 {captions.Captions}" + + VideoKnowRes[] questionRes; + while (true) + { + var postMessages = + $"浣犵殑浠诲姟鏄垎鏋愯棰戝瓧骞曞唴瀹瑰苟鎻愬彇鍑轰腑鍥介珮鑰冭冭瘯璇曢鏂规硶鐐,鐒跺悗鍒嗘瀽鍑<鐭ヨ瘑鍧>,鏉ュ府鍔╁鐢熷揩閫熶簡瑙h棰戝瓧骞曠殑鍐呭" + + $"閫氳繃闃呰骞剁悊瑙e瓧骞曞唴瀹.鐒跺悗璇嗗埆鍑簕subject}瀛︾涓睘浜巤fileNameInfoRes.鎺堣绔犺妭}绔犺妭鐩稿叧鐨勬柟娉曠偣浠ュ強瀵瑰簲鐨勬椂闂存銆" + + $"鍏宠仈鍚堝苟鐭ヨ瘑鍐呭鐩镐技鐨勭煡璇嗙偣鏉ュ悎骞朵负<鐭ヨ瘑鍧>銆(璇锋敞鎰忓鏋<鐭ヨ瘑鍧>鏃堕暱瓒呰繃600绉掑垯鑰冭檻鎷嗗皝涓轰袱涓洿鍔犺创鍒囩殑<鐭ヨ瘑鍧>.鎴栬<鐭ヨ瘑鍧>鏃堕暱灏忎簬30绉掑垯鑰冭檻鍚堝苟<鐭ヨ瘑鍧>鍒扮浉閭荤殑<鐭ヨ瘑鍧>)" + + $"鍒嗛厤绌轰綑鏈娇鐢ㄧ殑鏃堕棿娈靛埌鍐呭鐩歌繎鐨<鐭ヨ瘑鍧>鏃堕棿鍖洪棿鏉ヨ幏鍙栨洿鍔犺缁嗙殑涓婁笅鏂,浣嗘槸璇烽伩鍏<鐭ヨ瘑鍧>涔嬮棿鏃堕棿閲嶅悎銆" + + $"浠庢彁鍙栧嚭鐨<鐭ヨ瘑鍧>鍐呭绉版潵鍖归厤鎴戞彁渚涚殑鐭ヨ瘑鐐,鏉ヤ綔涓虹墖娈电殑鐭ヨ瘑鐐(璇风‘淇濆尮閰嶇殑鐭ヨ瘑鐐规槸鐢ㄦ埛鎻愪緵鐨,鍚﹀垯鐗囨鐭ヨ瘑鐐瑰间负绌哄瓧绗︿覆)銆" + + $"鎻愪緵鐨勬柟娉曠偣鍚嶇О({knows})銆 鏍煎紡 (鏂规硶鐐笽d|鏂规硶鐐瑰悕绉) 濡傛灉涓涓<鐭ヨ瘑鍧>鍑虹幇澶氫釜鐭ヨ瘑鐐归偅涔堢煡璇嗙偣Id涓庣煡璇嗙偣鍚嶇О閮界敤閫楀彿','鍒嗗壊銆" + + $"杩欐槸杈撳叆鐨勮棰戝瓧骞曞苟涓旀槸鍖呭惈鏃堕棿鎴崇殑瑙嗛瀛楀箷鐨勫浐瀹氭牸寮忔枃鏈" + + $"瀛楀箷鏍煎紡(璇磋瘽浜:寮濮嬬:缁撴潫绉:鍐呭|涓嬩竴娈靛瓧骞).浠ヤ笅鏄寘鍚椂闂寸殑瑙嗛瀛楀箷鏂囨湰銆傚瓧骞曞垪琛 {captions.Captions}銆" + + $"鏈鍚庤妫鏌ユ煇浜<鐭ヨ瘑鍧>涔嬮棿鐨勮繃娓℃槸鍚﹁嚜鐒躲傚缓璁寜鏃堕棿椤哄簭浼樺寲鍒嗘瀵嗗害锛屽寮虹煡璇嗙偣琛旀帴銆" + $"杈撳嚭鏍煎紡({resFormat})"; - Console.WriteLine("=>寮濮嬪垎鏋愯棰戝唴瀹"); + Console.WriteLine(DateTime.Now + "=>寮濮嬪垎鏋愯棰戝唴瀹"); - var questionRes = await ChatAsync(task, postMessages, null); + questionRes = await ChatAsync(task, postMessages, null); - if (questionRes.Length <= 3) - throw new Exception("瑙嗛鍒嗘鏁伴噺杩囦綆 =>" + questionRes.Length); + if (questionRes.Length <= 3) + throw new Exception("瑙嗛鍒嗘鏁伴噺杩囦綆 =>" + questionRes.Length); + questionRes = questionRes.OrderBy(s => s.StartTime).ToArray(); + for (int i = 0; i < questionRes.Length; i++) + { + var item = questionRes[i]; + if (i == questionRes.Length - 1) + item.EndTime = maxVideoTime; + else + item.EndTime = (int)(questionRes[i + 1]?.StartTime ?? 0) - 1; + } + var thems = string.Join(',', questionRes.Select(s => s.StartTime + "->" + s.Theme)); - for (int i = 0; i < questionRes.Length; i++) - { - var item = questionRes[i]; - if (i == questionRes.Length - 1) - item.EndTime = maxVideoTime; + var checkResFormat = """{"Score":鎵撳垎(number),"Evaluation":璇勪环(string)}"""; + var checkMessage = "鎴戜负瑙嗛鐨勮瑙e唴瀹瑰仛浜嗕竴浜涘垎娈,浣犺兘甯垜妫鏌ヤ笅杩欎簺鍒嗘鐨勫垎閰嶅悎鐞嗗悧?璇风粰鍑轰綘鐨勬墦鍒(0-100,60鍒嗗強鏍)浠ュ強璇勪环" + + $"杩欐槸鎴戠殑鍒嗘 {thems}." + + $"鍚庣画鐨勫唴瀹规槸鍖呭惈鏃堕棿鎴崇殑瑙嗛瀛楀箷鐨勫浐瀹氭牸寮忔枃鏈" + + $"瀛楀箷鏍煎紡(璇磋瘽浜:寮濮嬬:缁撴潫绉:鍐呭|涓嬩竴娈靛瓧骞).浠ヤ笅鏄寘鍚椂闂寸殑瑙嗛瀛楀箷鏂囨湰銆傚瓧骞曞垪琛 {captions.Captions}銆" + + $"杈撳嚭鏍煎紡涓簀son({checkResFormat})"; + + Console.WriteLine(DateTime.Now + "=>寮濮嬫鏌ヨ棰戝垎娈电粨鏋"); + var checkRes = await ChatAsync (task, checkMessage, null); + if (checkRes != null && checkRes.Score >= 80) + break; else - item.EndTime = (int)(questionRes[i + 1]?.StartTime ?? 0) - 1; - } + { + Console.WriteLine(DateTime.Now + "=>寰楀垎杩囦綆 " + checkRes?.Score ); + Console.WriteLine( checkRes.Evaluation); + Console.WriteLine( ); + } + } await videoKonwPointDB.DeleteAsync(s => s.VideoTaskId == taskId); - var data = questionRes.SelectMany( + var data = questionRes + .Where(s=>!string.IsNullOrEmpty(s.KnowPoint)) + .SelectMany( s => { var ks = s.KnowPoint.Split(","); @@ -152,7 +176,6 @@ namespace VideoAnalysisCore.AICore.GPT.DeepSeek max_tokens = maxTokens, temperature = 0.2f, messages = messageArr - }; RedisExpand.SetTaskGPTReqCached(task, chatRep); diff --git a/VideoAnalysisCore/AICore/GPT/Dto/QuestionRes.cs b/VideoAnalysisCore/AICore/GPT/Dto/QuestionRes.cs index 4eef506..0e1992f 100644 --- a/VideoAnalysisCore/AICore/GPT/Dto/QuestionRes.cs +++ b/VideoAnalysisCore/AICore/GPT/Dto/QuestionRes.cs @@ -127,10 +127,23 @@ namespace VideoAnalysisCore.AICore.GPT.Dto public string? ImprovedMethods { get; set; } } - /// - /// 璇惧爞AI璇勪环缁撴灉 - /// - public class AssessmentDto + + public class CheckMessageDto + { + /// + /// 鎵撳垎 + /// + public decimal Score { get; set; } + /// + /// 璇勫垎 + /// + public string Evaluation { get; set; } + } + + /// + /// 璇惧爞AI璇勪环缁撴灉 + /// + public class AssessmentDto { /// /// 浼樼鐨勮瘎浠 diff --git a/VideoAnalysisCore/AICore/SherpaOnnx/SenseVoice.cs b/VideoAnalysisCore/AICore/SherpaOnnx/SenseVoice.cs index 130a328..ae6a944 100644 --- a/VideoAnalysisCore/AICore/SherpaOnnx/SenseVoice.cs +++ b/VideoAnalysisCore/AICore/SherpaOnnx/SenseVoice.cs @@ -137,7 +137,7 @@ namespace VideoAnalysisCore.AICore.SherpaOnnx { res.Add(new() { - Text = ExpandFunction.HandleFormula(stream.Result.Text), + Text = stream.Result.Text, Start = (float)Math.Round(startTime, 2, MidpointRounding.AwayFromZero), End = (float)Math.Round(startTime + duration, 2, MidpointRounding.AwayFromZero), }); diff --git a/VideoAnalysisCore/Common/SqlSugarExpand.cs b/VideoAnalysisCore/Common/SqlSugarExpand.cs index a1493f3..db1d159 100644 --- a/VideoAnalysisCore/Common/SqlSugarExpand.cs +++ b/VideoAnalysisCore/Common/SqlSugarExpand.cs @@ -139,7 +139,7 @@ namespace VideoAnalysisCore.Common if (!AppCommon.Config.DB.UpdateTable) { Console.WriteLine($"銆1銆戝垵濮嬪寲涓诲簱琛 璺宠繃...."); - ShowSQL = true; + //ShowSQL = true; return; } Console.WriteLine($"銆1銆戝垵濮嬪寲涓诲簱琛 鎵ц涓....");