Compare commits
No commits in common. "58a25c5c083c61b44db8ee0e71dfc901e3d792f5" and "4d146d718bd6b3f8ef2b50950389b422cb8c771a" have entirely different histories.
58a25c5c08
...
4d146d718b
|
|
@ -1,12 +1,9 @@
|
|||
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
|
||||
FROM dotnet/aspnet:8.0
|
||||
|
||||
|
||||
# 更新 apt 源
|
||||
COPY sources.list /etc/apt/sources.list
|
||||
RUN apt-get update
|
||||
RUN apt-get install -y ffmpeg
|
||||
RUN ["apt-get", "--assume-yes", "update"]
|
||||
RUN ["apt-get", "--assume-yes", "install", "ffmpeg"]
|
||||
|
||||
WORKDIR /app
|
||||
EXPOSE 9040
|
||||
|
|
@ -16,6 +13,9 @@ COPY . .
|
|||
ENV TZ=Asia/Shanghai
|
||||
|
||||
|
||||
#RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ sid main contrib non-free" > /etc/apt/sources.list
|
||||
#RUN apt-get update && apt-get install -y apt-transport-https ca-certificates apt-utils libgdiplus libc6-dev && apt-get install -y libfreetype6 && apt-get install -y libfontconfig1 && apt-get install -y fontconfig
|
||||
#
|
||||
ENV ASPNETCORE_URLS=http://+:9040
|
||||
|
||||
ENTRYPOINT ["dotnet", "Learn.VideoAnalysis.dll"]
|
||||
|
|
|
|||
|
|
@ -17,16 +17,12 @@
|
|||
|
||||
<ItemGroup>
|
||||
<None Remove="Dockerfile" />
|
||||
<None Remove="sources.list" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="Dockerfile">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="sources.list">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -1,13 +0,0 @@
|
|||
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
|
||||
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
|
||||
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
|
||||
|
||||
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
|
||||
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
|
||||
|
||||
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
|
||||
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
|
||||
|
||||
# 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换
|
||||
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware
|
||||
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware
|
||||
|
|
@ -20,7 +20,7 @@ namespace VideoAnalysisCore.AICore.ChatGPT.Dto
|
|||
public TaskRes(TotalCaptionsDto captions)
|
||||
{
|
||||
this.TeacherSpeaking = captions.TeacherSpeaking;
|
||||
this.TimeBase = captions.TimeBase?.ToList();
|
||||
this.TimeBase = captions.TimeBase;
|
||||
this.StudentSpeaking = captions.StudentSpeaking;
|
||||
}
|
||||
/// <summary>
|
||||
|
|
@ -45,11 +45,11 @@ namespace VideoAnalysisCore.AICore.ChatGPT.Dto
|
|||
/// <summary>
|
||||
/// 时间段概览
|
||||
/// </summary>
|
||||
public TimeBase[]? TimeOverview { get; set; }
|
||||
public IEnumerable<TimeBase>? TimeOverview { get; set; }
|
||||
/// <summary>
|
||||
/// 视频时间轴
|
||||
/// </summary>
|
||||
public List<TimeBase>? TimeBase { get; set; }
|
||||
public IEnumerable<TimeBase>? TimeBase { get; set; }
|
||||
/// <summary>
|
||||
/// GPT模型id
|
||||
/// </summary>
|
||||
|
|
@ -63,9 +63,8 @@ namespace VideoAnalysisCore.AICore.ChatGPT.Dto
|
|||
/// <para>满分100</para>
|
||||
/// </summary>
|
||||
public float AssessmentScore =>
|
||||
(float)(
|
||||
(Assessment?.Bad?.Sum(x => x.Score) ?? 0) +
|
||||
(Assessment?.Merit?.Sum(x => x.Score) ?? 0));
|
||||
(float)(Assessment?.Bad?.Sum(x => x.Score)??0 +
|
||||
Assessment?.Merit?.Sum(x => x.Score) ?? 0);
|
||||
//(float)Math.Round((Assessment?.Bad?.Select(x => x.Score)
|
||||
//.Concat(Assessment?.Merit?.Select(s => s.Score) ?? [])
|
||||
//.Average() ?? 0) * 10,2);
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ namespace VideoAnalysisCore.AICore.ChatGPT.KIMI
|
|||
criteriaBuilder.Append("|");
|
||||
}
|
||||
|
||||
var resFormat = """{"问题编号":number,"结果":array|bool|object,"问题解释":string}""";
|
||||
var resFormat = "[{问题编号:int,结果:array|bool|object,问题解释:string}]";
|
||||
var postMessages =
|
||||
$"你是一个教学经验老道老师对教学工作有着深入的理解和丰富的经验,能够准确把握教学大纲的要求和教学重点。" +
|
||||
$"熟练掌握各种教学管理方法和手段,能够制定科学合理的教学计划和教学评估体系。" +
|
||||
|
|
@ -92,10 +92,11 @@ namespace VideoAnalysisCore.AICore.ChatGPT.KIMI
|
|||
$"以下是一段音频的字幕,分析这段字幕 字幕格式(说话人:开始秒:结束秒:内容|下一段字幕)." +
|
||||
$"字幕列表 {captions.Captions} " +
|
||||
$"基于字幕内容回答提出的所有问题 问题格式(问题编号:问题描述:结束秒:结果类型|下一个问题)" +
|
||||
$"问题列表 {criteriaBuilder} "
|
||||
+$"返回固定的JSON数组格式({resFormat})";
|
||||
|
||||
|
||||
$"问题列表 {criteriaBuilder} " +
|
||||
$"返回固定的JSON数组格式({resFormat}).";
|
||||
var modelsResp = await moonshotClient.ListModels();
|
||||
if (modelsResp is null || modelsResp.data.Count == 0)
|
||||
throw new Exception("未获取KIMI模型类型");
|
||||
var reqTokenCount = await moonshotClient.GetAsTiMateTokenCount(postMessages);
|
||||
var maxTokens = 4000;
|
||||
var modelId = reqTokenCount > 32 * 1000 - maxTokens ? "moonshot-v1-128k" : "moonshot-v1-32k";
|
||||
|
|
@ -108,28 +109,18 @@ namespace VideoAnalysisCore.AICore.ChatGPT.KIMI
|
|||
model = modelId,
|
||||
messages = new List<MessagesItem>(){
|
||||
new MessagesItem(postMessages,"system"),
|
||||
//new MessagesItem(resFormat,"assistant",true),
|
||||
new MessagesItem(resFormat,"assistant"),
|
||||
}
|
||||
};
|
||||
|
||||
RedisExpand.SetTaskGPTReqCached(task, chatRep);
|
||||
var chatResp = await moonshotClient.ChatSSE(chatRep);
|
||||
//chatResp = await moonshotClient.Chat(chatRep);
|
||||
var chatResContent = chatResp?.res;
|
||||
if (string.IsNullOrEmpty(chatResContent))
|
||||
throw new Exception("KIMIGPT返回message无效结果");
|
||||
if(chatResp !=null)
|
||||
RedisExpand.SetTaskGPTCached(task, new object[]{ chatResp.Value.res, chatResp.Value.u });
|
||||
|
||||
var chatResp = await moonshotClient.Chat(chatRep);
|
||||
RedisExpand.SetTaskGPTCached(task, chatResp);
|
||||
if (chatResp is null || chatResp.error != null)
|
||||
throw new Exception($"KIMI模型返回异常 Chat 返回参数: " +
|
||||
$" {JsonSerializer.Serialize(chatResp)}");
|
||||
var chatResContent = chatResp?.choices.FirstOrDefault()?.message.content;
|
||||
chatResContent = chatResContent?.Replace("字幕内容", "课堂情况");
|
||||
chatResContent = chatResContent?.Replace("\n", "");
|
||||
chatResContent = chatResContent?.Replace("}{", "},{");
|
||||
chatResContent = chatResContent?.Replace("}|{", "},{");
|
||||
chatResContent = chatResContent?.Trim();
|
||||
if (!chatResContent.StartsWith("["))
|
||||
chatResContent = "[" + chatResContent;
|
||||
if (!chatResContent.EndsWith("]"))
|
||||
chatResContent = chatResContent+ "]";
|
||||
if (chatResContent is null)
|
||||
throw new Exception("KIMIGPT返回message无效结果");
|
||||
var questionRes = JsonSerializer.Deserialize<QuestionRes[]>(chatResContent);
|
||||
var gptRes = new TaskRes(captions);
|
||||
if (questionRes is null)
|
||||
|
|
@ -185,7 +176,7 @@ namespace VideoAnalysisCore.AICore.ChatGPT.KIMI
|
|||
foreach (var s in arr)
|
||||
s.TimeBaseType = r;
|
||||
}
|
||||
var totalTokens = chatResp?.u.total_tokens ?? 0;
|
||||
var totalTokens = chatResp?.usage.total_tokens ?? 0;
|
||||
if (totalTokens > 1)
|
||||
{
|
||||
var tid = long.Parse(task);
|
||||
|
|
|
|||
|
|
@ -9,9 +9,6 @@ using System.Net.Http.Json;
|
|||
using AntDesign;
|
||||
using OneOf.Types;
|
||||
using System.Net;
|
||||
using Azure;
|
||||
using System.Reflection.PortableExecutable;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
|
||||
/// <summary>
|
||||
/// https://platform.moonshot.cn/docs/api-reference
|
||||
|
|
@ -53,76 +50,16 @@ namespace VideoAnalysisCore.AICore.ChatGPT.KIMI
|
|||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ChatSSE
|
||||
/// </summary>
|
||||
/// <param name="chatReq"></param>
|
||||
/// <returns>Return HttpResponseMessage for SSE</returns>
|
||||
public async Task<(Usage u, string res)?> ChatSSE(ChatReq chatReq)
|
||||
{
|
||||
chatReq.stream = true;
|
||||
var requestBody = System.Text.Json.JsonSerializer.Serialize(chatReq);
|
||||
var chatResp = await PostJsonStreamAsync("/v1/chat/completions", requestBody);
|
||||
using var stream = await chatResp.Content.ReadAsStreamAsync();
|
||||
using var reader = new StreamReader(stream, Encoding.UTF8);
|
||||
string line;
|
||||
StringBuilder messageBuilder = new StringBuilder();
|
||||
ChatResSSE lastChat = new ChatResSSE();
|
||||
while ((line = await reader.ReadLineAsync()) != null)
|
||||
{
|
||||
if (line.EndsWith("[DONE]"))
|
||||
{
|
||||
// 表示一条消息结束
|
||||
string message = messageBuilder.ToString();
|
||||
messageBuilder.Clear();
|
||||
var u = lastChat?.choices?.FirstOrDefault()?.usage;
|
||||
if (u == null || string.IsNullOrEmpty(message))
|
||||
return null;
|
||||
return (u, message);
|
||||
}
|
||||
else if (line.StartsWith("data:"))
|
||||
{
|
||||
try
|
||||
{
|
||||
var data = System.Text.Json.JsonSerializer.Deserialize<ChatResSSE>(line.Substring("data:".Length).Trim());
|
||||
lastChat = data;
|
||||
var str = data?.choices.FirstOrDefault()?.delta.content;
|
||||
if (!string.IsNullOrEmpty(str))
|
||||
messageBuilder.Append(str);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("异常 ChatSSE=>" );
|
||||
Console.WriteLine(line);
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine(e.StackTrace);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Chat
|
||||
/// </summary>
|
||||
/// <param name="chatReq"></param>
|
||||
/// <returns>Return HttpResponseMessage for SSE</returns>
|
||||
public async Task<(Usage u, string res)?> Chat(ChatReq chatReq)
|
||||
public async Task<ChatRes?> Chat(ChatReq chatReq)
|
||||
{
|
||||
var requestBody = System.Text.Json.JsonSerializer.Serialize(chatReq);
|
||||
var chatResp = await PostJsonStreamAsync("/v1/chat/completions", requestBody);
|
||||
var res = await chatResp.Content.ReadFromJsonAsync<ChatRes>();
|
||||
var chatResContent = res?.choices.FirstOrDefault()?.message.content.Trim();
|
||||
|
||||
if (res is null || res.error != null)
|
||||
throw new Exception($"KIMI模型返回异常 Chat 返回参数: " +
|
||||
$" {System.Text.Json.JsonSerializer.Serialize(res)}");
|
||||
|
||||
if (string.IsNullOrEmpty(chatResContent))
|
||||
return null;
|
||||
|
||||
|
||||
return (res.usage, chatResContent);
|
||||
return await chatResp.Content.ReadFromJsonAsync<ChatRes>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -7,11 +7,10 @@
|
|||
{
|
||||
|
||||
}
|
||||
public MessagesItem(string content, string role = "user",bool partial = false)
|
||||
public MessagesItem(string content, string role = "user")
|
||||
{
|
||||
this.content = content;
|
||||
this.role = role;
|
||||
this.partial = partial;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
|
|
@ -148,19 +147,6 @@
|
|||
public string type { get; set; } = string.Empty;
|
||||
|
||||
}
|
||||
public class ChatResSSE
|
||||
{
|
||||
public string id { get; set; }
|
||||
public int created { get; set; }
|
||||
/// <summary>
|
||||
/// 模型id
|
||||
/// </summary>
|
||||
public string model { get; set; }
|
||||
/// <summary>
|
||||
/// 对话
|
||||
/// </summary>
|
||||
public ChoiceSSE[] choices { get; set; }
|
||||
}
|
||||
public class ChatRes
|
||||
{
|
||||
public ChatResError? error { get; set; }
|
||||
|
|
@ -198,16 +184,6 @@
|
|||
public int total_tokens { get; set; }
|
||||
}
|
||||
|
||||
public class ChoiceSSE
|
||||
{
|
||||
public int index { get; set; }
|
||||
public Message delta { get; set; }
|
||||
public string finish_reason { get; set; }
|
||||
/// <summary>
|
||||
/// token使用情况
|
||||
/// </summary>
|
||||
public Usage usage { get; set; }
|
||||
}
|
||||
public class Choice
|
||||
{
|
||||
public int index { get; set; }
|
||||
|
|
|
|||
|
|
@ -105,11 +105,7 @@ namespace VideoAnalysisCore.Common
|
|||
/// <param name="taskId"></param>
|
||||
public static void SetTaskGPTCached(object taskId, object? data)
|
||||
{
|
||||
Redis.Set(RedisExpandKey.TaskGPT(taskId)+":Res_" + DateTime.Now.ToString("yyyy/MM/dd_HH/mm/ss"), data, 3600 * 24);
|
||||
}
|
||||
public static void SetTaskGPTReqCached(object taskId, object? data)
|
||||
{
|
||||
Redis.Set(RedisExpandKey.TaskGPT(taskId)+":Req_"+ DateTime.Now.ToString("yyyy/MM/dd_HH/mm/ss"), data, 3600*24);
|
||||
Redis.Set(RedisExpandKey.TaskGPT(taskId), data, 3600*24);
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取任务进度
|
||||
|
|
|
|||
|
|
@ -11,16 +11,16 @@ namespace VideoAnalysisCore.Enum
|
|||
{
|
||||
|
||||
[Display(Prompt = "分析授课中使用的高频词" +
|
||||
"10个频率从高到低 :结果类型[]")]
|
||||
"10个频率从高到低 结果类型[]")]
|
||||
高频词 = 5001,
|
||||
[Display(Prompt = "基于字幕内容精准的提取出课堂上全部的事件" +
|
||||
",分析事件的时间片段提取事件的的内容概览,字幕开始秒,结束秒.作为返回结果.每个片段不低于120秒 :结果类型[{Start:开始秒,End:结束秒,Content:概览}]")]
|
||||
[Display(Prompt = "基于字幕描述内容精准的划分成时间片段" +
|
||||
",提取片段的内容概览,字幕开始秒,结束秒.作为返回结果.每个个片段不低于120秒 结果类型[{Start:开始秒,End:结束秒,Content:概览}]")]
|
||||
时间段概览 = 5002,
|
||||
[Display(Prompt = "统计授课中教师回答类型的次数 回答类型" +
|
||||
"[重复回答,老师追问,简单性表扬,老师补充答案,表扬并补充答案] :结果类型{回答类型:次数}")]
|
||||
"[重复回答,老师追问,简单性表扬,老师补充答案,表扬并补充答案] 结果类型{回答类型:次数}")]
|
||||
提问类型 = 5003,
|
||||
[Display(Prompt = " 分析授课中教师提到 以下类型" +
|
||||
"[独立学习,小组合作,随堂练习]的时间段,精准提取出其中字幕开始秒,结束秒 :结果类型[{Start:开始秒(number),End:结束秒(number),Content:类型(string)}/null]")]
|
||||
"[独立学习,小组合作,随堂练习]的时间段,提取出其中字幕开始秒,结束秒 结果类型[{Start:开始秒,End:结束秒,Content:类型}/null]")]
|
||||
额外课堂情况 = 5004,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@
|
|||
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="org.k2fsa.sherpa.onnx" Version="1.10.32" />
|
||||
<PackageReference Include="org.k2fsa.sherpa.onnx" Version="1.10.30" />
|
||||
<PackageReference Include="SqlSugar.IOC" Version="2.0.0" />
|
||||
<PackageReference Include="SqlSugarCore" Version="5.1.4.170" />
|
||||
<PackageReference Include="UserCenter.Model" Version="1.3.4" />
|
||||
|
|
|
|||
Loading…
Reference in New Issue