优化 部署线上流程

优化 ds提示词
This commit is contained in:
小肥羊 2025-02-25 18:26:47 +08:00
parent 8ee1db05ed
commit c12c8ebfcd
7 changed files with 37 additions and 30 deletions

View File

@ -6,11 +6,11 @@
"LinuxServerList": [ "LinuxServerList": [
{ {
"UserName": "hy", "UserName": "hy",
"Pwd": "E9D1AC136FDD59740A9595ABD0EB953A", "Pwd": "9718CB3C9A0760CA326767D677ADEC1C",
"Host": "192.168.2.21:10107", "Host": "192.168.2.21:10107",
"NickName": "", "NickName": "",
"IIsFireUrl": null, "IIsFireUrl": null,
"DockerFireUrl": "https://videoanalysis.w.23544.com:8843/", "DockerFireUrl": "",
"WindowsServiceFireUrl": null, "WindowsServiceFireUrl": null,
"LinuxServiceFireUrl": null "LinuxServiceFireUrl": null
} }
@ -74,8 +74,8 @@
"AspNetCoreEnv": "", "AspNetCoreEnv": "",
"LastEnvName": "10楼刀片机", "LastEnvName": "10楼刀片机",
"RemoveDaysFromPublished": "10", "RemoveDaysFromPublished": "10",
"WorkDir": "", "WorkDir": "/home/hy/",
"Volume": "/home/hy/VideoAnalysis/AICore:/app/AICore/_Static;/home/hy//VideoAnalysis/TaskCachedFile:/app/TaskCachedFile", "Volume": "/home/hy/VideoAnalysis/AICore:/app/AICore/_Static;/home/hy/VideoAnalysis/TaskCachedFile:/app/TaskCachedFile",
"Other": "", "Other": "",
"EnvPairList": [ "EnvPairList": [
{ {
@ -84,7 +84,7 @@
"LinuxEnvParam": null, "LinuxEnvParam": null,
"DockerPort": "9040", "DockerPort": "9040",
"DockerEnvName": "", "DockerEnvName": "",
"DockerVolume": "/home/hy/VideoAnalysis/AICore:/app/AICore/_Static;/home/hy//VideoAnalysis/TaskCachedFile:/app/TaskCachedFile", "DockerVolume": "/home/hy/VideoAnalysis/AICore:/app/AICore/_Static;/home/hy/VideoAnalysis/TaskCachedFile:/app/TaskCachedFile",
"DockerOther": "" "DockerOther": ""
} }
] ]

View File

@ -3,17 +3,17 @@
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app
EXPOSE 9040
COPY . .
#设置时间为中国上海 环境为开发环境
ENV TZ=Asia/Shanghai
# 更新 apt 源 # 更新 apt 源
COPY sources.list /etc/apt/sources.list COPY sources.list /etc/apt/sources.list
RUN apt-get update RUN apt-get update
RUN apt-get install -y ffmpeg RUN apt-get install -y ffmpeg
WORKDIR /app
EXPOSE 9040
COPY . .
#设置时间为中国上海 环境为开发环境
ENV TZ=Asia/Shanghai
ENV ASPNETCORE_URLS=http://+:9040 ENV ASPNETCORE_URLS=http://+:9040

View File

@ -20,6 +20,8 @@ namespace VideoAnalysisCore.AICore.FFMPGE
public static string FFmpegPath = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) public static string FFmpegPath = RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
? $"/usr/bin/ffmpeg" ? $"/usr/bin/ffmpeg"
: Path.Combine(AppCommon.AIModelFile, "ffmpeg.exe"); : Path.Combine(AppCommon.AIModelFile, "ffmpeg.exe");
public static string Task = string.Empty;
/// <summary> /// <summary>
/// 音频转码为 wav_16k /// 音频转码为 wav_16k
/// </summary> /// </summary>
@ -27,6 +29,7 @@ namespace VideoAnalysisCore.AICore.FFMPGE
/// <returns></returns> /// <returns></returns>
public static async Task Audio2WAV16KAsync(string task) public static async Task Audio2WAV16KAsync(string task)
{ {
Task = task;
var filePath = RedisExpand.Redis.HGet(RedisExpandKey.Task(task), "LocalMediaPath"); var filePath = RedisExpand.Redis.HGet(RedisExpandKey.Task(task), "LocalMediaPath");
if (string.IsNullOrEmpty(filePath)) if (string.IsNullOrEmpty(filePath))
throw new Exception($"任务id[{task}] 无效"); throw new Exception($"任务id[{task}] 无效");
@ -41,7 +44,9 @@ namespace VideoAnalysisCore.AICore.FFMPGE
ffmpeg.Complete += OnComplete; ffmpeg.Complete += OnComplete;
ffmpeg.Error += (sender, e) => ffmpeg.Error += (sender, e) =>
{ {
throw new Exception($"[{e.Input.Name} => {e.Output.Name}]: 错误: {e.Exception.Message}"); var ee = new Exception($"音频转码出现异常 \r\n[{e.Input.Name} => {e.Output.Name}]: 错误: {e.Exception.Message}");
RedisExpand.SetTaskErrorMessage(long.Parse(task), ee);
throw ee;
}; };
var conversionOptions = new ConversionOptions var conversionOptions = new ConversionOptions
@ -53,8 +58,6 @@ namespace VideoAnalysisCore.AICore.FFMPGE
}; };
var res = await ffmpeg.ConvertAsync(inputFile, outputFile, conversionOptions); var res = await ffmpeg.ConvertAsync(inputFile, outputFile, conversionOptions);
//加入下一队列
RedisExpand.InsertChannel(Enum.RedisChannelEnum.ParsingCaptions, task);
} }
private static void OnProgress(object sender, ConversionProgressEventArgs e) private static void OnProgress(object sender, ConversionProgressEventArgs e)
@ -76,6 +79,8 @@ namespace VideoAnalysisCore.AICore.FFMPGE
private static void OnComplete(object sender, ConversionCompleteEventArgs e) private static void OnComplete(object sender, ConversionCompleteEventArgs e)
{ {
Console.WriteLine("转换完成=>" + e.Output.Name); Console.WriteLine("转换完成=>" + e.Output.Name);
//加入下一队列
RedisExpand.InsertChannel(Enum.RedisChannelEnum.ParsingCaptions, Task);
} }
} }
} }

View File

@ -63,7 +63,7 @@ namespace VideoAnalysisCore.AICore.GPT.DeepSeek
} }
//throw new Exception($" GPT模型返回异常 返回参数: " + //throw new Exception($" GPT模型返回异常 返回参数: " +
// $" {System.Text.Json.JsonSerializer.Serialize(res1)}"); // $" {System.Text.Json.JsonSerializer.Serialize(res1)}");
Console.WriteLine(DateTime.Now + $"=>GPT请求头获取成功 Code = {chatResp.StatusCode} Res={res1}");
var res = await chatResp.Content.ReadFromJsonAsync<ChatRes>(); var res = await chatResp.Content.ReadFromJsonAsync<ChatRes>();
if (res is null || res.error != null) if (res is null || res.error != null)
throw new Exception($" GPT模型返回异常 返回参数: " + throw new Exception($" GPT模型返回异常 返回参数: " +

View File

@ -82,13 +82,13 @@ namespace VideoAnalysisCore.AICore.GPT.DeepSeek
var postMessages = var postMessages =
$"你的任务是分析视频字幕内容并提取出中国高考考试试题方法点,然后分析出<知识块>,来帮助学生快速了解视频字幕的内容" + $"你的任务是分析视频字幕内容并提取出中国高考考试试题方法点,然后分析出<知识块>,来帮助学生快速了解视频字幕的内容" +
$"通过阅读并理解字幕内容.然后识别出{subject}学科中属于{fileNameInfoRes.授课章节}章节相关的方法点以及对应的时间段。" + $"通过阅读并理解字幕内容.然后识别出{subject}学科中属于{fileNameInfoRes.授课章节}章节相关的方法点以及对应的时间段。" +
$"关联合并知识内容相似的知识点来合并为<知识块>。(请注意如果<知识块>时长超过600秒则考虑拆封为两个更加贴切的<知识块>.或者<知识块>时长小于30秒则考虑合并<知识块>到相邻的<知识块>)" + $"关联合并知识内容相似的知识点来合并为<知识块>。" +
$"分配空余未使用的时间段到内容相近的<知识块>时间区间来获取更加详细的上下文,但是请避免<知识块>之间时间重合。" + $"分配空余未使用的时间段到内容相近的<知识块>时间区间来获取更加详细的上下文,但是请避免<知识块>之间时间重合。" +
$"从提取出的<知识块>内容称来匹配我提供的知识点,来作为片段的知识点(请确保匹配的知识点是用户提供的,否则片段知识点值为空字符串)。" + $"从提取出的<知识块>内容称来匹配我提供的知识点,来作为片段的知识点(请确保匹配的知识点是用户提供的,否则片段知识点值为空字符串)。" +
$"提供的方法点名称({knows})。 格式 (方法点Id|方法点名称) 如果一个<知识块>出现多个知识点那么知识点Id与知识点名称都用逗号','分割。" + $"提供的方法点名称({knows})。 格式 (方法点Id|方法点名称) 如果一个<知识块>出现多个知识点那么知识点Id与知识点名称都用逗号','分割。" +
$"这是输入的视频字幕并且是包含时间戳的视频字幕的固定格式文本。" + $"这是输入的视频字幕并且是包含时间戳的视频字幕的固定格式文本。" +
$"字幕格式(说话人:开始秒:结束秒:内容|下一段字幕).以下是包含时间的视频字幕文本。字幕列表 {captions.Captions}。" + $"字幕格式(说话人:开始秒:结束秒:内容|下一段字幕).以下是包含时间的视频字幕文本。字幕列表 {captions.Captions}。" +
$"最后请检查某些<知识块>之间的过渡是否自然。建议按时间顺序优化分段密度,增强知识点衔接。" + $"最后请检查某些<知识块>之间的过渡是否自然,如果<知识块>时长超过500秒则考虑拆封为两个更加贴切的<知识块>.或者<知识块>时长小于30秒则考虑合并<知识块>到相邻的<知识块>)。" +
$"输出格式({resFormat})"; $"输出格式({resFormat})";
Console.WriteLine(DateTime.Now + "=>开始分析视频内容"); Console.WriteLine(DateTime.Now + "=>开始分析视频内容");
@ -109,7 +109,7 @@ namespace VideoAnalysisCore.AICore.GPT.DeepSeek
var thems = string.Join(',', questionRes.Select(s => s.StartTime + "->" + s.Theme)); var thems = string.Join(',', questionRes.Select(s => s.StartTime + "->" + s.Theme));
var checkResFormat = """{"Score":打分(number),"Evaluation":评价(string)}"""; var checkResFormat = """{"Score":打分(number),"Evaluation":评价(string)}""";
var checkMessage = "我为视频的讲解内容做了一些分段,你能帮我检查下这些分段的分配合理吗?请给出你的打分(0-100,60分及格)以及评价" + var checkMessage = "我为视频的讲解内容做了一些分段,你能帮我检查下这些分段的时间分配合理吗?请给出你的打分(0-100,70分及格)以及评价" +
$"这是我的分段 {thems}." + $"这是我的分段 {thems}." +
$"后续的内容是包含时间戳的视频字幕的固定格式文本。" + $"后续的内容是包含时间戳的视频字幕的固定格式文本。" +
$"字幕格式(说话人:开始秒:结束秒:内容|下一段字幕).以下是包含时间的视频字幕文本。字幕列表 {captions.Captions}。" + $"字幕格式(说话人:开始秒:结束秒:内容|下一段字幕).以下是包含时间的视频字幕文本。字幕列表 {captions.Captions}。" +
@ -121,20 +121,20 @@ namespace VideoAnalysisCore.AICore.GPT.DeepSeek
break; break;
else else
{ {
Console.WriteLine(DateTime.Now + "=>得分过低 " + checkRes?.Score ); Console.WriteLine(DateTime.Now + $"=>{task} 得分过低 " + checkRes?.Score );
Console.WriteLine( checkRes.Evaluation); Console.WriteLine( checkRes.Evaluation);
Console.WriteLine( ); Console.WriteLine( );
} }
} }
await videoKonwPointDB.DeleteAsync(s => s.VideoTaskId == taskId);
var data = questionRes var insertData = questionRes
.Where(s=>!string.IsNullOrEmpty(s.KnowPoint)) .Where(s => !string.IsNullOrEmpty(s.KnowPoint))
.SelectMany( .SelectMany(
s => s =>
{ {
var ks = s.KnowPoint.Split(","); var ks = s.KnowPoint.Split(",").Distinct();
return ks.Where(x=>knowDic.ContainsKey(x)) return ks.Where(x => knowDic.ContainsKey(x))
.Select(x => new VideoKonwPoint() .Select(x => new VideoKonwPoint()
{ {
Content = s.Content, Content = s.Content,
@ -147,7 +147,8 @@ namespace VideoAnalysisCore.AICore.GPT.DeepSeek
VideoTaskId = taskInfo.Id, VideoTaskId = taskInfo.Id,
}); });
}).ToList(); }).ToList();
await videoKonwPointDB.InsertRangeAsync(data); await videoKonwPointDB.DeleteAsync(s => s.VideoTaskId == taskId);
await videoKonwPointDB.InsertRangeAsync(insertData);

View File

@ -42,6 +42,7 @@ namespace VideoAnalysisCore.AICore.SherpaOnnx
//模型类型 //模型类型
config.ModelConfig.ModelType = string.Empty; config.ModelConfig.ModelType = string.Empty;
config.ModelConfig.NumThreads = numThreads; config.ModelConfig.NumThreads = numThreads;
config.ModelConfig.Provider = "cpu";
//需要使用GPU //需要使用GPU
if (!useGPU) if (!useGPU)
config.ModelConfig.Provider = "cuda"; config.ModelConfig.Provider = "cuda";
@ -251,10 +252,10 @@ namespace VideoAnalysisCore.AICore.SherpaOnnx
End = (float)Math.Round(startTime + duration, 2, MidpointRounding.AwayFromZero), End = (float)Math.Round(startTime + duration, 2, MidpointRounding.AwayFromZero),
}); });
} }
VAD.Pop(); VAD.Pop();
} }
Console.WriteLine(DateTime.Now + "=> SenseVoice 字幕数量"+ res.Count);
await RedisExpand.Redis.HMSetAsync(RedisExpandKey.Task(task), "Captions", res); await RedisExpand.Redis.HMSetAsync(RedisExpandKey.Task(task), "Captions", res);
//RedisExpand.InsertChannel(Enum.RedisChannelEnum.ParsingSpeaker, task); //RedisExpand.InsertChannel(Enum.RedisChannelEnum.ParsingSpeaker, task);
RedisExpand.InsertChannel(Enum.RedisChannelEnum.ChatModelAnalysis, task); RedisExpand.InsertChannel(Enum.RedisChannelEnum.ChatModelAnalysis, task);

View File

@ -97,7 +97,7 @@ namespace VideoAnalysisCore.Common
Redis.Deserialize = (json, type) => System.Text.Json.JsonSerializer.Deserialize(json, type); Redis.Deserialize = (json, type) => System.Text.Json.JsonSerializer.Deserialize(json, type);
Task.Run(() => Task.Run(() =>
{ {
Task.Delay(1000 * 10); Thread.Sleep(1000 * 10);
InitChannel(); InitChannel();
}); });
} }