last ...
This commit is contained in:
@@ -6,6 +6,7 @@ using Microsoft.Extensions.Logging;
|
||||
using xAiApi.AI.Interfaces;
|
||||
using xAiApi.Base;
|
||||
using xCommons.Configurations;
|
||||
using xCommons.Extensions;
|
||||
using xCommons.Providers;
|
||||
using xIdentityService.Interfaces;
|
||||
|
||||
@@ -57,6 +58,37 @@ namespace xAiApi.Controllers.V1
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
[HttpGet("AskAIStream")]
|
||||
public async Task AskAIStream(
|
||||
[FromQuery] string prompt
|
||||
)
|
||||
{
|
||||
//
|
||||
// Do ...
|
||||
try
|
||||
{
|
||||
//
|
||||
var stream = aiService
|
||||
.GetTextReponseStreamAsync(prompt);
|
||||
await foreach (var message in stream)
|
||||
{
|
||||
//
|
||||
// Do What we Have to Do with Message ...
|
||||
|
||||
//
|
||||
var msgBytes = message.Text.ToBytes();
|
||||
await Response.Body.WriteAsync(msgBytes, 0, msgBytes.Length);
|
||||
await Response.Body.FlushAsync();
|
||||
}
|
||||
|
||||
//
|
||||
await Response.Body.FlushAsync();
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user