接入 bset的Deepseek
This commit is contained in:
parent
a8ac40d6fb
commit
7188f8ab71
|
|
@ -185,6 +185,7 @@ namespace VideoAnalysisCore.AICore.GPT
|
|||
public static void AddGPTService(this IServiceCollection services)
|
||||
{
|
||||
services.AddSingleton<DeepSeekGPTClient>();
|
||||
services.AddSingleton<BSET_DeepSeekGPTClient>();
|
||||
services.AddSingleton<BestAIClient>();
|
||||
services.AddSingleton<GeminiGPTClient>();
|
||||
services.AddSingleton<IBserGPTWorkflow, GTP_Analysis_1>();
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ namespace VideoAnalysisCore.AICore.GPT
|
|||
|
||||
public const string Deepseek_Reasoner = "deepseek-reasoner";
|
||||
public const string Deepseek_Chat = "deepseek-chat";
|
||||
public const string Deepseek_v32 = "deepseek-v3.2";
|
||||
public const string Deepseek_v32_thinking = "deepseek-v3.2-thinking";
|
||||
|
||||
//渠道限制没有并发
|
||||
//public const string Gemini_3_Chat_thinking = "gemini-3-pro-preview-thinking";
|
||||
|
|
|
|||
|
|
@ -0,0 +1,64 @@
|
|||
using VideoAnalysisCore.Common;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Net.Http;
|
||||
using Newtonsoft.Json;
|
||||
using System.Net.Http.Json;
|
||||
using System.Net;
|
||||
using System.Text.Json;
|
||||
|
||||
|
||||
namespace VideoAnalysisCore.AICore.GPT.DeepSeek
|
||||
{
|
||||
|
||||
public class BSET_DeepSeekGPTClient : GPTClient
|
||||
{
|
||||
|
||||
public override GptConfig Config { get; set; } = AppCommon.Config.ChatGpt.ChatGpt;
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
private readonly RedisManager redisManager;
|
||||
|
||||
public BSET_DeepSeekGPTClient(IHttpClientFactory httpClientFactory, RedisManager redisManager, VideoSliceWorkflowManager workflowManager)
|
||||
: base(httpClientFactory, redisManager, workflowManager)
|
||||
{
|
||||
_httpClientFactory = httpClientFactory;
|
||||
this.redisManager = redisManager;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 请求AI
|
||||
/// </summary>
|
||||
/// <typeparam name="T">返回JSON类型</typeparam>
|
||||
/// <param name="task">任务id</param>
|
||||
/// <param name="postMessages">提示词</param>
|
||||
/// <param name="title">任务类型</param>
|
||||
/// <param name="model">GPT版本</param>
|
||||
/// <param name="max_tokens">最大token <para>不设置默认最大值 16000/8000</para></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="Exception"></exception>
|
||||
public override async Task<T> ChatAsync<T>(string task, string postMessages, string title, string model = ChatGPTType.Deepseek_v32, int max_tokens = 8000)
|
||||
{
|
||||
Message[] messageArr = [
|
||||
new Message(postMessages,"user"),
|
||||
];
|
||||
messageArr = messageArr.Where(s => s != null).ToArray();
|
||||
if (max_tokens > 8000 && (model is null || model == ChatGPTType.Deepseek_v32))
|
||||
max_tokens = 8000;
|
||||
var chatReq = new ChatRequest
|
||||
{
|
||||
taskId = task,
|
||||
title = title,
|
||||
model = model ?? ChatGPTType.Deepseek_v32_thinking,
|
||||
max_tokens = model == ChatGPTType.Deepseek_v32_thinking ? 32000 : max_tokens,
|
||||
stream = true,
|
||||
messages = messageArr
|
||||
};
|
||||
chatReq.modalities = null;
|
||||
return await ChatAsync<T>(chatReq);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
using VideoAnalysisCore.Common;
|
||||
using VideoAnalysisCore.Common;
|
||||
using System.Text.Json;
|
||||
using VideoAnalysisCore.Model;
|
||||
using System.Text;
|
||||
|
|
@ -37,6 +37,7 @@ namespace VideoAnalysisCore.AICore.GPT
|
|||
{
|
||||
private readonly GeminiGPTClient geminiClient;
|
||||
private readonly DeepSeekGPTClient deepSeekClient;
|
||||
private readonly BSET_DeepSeekGPTClient bset_deepSeekClient;
|
||||
private readonly BestAIClient chatGPTClient;
|
||||
private readonly Repository<CourseGradingCriteria> criteriaDB;
|
||||
private readonly RedisManager redisManager;
|
||||
|
|
@ -56,7 +57,7 @@ namespace VideoAnalysisCore.AICore.GPT
|
|||
/// <param name="logger"></param>
|
||||
public GTP_Analysis_1(DeepSeekGPTClient moonshotClient, Repository<CourseGradingCriteria> criteria, Repository<VideoTask> videoTaskDB,
|
||||
Repository<KnowledgeInfo> knowledgeInfoDB, Repository<VideoKonwPoint> videoKonwPointDB, SimpLetexClient simpLetexClient,
|
||||
Repository<VideoQuestion> videoQuestionDB, OssClient ossClient, Repository<VideoQuestionKonw> videoQuestionKonwDB, RedisManager redisManager, VideoSliceWorkflowManager workflowManager, BestAIClient chatGPTClient, GeminiGPTClient geminiClient, Repository<VideoTaskStage> videoTaskStageDB)
|
||||
Repository<VideoQuestion> videoQuestionDB, OssClient ossClient, Repository<VideoQuestionKonw> videoQuestionKonwDB, RedisManager redisManager, VideoSliceWorkflowManager workflowManager, BestAIClient chatGPTClient, GeminiGPTClient geminiClient, Repository<VideoTaskStage> videoTaskStageDB, BSET_DeepSeekGPTClient bset_deepSeekClient)
|
||||
{
|
||||
deepSeekClient = moonshotClient;
|
||||
criteriaDB = criteria;
|
||||
|
|
@ -72,6 +73,7 @@ namespace VideoAnalysisCore.AICore.GPT
|
|||
this.chatGPTClient = chatGPTClient;
|
||||
this.geminiClient = geminiClient;
|
||||
this.videoTaskStageDB = videoTaskStageDB;
|
||||
this.bset_deepSeekClient = bset_deepSeekClient;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取分段内容对应的章节知识点
|
||||
|
|
@ -303,6 +305,8 @@ namespace VideoAnalysisCore.AICore.GPT
|
|||
|
||||
Func<string, Task<List<SenseVoiceInput>>>[] chatClentArr =
|
||||
[
|
||||
async (m)=>await bset_deepSeekClient
|
||||
.ChatAsync<List<SenseVoiceInput>>(taskInfo.Id.ToString(), m, "优化字幕",ChatGPTType.Deepseek_v32,8_000),
|
||||
async (m)=>await deepSeekClient
|
||||
.ChatAsync<List<SenseVoiceInput>>(taskInfo.Id.ToString(), m, "优化字幕",ChatGPTType.Deepseek_Chat,8_000),
|
||||
async (m)=>await chatGPTClient
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using SherpaOnnx;
|
||||
using SqlSugar;
|
||||
|
|
|
|||
|
|
@ -131,8 +131,31 @@ namespace VideoAnalysisCore.Common.Expand
|
|||
var fileName = Path.GetFileName(tsFile);
|
||||
var tsObjectKey = ossPrefix + fileName;
|
||||
|
||||
using var fs = File.OpenRead(tsFile);
|
||||
ossClient.PutObject(bucket, tsObjectKey, fs);
|
||||
var tsRetryCount = 0;
|
||||
var tsMaxRetries = 10;
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
using var fs = File.OpenRead(tsFile);
|
||||
ossClient.PutObject(bucket, tsObjectKey, fs);
|
||||
break; // Upload successful, break retry loop
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
tsRetryCount++;
|
||||
if (tsRetryCount >= tsMaxRetries)
|
||||
{
|
||||
await _workflowManager.AddTaskLog(task, $"上传 TS 切片 {fileName} 失败,已重试 {tsMaxRetries} 次: {ex.Message}");
|
||||
throw; // Re-throw exception to stop the process
|
||||
}
|
||||
else
|
||||
{
|
||||
await _workflowManager.AddTaskLog(task, $"上传 TS 切片 {fileName} 失败 (第 {tsRetryCount} 次重试): {ex.Message},1秒后重试...");
|
||||
await Task.Delay(1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 更新上传进度
|
||||
if (i % 5 == 0) // 每5个文件更新一次进度
|
||||
|
|
@ -145,9 +168,33 @@ namespace VideoAnalysisCore.Common.Expand
|
|||
// B. 上传 m3u8 索引文件
|
||||
// 必须使用 VOD 指定的 objectName
|
||||
await _workflowManager.AddTaskLog(task, "开始上传 m3u8 索引文件...");
|
||||
using (var fs = File.OpenRead(m3u8Path))
|
||||
|
||||
var m3u8RetryCount = 0;
|
||||
var m3u8MaxRetries = 3;
|
||||
while (true)
|
||||
{
|
||||
ossClient.PutObject(bucket, objectName, fs);
|
||||
try
|
||||
{
|
||||
using (var fs = File.OpenRead(m3u8Path))
|
||||
{
|
||||
ossClient.PutObject(bucket, objectName, fs);
|
||||
}
|
||||
break; // Upload successful
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
m3u8RetryCount++;
|
||||
if (m3u8RetryCount >= m3u8MaxRetries)
|
||||
{
|
||||
await _workflowManager.AddTaskLog(task, $"上传 m3u8 文件失败,已重试 {m3u8MaxRetries} 次: {ex.Message}");
|
||||
throw;
|
||||
}
|
||||
else
|
||||
{
|
||||
await _workflowManager.AddTaskLog(task, $"上传 m3u8 文件失败 (第 {m3u8RetryCount} 次重试): {ex.Message},1秒后重试...");
|
||||
await Task.Delay(1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await _workflowManager.AddTaskLog(task, "上传成功");
|
||||
|
|
@ -167,6 +214,23 @@ namespace VideoAnalysisCore.Common.Expand
|
|||
catch (Exception ex)
|
||||
{
|
||||
await _workflowManager.AddTaskLog(task, $"上传 VOD OSS 异常: {ex.Message}");
|
||||
|
||||
// 如果已获取 VideoId 但上传失败,则删除 VOD 记录
|
||||
if (!string.IsNullOrEmpty(videoId))
|
||||
{
|
||||
try
|
||||
{
|
||||
await _workflowManager.AddTaskLog(task, $"正在回滚删除 VOD 视频记录 (VideoId: {videoId})...");
|
||||
var deleteRequest = new DeleteVideoRequest { VideoIds = videoId };
|
||||
await _vodClient.DeleteVideoAsync(deleteRequest);
|
||||
await _workflowManager.AddTaskLog(task, "VOD 视频记录删除成功");
|
||||
}
|
||||
catch (Exception deleteEx)
|
||||
{
|
||||
await _workflowManager.AddTaskLog(task, $"回滚删除 VOD 视频记录失败: {deleteEx.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
using FreeRedis;
|
||||
using FreeRedis;
|
||||
using FreeRedis.Internal;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
|
|
|
|||
Loading…
Reference in New Issue