6 changed files with 189 additions and 42 deletions
-
104src/Shentun.Peis.Application/AIMessages/AIMessageAppService.cs
-
12src/Shentun.Peis.Application/BeiJingMZAKExportDatas/Class1.cs
-
9src/Shentun.Peis.Application/InternalReports/InternalReportAppService.cs
-
28src/Shentun.Peis.Application/PeisReports/PeisReportAppService.cs
-
69src/Shentun.Peis.HttpApi.Host/Controllers/AiMessageWsController.cs
-
9src/Shentun.Peis.HttpApi.Host/appsettings.json
@ -1,12 +0,0 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Shentun.Peis.BeiJingMZAKExportDatas |
|||
{ |
|||
internal class Class1 |
|||
{ |
|||
} |
|||
} |
|||
@ -0,0 +1,69 @@ |
|||
using Microsoft.AspNetCore.Http; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using System.Net.WebSockets; |
|||
using System.Text; |
|||
using System.Threading; |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Shentun.Peis.Controllers |
|||
{ |
|||
[Route("api/[controller]")]
|
|||
[ApiController] |
|||
public class AiMessageWsController : ControllerBase |
|||
{ |
|||
|
|||
[HttpGet] |
|||
public IAsyncEnumerable<string> GetData() |
|||
{ |
|||
return GenerateDataAsync(); |
|||
} |
|||
|
|||
private async IAsyncEnumerable<string> GenerateDataAsync() |
|||
{ |
|||
for (int i = 0; i < 100; i++) |
|||
{ |
|||
await Task.Delay(100); // 模拟延迟
|
|||
yield return $"Data {i}"; |
|||
} |
|||
} |
|||
|
|||
//public async Task HandleWebSocket()
|
|||
//{
|
|||
// if (HttpContext.WebSockets.IsWebSocketRequest)
|
|||
// {
|
|||
// using var webSocket = await HttpContext.WebSockets.AcceptWebSocketAsync();
|
|||
// await ProcessDeepSeekStream(webSocket);
|
|||
// }
|
|||
// else
|
|||
// {
|
|||
// HttpContext.Response.StatusCode = StatusCodes.Status400BadRequest;
|
|||
// }
|
|||
//}
|
|||
|
|||
|
|||
|
|||
//private async Task ProcessDeepSeekStream(WebSocket webSocket)
|
|||
//{
|
|||
// // 调用deepseek API
|
|||
// var stream = await GetDeepSeekStream();
|
|||
|
|||
// foreach (var chunk in stream)
|
|||
// {
|
|||
// var buffer = Encoding.UTF8.GetBytes(JsonSerializer.Serialize(chunk));
|
|||
// await webSocket.SendAsync(
|
|||
// new ArraySegment<byte>(buffer),
|
|||
// WebSocketMessageType.Text,
|
|||
// true,
|
|||
// CancellationToken.None);
|
|||
// }
|
|||
|
|||
// await webSocket.CloseAsync(
|
|||
// WebSocketCloseStatus.NormalClosure,
|
|||
// "Stream completed",
|
|||
// CancellationToken.None);
|
|||
//}
|
|||
|
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue