Compare commits
No commits in common. "d433d84d46c702e69a3a8f7db175af88744d2cf8" and "2bdd77380cf8e31f69324757b388d7c63566b390" have entirely different histories.
d433d84d46
...
2bdd77380c
|
|
@ -11,24 +11,19 @@
|
|||
@for (int i = 0; i < videoKnows.Length; i++)
|
||||
{
|
||||
var item = videoKnows[i];
|
||||
<div class="knowDiv">
|
||||
<div class="knowDiv" onclick="spClick(@i,this)">
|
||||
|
||||
<div class="knowTtile">
|
||||
<div style="cursor: pointer" onclick="spClick(@i,this)">
|
||||
<div class="knowTtileTheme">@getF(item) @item.Theme</div>
|
||||
<span class="kSpan">#@item.KnowPointId @item.KnowPoint</span>
|
||||
</div>
|
||||
<div>概览: @item.Content</div>
|
||||
<br />
|
||||
@foreach (var q in item.QuestionArr)
|
||||
{
|
||||
|
||||
<div class="knowQuestion" onclick="spClickTime(@q.StartTime)">
|
||||
<h3>问题: <span class="kSpan">@q.StartTime 秒</span></h3>
|
||||
<div class="kSpan">@q.TopicStem</div>
|
||||
<div >@q.Question</div>
|
||||
<h3>问题: </h3>
|
||||
<div class="knowQuestion">@q.Question</div>
|
||||
<img style="text-align:center" src="@q.ImageUrl" width="320" height="180" />
|
||||
</div>
|
||||
<br />
|
||||
<br />
|
||||
}
|
||||
<br />
|
||||
|
|
@ -117,9 +112,6 @@
|
|||
function spClick(i, button) {
|
||||
videoPlayer.currentTime = displayButton[i].startTime;
|
||||
}
|
||||
function spClickTime(startTime) {
|
||||
videoPlayer.currentTime = startTime;
|
||||
}
|
||||
function gd(btn) {
|
||||
let e = btn.parentElement.parentElement
|
||||
if (e.style.right == "0px") {
|
||||
|
|
|
|||
|
|
@ -11,24 +11,20 @@
|
|||
float: left;
|
||||
overflow-x: hidden;
|
||||
}
|
||||
|
||||
.kSpan {
|
||||
color: rgba(120, 120, 120,0.66);
|
||||
font-size: 0.8rem;
|
||||
width: 330px;
|
||||
}
|
||||
|
||||
.textEllipsis {
|
||||
white-space: nowrap; /* 禁止换行 */
|
||||
overflow: hidden; /* 隐藏溢出内容 */
|
||||
text-overflow: ellipsis; /* 显示省略号 */
|
||||
}
|
||||
|
||||
video {
|
||||
width: 94%;
|
||||
height: 85%;
|
||||
}
|
||||
|
||||
.gudingBtn {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
|
|
@ -36,7 +32,6 @@ video {
|
|||
line-height: 27px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.subtitles {
|
||||
position: absolute;
|
||||
bottom: 200px;
|
||||
|
|
@ -46,11 +41,9 @@ video {
|
|||
background-color: rgba(0, 0, 0, 0.7);
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
#segmentsContainer:is(:hover) {
|
||||
right: 0px!important;
|
||||
}
|
||||
|
||||
#segmentsContainer {
|
||||
transition: right 0.7s;
|
||||
z-index: 999;
|
||||
|
|
@ -69,7 +62,7 @@ video {
|
|||
padding: 10px;
|
||||
align-content: flex-start;
|
||||
justify-content: flex-start;
|
||||
align-items: center;
|
||||
align-items: flex-end
|
||||
}
|
||||
|
||||
.kBtn {
|
||||
|
|
@ -82,7 +75,6 @@ video {
|
|||
background-color: rgb(240, 249, 235);
|
||||
border: 1px solid rgb(179, 225, 157);
|
||||
}
|
||||
|
||||
.knowTtileTheme {
|
||||
font-size: 1.3rem;
|
||||
cursor: pointer;
|
||||
|
|
@ -93,24 +85,18 @@ video {
|
|||
background-color: rgb(248, 230, 191) !important;
|
||||
border: 1px solid rgb(206, 187, 81);
|
||||
}
|
||||
|
||||
.knowDiv {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.knowQuestion {
|
||||
cursor: pointer;
|
||||
border: 2px solid #ff000059;
|
||||
border-radius: 10px;
|
||||
background-color: #cddc393d;
|
||||
}
|
||||
|
||||
.knowDiv:hover .knowTtile {
|
||||
width: 340px;
|
||||
display:block;
|
||||
background-color: rgb(240, 249, 235);
|
||||
border: 1px solid rgb(179, 225, 157);
|
||||
}
|
||||
|
||||
.knowTtile {
|
||||
position: absolute;
|
||||
text-align: left;
|
||||
|
|
|
|||
|
|
@ -15,8 +15,6 @@ using Microsoft.AspNetCore.Mvc.Formatters;
|
|||
using System.Security.Cryptography;
|
||||
using System.Diagnostics;
|
||||
using VideoAnalysisCore.AICore.FFMPGE;
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Text.Unicode;
|
||||
|
||||
|
||||
|
||||
|
|
@ -41,11 +39,7 @@ namespace Learn.VideoAnalysis
|
|||
loggingBuilder.SetMinimumLevel(LogLevel.Warning); // 设置最小日志级别为 Warning
|
||||
});
|
||||
|
||||
builder.Services.AddControllers()
|
||||
.AddJsonOptions(options =>
|
||||
{
|
||||
options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All);
|
||||
});
|
||||
builder.Services.AddControllers();
|
||||
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen(c =>
|
||||
|
|
|
|||
|
|
@ -154,7 +154,7 @@ namespace VideoAnalysisCore.AICore.GPT.DeepSeek
|
|||
var messageBuilder1 = new StringBuilder();
|
||||
var lastChat = new ChatResSSE();
|
||||
var splitCount = "data:".Length;
|
||||
var maxLoop = 60*10000;
|
||||
var maxLoop = 60*1000;
|
||||
int threshold = 0;
|
||||
while (maxLoop>0)
|
||||
{
|
||||
|
|
@ -205,7 +205,6 @@ namespace VideoAnalysisCore.AICore.GPT.DeepSeek
|
|||
}
|
||||
}
|
||||
}
|
||||
Console.WriteLine(DateTime.Now + "=>AI请求超时 " + chatReq.taskId);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ namespace VideoAnalysisCore.AICore.GPT.DeepSeek
|
|||
/// </summary>
|
||||
public string model { get; set; } = "deepseek-reasoner";
|
||||
|
||||
public float max_tokens { get; set; } = 8000;
|
||||
public float max_tokens { get; set; } = 4000;
|
||||
/// <summary>
|
||||
/// 要使用的采样温度,介于 0 和 2 之间。较高的值(如 0.8)将使输出更加随机,而较低的值(如 0.2)将使其更加集中和确定。 我们通常建议更改此项或同时更改两者。top_p
|
||||
/// <para> 默认为 1</para>
|
||||
|
|
@ -38,7 +38,7 @@ namespace VideoAnalysisCore.AICore.GPT.DeepSeek
|
|||
/// 一种替代温度采样的方法,称为原子核采样, 其中,模型考虑具有top_p概率的标记的结果 质量。所以 0.1 表示仅包含前 10% 概率质量的代币 被考
|
||||
/// <para>建议与<see cref="ChatRequest.temperature"/>联动</para>
|
||||
/// </summary>
|
||||
public float top_p { get; set; } = 0.1f;
|
||||
public float top_p { get; set; } = 0.5f;
|
||||
/// <summary>
|
||||
/// 一个对象,用于指定模型必须输出的格式。设置为 enable 结构化输出,确保模型与您提供的 JSON 匹配 图式。
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ using static System.Collections.Specialized.BitVector32;
|
|||
using FFmpeg.NET.Services;
|
||||
using Aliyun.OSS;
|
||||
using Yitter.IdGenerator;
|
||||
using VideoAnalysisCore.Common.Expand;
|
||||
|
||||
namespace VideoAnalysisCore.AICore.GPT.DeepSeek
|
||||
{
|
||||
|
|
@ -173,14 +172,10 @@ namespace VideoAnalysisCore.AICore.GPT.DeepSeek
|
|||
{
|
||||
//校验结果质量
|
||||
var thems = JsonSerializer.Serialize(questionRes.Adapt<VideoKnowQueryDto[]>());
|
||||
var pptFormat = taskInfo.VideoType==AttachmentsInfoType.PPT
|
||||
? "这堂课是习题课,所讲解内容都是试题。"
|
||||
: string.Empty;
|
||||
var checkResFormat = """{"Score":打分(number),"Evaluation":评价(string)""";//,"Data":优化后的分段(array)}""";
|
||||
var checkMessage = "我为视频的讲解内容做了一些分段,希望你能通读字幕内容后检查下的分段是否符合我的要求?" +
|
||||
$"检查这些分段的时间是否合理 与相邻的时间段间隔是否大于30秒?" +
|
||||
$"检查这些分段的时间是否合理 与相邻的时间段间隔是否处于合理区间30~900秒之间?" +
|
||||
$"分段的主题内容,知识点分配是否合理符合实际吗?" +
|
||||
$"{pptFormat}" +
|
||||
$"请给出你的打分(0-100,70分及格)以及打分原因。" +
|
||||
$"这是我的分段 {thems}。" +
|
||||
$"后续的内容是包含时间戳的视频字幕的固定格式文本。" +
|
||||
|
|
@ -259,48 +254,50 @@ namespace VideoAnalysisCore.AICore.GPT.DeepSeek
|
|||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private async Task Analytics(List<VideoKnowRes> questionRes, VideoTask taskInfo,
|
||||
TotalCaptionsDto captions, string sections)
|
||||
SenseVoiceRes[] captionsArr, string sections)
|
||||
{
|
||||
var tryCount = 10;
|
||||
while (tryCount-->0)
|
||||
var lastTime = 0;
|
||||
var endTime = 0;
|
||||
var maxVideoTime = captionsArr?.LastOrDefault()?.End ?? 0;
|
||||
var subject = taskInfo.Subject.ToString();
|
||||
var timeSpan = (int)(maxVideoTime * 0.5);
|
||||
while (endTime + 60 < maxVideoTime)
|
||||
{
|
||||
try
|
||||
{
|
||||
endTime = lastTime + timeSpan;
|
||||
var nowCaptionStr = string.Join('|', captionsArr
|
||||
.Where(s => s.Text != "。")
|
||||
.Where((s, i) => s.Start > lastTime && s.End < endTime)
|
||||
.Select(s => s.Start + ":" + s.Text));
|
||||
var keyFrameArr = string.IsNullOrEmpty(taskInfo?.PPTVideoCode)
|
||||
? string.Empty
|
||||
: $"图像视频中授课内容PPT发生了变化的时间节点是{taskInfo.PPTKeyFrame},授课阶段结果可以参考这些时间节点。";
|
||||
: $"视频授课内容发生了变化的时间节点{taskInfo.PPTKeyFrame},授课阶段应当在附近时间发生变化。";
|
||||
var resFormat = """[{"StartTime":开始秒(number),"EndTime":结束秒(number),"Stage":阶段(string),"Theme":主题(string),"Content":内容总结(string)}]""";
|
||||
|
||||
var exerciseClass = taskInfo?.VideoType == AttachmentsInfoType.Review
|
||||
? $"但是本堂课是习题课,所以每个阶段是不同的例题讲解内容。"
|
||||
: string.Empty;
|
||||
//$"请注意 本次分析的视频字幕只是其中一部分 不需要分析出所有类型的授课阶段。";
|
||||
var postMessages =
|
||||
$"请通过视频字幕内容分析出视频中课堂的授课阶段。" +
|
||||
$"课堂内容与{taskInfo.Subject}学科下的{sections}章节相关。" +
|
||||
$"请通过视频字幕内容分析出视频中{subject}课堂的授课阶段。" +
|
||||
$"课堂内容与{sections}章节相关。" +
|
||||
$"{keyFrameArr}" +
|
||||
$"完整的课堂标准流程包含以下5个阶段:课程引入/新知讲解/例题精讲/课堂练习/知识总结。" +
|
||||
$"{exerciseClass}" +
|
||||
$"通过授课阶段的主要讲解内容分析出对应的授课阶段内容总结。" +
|
||||
$"通过生成的内容总结分析出对应的授课阶段主题。 " +
|
||||
$"最后请检查每个授课阶段的时长,不允许出现低于50秒的阶段。" +
|
||||
$"请注意 本次分析的视频字幕只是其中一部分 不需要分析出所有类型的授课阶段。" +
|
||||
$"最后请检查每个授课阶段的时长,不允许出现超出800秒或者低于50秒的授课阶段。" +
|
||||
$"输出内容只返回json格式({resFormat})" +
|
||||
$"字幕格式(开始秒:内容|下一段字幕).以下是包含时间的视频字幕文本。" +
|
||||
$"字幕列表 {captions.Captions} 字幕结束!";
|
||||
$"字幕列表 {nowCaptionStr} 字幕结束!";
|
||||
|
||||
Console.WriteLine(DateTime.Now + $"=>{taskInfo.Id.ToString()}.开始分析视频内容 {tryCount}");
|
||||
var resData = await ChatAsync<VideoKnowRes[]>(taskInfo.Id.ToString(), postMessages, "分析字幕");
|
||||
if (taskInfo?.VideoType == AttachmentsInfoType.Review)
|
||||
foreach (var item in resData)
|
||||
item.Stage = StageEnum.例题精讲.ToString();
|
||||
questionRes.AddRange(resData);
|
||||
break;
|
||||
Console.WriteLine(DateTime.Now + $"=>{taskInfo.Id.ToString()}.开始分析视频内容 {lastTime}~{endTime}");
|
||||
questionRes.AddRange(await ChatAsync<VideoKnowRes[]>(taskInfo.Id.ToString(), postMessages, "分析字幕"));
|
||||
lastTime = (int)questionRes.Last().EndTime.Value - (lastTime == 0 ? 0 : 30);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(DateTime.Now + $"=>{taskInfo.Id.ToString()}分析视频内容失败 {tryCount}");
|
||||
Console.WriteLine(DateTime.Now + $"=>分析视频内容失败 {lastTime}~{endTime}");
|
||||
Console.WriteLine(DateTime.Now + ex.Message);
|
||||
Console.WriteLine(DateTime.Now + ex.StackTrace);
|
||||
endTime = lastTime - timeSpan;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -316,7 +313,6 @@ namespace VideoAnalysisCore.AICore.GPT.DeepSeek
|
|||
{
|
||||
taskId = task,
|
||||
model = model,
|
||||
max_tokens= model== "deepseek-reasoner"?16000:8000,
|
||||
stream = true,
|
||||
temperature = 0.2f,
|
||||
messages = messageArr
|
||||
|
|
@ -337,13 +333,13 @@ namespace VideoAnalysisCore.AICore.GPT.DeepSeek
|
|||
redisCached[1] = new object[] { chatResp.Value.res, chatResp.Value.u, chatResp.Value.reasoning };
|
||||
RedisExpand.SetTaskGPTCached(task, time, redisCached);
|
||||
}
|
||||
chatResContent = chatResContent?.ExtractJsonStrings()?.FirstOrDefault();
|
||||
chatResContent = chatResContent?.Replace("字幕内容", "课堂情况");
|
||||
chatResContent = chatResContent?.Replace("\n", "");
|
||||
chatResContent = chatResContent?.Replace("```json", "");
|
||||
chatResContent = chatResContent?.Replace("```", "");
|
||||
chatResContent = chatResContent?.Replace("}{", "},{");
|
||||
chatResContent = chatResContent?.Replace("}|{", "},{");
|
||||
chatResContent = chatResContent?.Trim();
|
||||
chatResContent = chatResContent?.Trim().ExtractJson().FirstOrDefault();
|
||||
|
||||
var startsStr = typeof(T).IsArray ? "[" : "{";
|
||||
var endStr = typeof(T).IsArray ? "]" : "}";
|
||||
|
|
@ -405,39 +401,25 @@ namespace VideoAnalysisCore.AICore.GPT.DeepSeek
|
|||
.ProcessImageAsync(new SimpleTexOcrRequest(filePath));
|
||||
if (!sRes.Success)
|
||||
continue;
|
||||
if(sRes.Result.res.value.Trim().Length<10)//总试题内容长度小于10 视为无效题目
|
||||
break;
|
||||
Console.WriteLine(DateTime.Now + $"=>{taskInfo.Id} 提取{knowInfoArr.First().StartTime}秒试题的试题内容");
|
||||
Console.WriteLine( sRes.Result.res.value);
|
||||
var knowArr=JsonSerializer.Serialize(knowInfoArr.Select(s => new { s.KnowPointId, s.KnowPoint }));
|
||||
var resFormat = """[{"Type":string(试题类型),"TopicStem":string(试题题干),"QuestionArr":[{"Question":string(子问题),"KnowPointId":(string)知识点ID}]}]""";
|
||||
var knowArr=string.Join(',', knowInfoArr.Select(s => s.KnowPointId + "|" + s.KnowPoint ));
|
||||
var resFormat = """[{"TopicStem":string(试题题干),"Question:string(问题)","KnowPointId":(string)知识点ID}]""";
|
||||
var postMessages =
|
||||
$"我将提供一段内容是md格式的试题内容字符串。" +
|
||||
$"请提取出其中的试题内容试,题干以及每个试题的问题。并且为每个试题关联上在我限定范围内的知识点(多个则用逗号分割)。" +
|
||||
$"知识点格式(json格式)范围[{knowArr}]。" +
|
||||
$"排除不是试题内容的文字,优化公式排版并且去除题号,但不要修改latex数学公式。" +
|
||||
$"如果存在多道题,则需要拆分成为多个试题对象!" +
|
||||
$"试题的类型约束在 填空题/判断题/选择题/解答题 范围内。" +
|
||||
$"请检查我提供的字符串内容,如不包含问题试题则返回`[]`" +
|
||||
$"提供一段内容是md格式的试题内容字符串。" +
|
||||
$"请提取出其中的试题内容。并且为每个试题关联上在我限定范围内的知识点(多个则用逗号分割)。" +
|
||||
$"知识点格式(知识点ID|知识点名称)范围[{knowArr}]。" +
|
||||
$"排除不是试题内容的文字,优化公式排版并且去除题号。" +
|
||||
$"如果存在多道大题,请帮忙拆分开!" +
|
||||
$"输出内容只返回json格式为({resFormat})" +
|
||||
$"以下是试题内容" +
|
||||
$"`{sRes.Result.res.value}`";
|
||||
$"`{sRes.Result.res.info.markdown}`";
|
||||
var resData = await ChatAsync<VideoQuestionOSSDto[]>(taskInfo.Id.ToString(), postMessages, "提取试题", "deepseek-chat");
|
||||
foreach (var q in resData)
|
||||
{
|
||||
var TopicId = YitIdHelper.NextId();
|
||||
foreach (var qt in q.QuestionArr)
|
||||
{
|
||||
var vq = q.Adapt<VideoQuestionOSSDto>();
|
||||
vq.Id = YitIdHelper.NextId();
|
||||
vq.StartTime = item;
|
||||
vq.FilePath = filePath;
|
||||
vq.VideoTaskId = taskInfo.Id;
|
||||
vq.StageId = knowInfoArr.First().StageId;
|
||||
vq.Question = qt.Question;
|
||||
vq.TopicId = TopicId;
|
||||
insertData.Add(vq);
|
||||
foreach (var kid in qt.KnowPointId.Split(","))
|
||||
q.Id = YitIdHelper.NextId();
|
||||
q.FilePath = filePath;
|
||||
q.VideoTaskId = taskInfo.Id;
|
||||
q.StageId = knowInfoArr.First().StageId;
|
||||
foreach (var kid in q.KnowPointId.Split(","))
|
||||
{
|
||||
insertQuestionKonw.Add(new VideoQuestionKonw()
|
||||
{
|
||||
|
|
@ -449,7 +431,7 @@ namespace VideoAnalysisCore.AICore.GPT.DeepSeek
|
|||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
insertData.AddRange(resData);
|
||||
break;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -458,6 +440,13 @@ namespace VideoAnalysisCore.AICore.GPT.DeepSeek
|
|||
}
|
||||
}
|
||||
}
|
||||
//分组共同题干试题ID
|
||||
foreach (var item in insertData.GroupBy(x => x.TopicStem))
|
||||
{
|
||||
var keyId=YitIdHelper.NextId();
|
||||
foreach (var s in item)
|
||||
s.TopicId = keyId;
|
||||
}
|
||||
//上传oss 并更新imageUrl
|
||||
ossClient.AddVideoQuestionUrl(insertData);
|
||||
|
||||
|
|
@ -512,7 +501,7 @@ namespace VideoAnalysisCore.AICore.GPT.DeepSeek
|
|||
{
|
||||
questionRes = new List<VideoKnowRes>();
|
||||
//视频字幕分析
|
||||
await Analytics(questionRes, taskInfo, captions, sections);
|
||||
await Analytics(questionRes, taskInfo, captionsArr, sections);
|
||||
|
||||
if (questionRes.Count == 0) continue;
|
||||
//处理分段 知识点
|
||||
|
|
|
|||
|
|
@ -102,6 +102,50 @@ namespace VideoAnalysisCore.Common
|
|||
return Path.Combine(task.Id.ToString().LocalPath(), $"{FrameName}{(fTime / 5).ToString().PadLeft(3,'0')}.jpg");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 识别字符串中的json字符串
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
public static List<string> ExtractJson(this string input)
|
||||
{
|
||||
List<string> jsonList = new List<string>();
|
||||
int index = 0;
|
||||
|
||||
while (index < input.Length)
|
||||
{
|
||||
if (input[index] == '{' || input[index] == '[')
|
||||
{
|
||||
int startIndex = index;
|
||||
int openCount = 1;
|
||||
index++;
|
||||
|
||||
while (index < input.Length && openCount > 0)
|
||||
{
|
||||
if (input[index] == '{' || input[index] == '[')
|
||||
{
|
||||
openCount++;
|
||||
}
|
||||
else if (input[index] == '}' || input[index] == ']')
|
||||
{
|
||||
openCount--;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
|
||||
if (openCount == 0)
|
||||
{
|
||||
string json = input.Substring(startIndex, index - startIndex);
|
||||
jsonList.Add(json);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
index++;
|
||||
}
|
||||
}
|
||||
return jsonList;
|
||||
}
|
||||
/// <summary>
|
||||
/// 处理数学公式
|
||||
/// </summary>
|
||||
|
|
@ -202,8 +246,8 @@ namespace VideoAnalysisCore.Common
|
|||
//stringBuilder.Append(":");
|
||||
stringBuilder.Append((int)item.Key.Start);
|
||||
stringBuilder.Append(":");
|
||||
//stringBuilder.Append((int)item.Key.End);
|
||||
//stringBuilder.Append(":");
|
||||
stringBuilder.Append((int)item.Key.End);
|
||||
stringBuilder.Append(":");
|
||||
stringBuilder.Append(item.Key.Text);
|
||||
stringBuilder.Append("|");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VideoAnalysisCore.Common.Expand;
|
||||
|
||||
namespace VideoAnalysisCore.Common
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ using AlibabaCloud.TeaUtil.Models;
|
|||
using Microsoft.Extensions.DependencyInjection;
|
||||
using VideoAnalysisCore.Job;
|
||||
|
||||
namespace VideoAnalysisCore.Common.Expand
|
||||
namespace VideoAnalysisCore.Common
|
||||
{
|
||||
public class AlibabaCloudVodConfig
|
||||
{
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ using Aliyun.Credentials.Models;
|
|||
using VideoAnalysisCore.Model.Dto;
|
||||
using System.IO;
|
||||
|
||||
namespace VideoAnalysisCore.Common.Expand
|
||||
namespace VideoAnalysisCore.Common
|
||||
{
|
||||
public class AliyunOSSConfig
|
||||
{
|
||||
|
|
|
|||
|
|
@ -7,8 +7,6 @@ using System.Net.Http.Json;
|
|||
using System.Net.Sockets;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using AlibabaCloud.OpenApiClient.Models;
|
||||
using AlibabaCloud.SDK.Vod20170321;
|
||||
|
|
@ -17,9 +15,10 @@ using AlibabaCloud.TeaUtil.Models;
|
|||
using Azure;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Newtonsoft.Json;
|
||||
using VideoAnalysisCore.Job;
|
||||
|
||||
namespace VideoAnalysisCore.Common.Expand
|
||||
namespace VideoAnalysisCore.Common
|
||||
{
|
||||
|
||||
|
||||
|
|
@ -33,10 +32,7 @@ namespace VideoAnalysisCore.Common.Expand
|
|||
public class SimpleTexOcrResponseDataRes
|
||||
{
|
||||
public string type { get; set; }
|
||||
|
||||
[JsonPropertyName("info")] // 替换为实际字段名
|
||||
public JsonElement DataInfo { get; set; } // 使用JsonElement接收未知类型
|
||||
public string value { get; set; }
|
||||
public SimpleTexOcrResponseDataInfo info { get; set; }
|
||||
}
|
||||
|
||||
public class SimpleTexOcrResponseDataInfo
|
||||
|
|
@ -85,7 +81,6 @@ namespace VideoAnalysisCore.Common.Expand
|
|||
{
|
||||
public bool Success { get; set; }
|
||||
public SimpleTexOcrResponseData Result { get; set; }
|
||||
public string ResultStr { get; set; }
|
||||
public string Error { get; set; }
|
||||
}
|
||||
|
||||
|
|
@ -128,7 +123,7 @@ namespace VideoAnalysisCore.Common.Expand
|
|||
|
||||
if (request.isolated_formula_wrapper != null)
|
||||
{
|
||||
var isolatedWrapper = JsonSerializer.Serialize(request.isolated_formula_wrapper);
|
||||
var isolatedWrapper = JsonConvert.SerializeObject(request.isolated_formula_wrapper);
|
||||
content.Add(new StringContent(isolatedWrapper), nameof(request.isolated_formula_wrapper));
|
||||
parameters[nameof(request.isolated_formula_wrapper)] = isolatedWrapper;
|
||||
}
|
||||
|
|
@ -166,25 +161,11 @@ namespace VideoAnalysisCore.Common.Expand
|
|||
var response = await client.SendAsync(requestMessage);
|
||||
var resStr = await response.Content.ReadAsStringAsync();
|
||||
var responseContent = await response.Content.ReadFromJsonAsync<SimpleTexOcrResponseData>();
|
||||
if (responseContent.res.DataInfo.ValueKind == JsonValueKind.Object)
|
||||
{
|
||||
responseContent.res.value = JsonSerializer.Deserialize<SimpleTexOcrResponseDataInfo>(
|
||||
responseContent.res.DataInfo.GetRawText(),
|
||||
new JsonSerializerOptions { PropertyNameCaseInsensitive = true }
|
||||
)?.markdown??string.Empty;
|
||||
// 处理字符串
|
||||
}
|
||||
else if (responseContent.res.DataInfo.ValueKind == JsonValueKind.String)
|
||||
{
|
||||
responseContent.res.value = responseContent.res.DataInfo.GetString();
|
||||
}
|
||||
|
||||
request.file.Dispose();
|
||||
return new SimpleTexOcrResponse
|
||||
{
|
||||
Success = response.IsSuccessStatusCode,
|
||||
Result = responseContent,
|
||||
ResultStr= resStr,
|
||||
Error = response.IsSuccessStatusCode ? null : $"HTTP Error: {response.StatusCode}"
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,105 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace VideoAnalysisCore.Common
|
||||
{
|
||||
public static class JsonExtractor
|
||||
{
|
||||
/// <summary>
|
||||
/// 提取json字符串
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
public static List<string> ExtractJsonStrings(this string input)
|
||||
{
|
||||
List<string> jsonList = new List<string>();
|
||||
int index = 0;
|
||||
while (index < input.Length)
|
||||
{
|
||||
if (input[index] == '{' || input[index] == '[')
|
||||
{
|
||||
int? endIndex = FindMatchingBracket(input, index);
|
||||
if (endIndex.HasValue)
|
||||
{
|
||||
string candidate = input.Substring(index, endIndex.Value - index + 1);
|
||||
if (IsValidJson(candidate))
|
||||
{
|
||||
jsonList.Add(candidate);
|
||||
index = endIndex.Value + 1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
index++;
|
||||
}
|
||||
return jsonList;
|
||||
}
|
||||
|
||||
private static int? FindMatchingBracket(string str, int start)
|
||||
{
|
||||
Stack<char> stack = new Stack<char>();
|
||||
bool inString = false;
|
||||
bool inEscape = false;
|
||||
|
||||
for (int i = start; i < str.Length; i++)
|
||||
{
|
||||
char c = str[i];
|
||||
|
||||
if (inEscape)
|
||||
{
|
||||
inEscape = false;
|
||||
}
|
||||
else if (inString)
|
||||
{
|
||||
if (c == '\\')
|
||||
inEscape = true;
|
||||
else if (c == '"')
|
||||
inString = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case '{':
|
||||
case '[':
|
||||
stack.Push(c);
|
||||
break;
|
||||
case '}':
|
||||
if (stack.Count == 0 || stack.Peek() != '{')
|
||||
return null;
|
||||
stack.Pop();
|
||||
break;
|
||||
case ']':
|
||||
if (stack.Count == 0 || stack.Peek() != '[')
|
||||
return null;
|
||||
stack.Pop();
|
||||
break;
|
||||
case '"':
|
||||
inString = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (stack.Count == 0)
|
||||
return i;
|
||||
}
|
||||
return null; // 括号未完全匹配
|
||||
}
|
||||
|
||||
public static bool IsValidJson(string candidate)
|
||||
{
|
||||
if (string.IsNullOrEmpty(candidate))
|
||||
return false;
|
||||
try
|
||||
{
|
||||
JsonDocument.Parse(candidate);
|
||||
return true;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -15,7 +15,6 @@ using VideoAnalysisCore.Model;
|
|||
using Microsoft.AspNetCore.Http;
|
||||
using VideoAnalysisCore.Model.Dto;
|
||||
using VideoAnalysisCore.Controllers.Dto;
|
||||
using VideoAnalysisCore.Common.Expand;
|
||||
|
||||
namespace VideoAnalysisCore.Controllers
|
||||
{
|
||||
|
|
@ -45,29 +44,6 @@ namespace VideoAnalysisCore.Controllers
|
|||
throw new Exception("未能获取到客户端ip地址");
|
||||
}
|
||||
|
||||
|
||||
#if DEBUG
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// ³õʼ»¯Ö÷¿â±í
|
||||
/// </summary>
|
||||
/// <param name="url">ÎļþÁ÷</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet(Name = "InitDbTable")]
|
||||
public IActionResult InitDbTable()
|
||||
{
|
||||
var b = AppCommon.Config.DB.UpdateTable;
|
||||
AppCommon.Config.DB.UpdateTable= true;
|
||||
SqlSugarExpand.InitDbTable();
|
||||
AppCommon.Config.DB.UpdateTable = b;
|
||||
return Ok();
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 语音识别
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
using SqlSugar;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
|
@ -7,26 +6,9 @@ using System.Threading.Tasks;
|
|||
|
||||
namespace VideoAnalysisCore.Model.Dto
|
||||
{
|
||||
public class AIQuestionDto
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 问题
|
||||
/// </summary>
|
||||
public string Question { get; set; }
|
||||
/// <summary>
|
||||
/// 知识点id
|
||||
/// </summary>
|
||||
public string KnowPointId { get; set; }
|
||||
}
|
||||
public class VideoQuestionOSSDto: VideoQuestion
|
||||
{
|
||||
/// <summary>
|
||||
/// 问题
|
||||
/// </summary>
|
||||
public AIQuestionDto[]? QuestionArr { get; set; }
|
||||
public string FilePath { get; set; }
|
||||
public string Type { get; set; }
|
||||
public string KnowPointId { get; set; }
|
||||
}
|
||||
public class VideoQuestionShowDto : VideoQuestion
|
||||
|
|
|
|||
|
|
@ -52,9 +52,5 @@ namespace VideoAnalysisCore.Model
|
|||
/// 问题(设问)
|
||||
/// </summary>
|
||||
public string? Question { get; set; }
|
||||
/// <summary>
|
||||
/// 试题开始时间
|
||||
/// </summary>
|
||||
public int StartTime { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue