|
|
@@ -1,3 +1,5 @@
|
|
|
+using Microsoft.AspNetCore.Mvc;
|
|
|
+using OASystem.API.OAMethodLib.DeepSeekAPI;
|
|
|
using Flurl.Http.Configuration;
|
|
|
using Microsoft.Extensions.Options;
|
|
|
using OASystem.API.OAMethodLib.DoubaoAPI;
|
|
|
@@ -30,16 +32,19 @@ namespace OASystem.API.Controllers
|
|
|
private readonly IMicrosoftGraphMailboxService _microsoftGraphMailboxService;
|
|
|
private readonly IOptionsMonitor<MicrosoftGraphMailboxOptions> _microsoftGraphMailboxOptions;
|
|
|
|
|
|
+ private readonly IDeepSeekService _deepSeekService;
|
|
|
+
|
|
|
public AITestController(
|
|
|
- IHunyuanService hunyuanService,
|
|
|
- IDoubaoService doubaoService,
|
|
|
- ILogger<AITestController> logger,
|
|
|
- IQiYeWeChatApiService qiYeWeChatApiService,
|
|
|
- HotmailService hotmailService,
|
|
|
- System.Net.Http.IHttpClientFactory httpClientFactory,
|
|
|
+ IHunyuanService hunyuanService,
|
|
|
+ IDoubaoService doubaoService,
|
|
|
+ ILogger<AITestController> logger,
|
|
|
+ IQiYeWeChatApiService qiYeWeChatApiService,
|
|
|
+ HotmailService hotmailService,
|
|
|
+ System.Net.Http.IHttpClientFactory httpClientFactory,
|
|
|
IConfiguration config,
|
|
|
IMicrosoftGraphMailboxService microsoftGraphMailboxService,
|
|
|
- IOptionsMonitor<MicrosoftGraphMailboxOptions> microsoftGraphMailboxOptions
|
|
|
+ IOptionsMonitor<MicrosoftGraphMailboxOptions> microsoftGraphMailboxOptions,
|
|
|
+ IDeepSeekService deepSeekService
|
|
|
)
|
|
|
{
|
|
|
_hunyuanService = hunyuanService;
|
|
|
@@ -50,6 +55,7 @@ namespace OASystem.API.Controllers
|
|
|
_httpClientFactory = httpClientFactory;
|
|
|
_config = config;
|
|
|
_microsoftGraphMailboxService = microsoftGraphMailboxService;
|
|
|
+ _deepSeekService = deepSeekService;
|
|
|
_microsoftGraphMailboxOptions = microsoftGraphMailboxOptions;
|
|
|
}
|
|
|
|
|
|
@@ -346,6 +352,71 @@ namespace OASystem.API.Controllers
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
+ #region DeepSeek 测试
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// DeepSeek 带上下文的流式对话测试。响应为 NDJSON:每行一条 JSON,phase 为 reasoning、content 或 error。
|
|
|
+ /// </summary>
|
|
|
+ [HttpPost("deepseek-chat-stream-with-history")]
|
|
|
+ public async Task<IActionResult> DeepSeekChatStreamWithHistory(
|
|
|
+ [FromBody] DeepSeekChatStreamHistoryTestRequest request,
|
|
|
+ CancellationToken cancellationToken = default)
|
|
|
+ {
|
|
|
+ if (request?.Messages == null || request.Messages.Count == 0)
|
|
|
+ return BadRequest(new { message = "Messages 不能为空,且至少包含一条 user/system/assistant 消息。" });
|
|
|
+
|
|
|
+ Response.ContentType = "application/x-ndjson; charset=utf-8";
|
|
|
+ Response.Headers["Cache-Control"] = "no-cache";
|
|
|
+
|
|
|
+ static string NdjsonLine(DeepSeekStreamChunk c) => JsonConvert.SerializeObject(new
|
|
|
+ {
|
|
|
+ phase = c.Phase == DeepSeekStreamPhase.Reasoning ? "reasoning" : "content",
|
|
|
+ text = c.Text
|
|
|
+ });
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ await foreach (var chunk in _deepSeekService.ChatStreamWithHistoryAsync(
|
|
|
+ request.Messages,
|
|
|
+ string.IsNullOrWhiteSpace(request.Model) ? "deepseek-chat" : request.Model!.Trim(),
|
|
|
+ request.Temperature,
|
|
|
+ request.MaxTokens))
|
|
|
+ {
|
|
|
+ cancellationToken.ThrowIfCancellationRequested();
|
|
|
+ await Response.WriteAsync(NdjsonLine(chunk) + "\n", cancellationToken);
|
|
|
+ await Response.Body.FlushAsync(cancellationToken);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (OperationCanceledException)
|
|
|
+ {
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ _logger.LogError(ex, "DeepSeek 带历史流式对话失败");
|
|
|
+ await Response.WriteAsync(
|
|
|
+ JsonConvert.SerializeObject(new { phase = "error", text = ex.Message }) + "\n",
|
|
|
+ cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ return new EmptyResult();
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// DeepSeek 流式对话(含多轮)请求体
|
|
|
+ /// </summary>
|
|
|
+ public class DeepSeekChatStreamHistoryTestRequest
|
|
|
+ {
|
|
|
+ public List<DeepSeekHistoryMessage> Messages { get; set; } = new();
|
|
|
+
|
|
|
+ public string? Model { get; set; } = "deepseek-chat";
|
|
|
+
|
|
|
+ public float Temperature { get; set; } = 0.7f;
|
|
|
+
|
|
|
+ public int MaxTokens { get; set; } = 4000;
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// hotmail 发送邮件
|
|
|
/// </summary>
|
|
|
@@ -356,11 +427,12 @@ namespace OASystem.API.Controllers
|
|
|
//"Roy.Lei.Atom@hotmail.com",
|
|
|
"925554512@qq.com",
|
|
|
//"johnny.yang@pan-american-intl.com",
|
|
|
- new HotmailService.MailDto() {
|
|
|
- Subject = "系统提醒",
|
|
|
- Content = "<p>这是一封Homail 发送的测试邮件</p>",
|
|
|
- //To = "Roy.lei@pan-american-intl.com"
|
|
|
- To = "johnny.yang@pan-american-intl.com"
|
|
|
+ new HotmailService.MailDto()
|
|
|
+ {
|
|
|
+ Subject = "系统提醒",
|
|
|
+ Content = "<p>这是一封Homail 发送的测试邮件</p>",
|
|
|
+ //To = "Roy.lei@pan-american-intl.com"
|
|
|
+ To = "johnny.yang@pan-american-intl.com"
|
|
|
});
|
|
|
|
|
|
return StatusCode(200, new { Message = "操作成功。" });
|
|
|
@@ -382,11 +454,11 @@ namespace OASystem.API.Controllers
|
|
|
var yesterdayEnd = yesterdayStart.AddDays(1).AddTicks(-1); // 昨天的 23:59:59
|
|
|
|
|
|
|
|
|
- var res = await _hotmailService.GetMergedMessagesAsync(
|
|
|
- new List<string>() { "925554512@qq.com" },
|
|
|
- yesterdayStart,
|
|
|
- yesterdayEnd
|
|
|
- );
|
|
|
+ var res = await _hotmailService.GetMergedMessagesAsync(
|
|
|
+ new List<string>() { "925554512@qq.com" },
|
|
|
+ yesterdayStart,
|
|
|
+ yesterdayEnd
|
|
|
+ );
|
|
|
|
|
|
return StatusCode(200, res);
|
|
|
}
|
|
|
@@ -519,8 +591,6 @@ namespace OASystem.API.Controllers
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
public class EmailAuthRedisCache
|
|
|
{
|
|
|
public string? AccessToken { get; set; }
|
|
|
@@ -529,7 +599,6 @@ namespace OASystem.API.Controllers
|
|
|
public string? ClientId { get; set; }
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/// <summary>
|
|
|
/// 从 Redis 读取 MSAL 缓存与 HomeAccountId,静默刷新 Graph access_token。
|
|
|
/// </summary>
|