This commit is contained in:
2026-04-10 23:51:44 +03:30
parent e4ddceafa0
commit 81ea808377
3 changed files with 28 additions and 20 deletions
+1 -1
View File
@@ -7,8 +7,8 @@ using xCommons.Extensions;
using xExceptions.Constants;
using xAiApi.AI.Configuration;
using System.Collections.Generic;
using Microsoft.SemanticKernel.ChatCompletion;
using System.Threading;
using Microsoft.SemanticKernel.ChatCompletion;
namespace xAiApi.AI.Services
{
+26 -5
View File
@@ -1,6 +1,8 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using xAiApi.AI.Interfaces;
@@ -37,7 +39,8 @@ namespace xAiApi.Controllers.V1
[AllowAnonymous]
[HttpGet("AskAI")]
public async Task<ActionResult<string>> AskAI(
[FromQuery] string prompt
[FromQuery] string prompt,
CancellationToken cancellationToken = default
)
{
//
@@ -46,7 +49,10 @@ namespace xAiApi.Controllers.V1
{
//
var result = await aiService
.GetTextResponseAsync(prompt);
.GetTextResponseAsync(
prompt: prompt,
cancellationToken: cancellationToken
);
//
return Ok(result);
@@ -62,7 +68,8 @@ namespace xAiApi.Controllers.V1
[AllowAnonymous]
[HttpGet("AskAIStream")]
public async Task AskAIStream(
[FromQuery] string prompt
[FromQuery] string prompt,
CancellationToken cancellationToken = default
)
{
//
@@ -70,8 +77,17 @@ namespace xAiApi.Controllers.V1
try
{
//
// Adding Content Type ...
Response.Headers
.Append("Content-Type", "text/event-stream");
//
// Retrieving Stream ...
var stream = aiService
.GetTextReponseStreamAsync(prompt);
.GetTextReponseStreamAsync(
prompt: prompt,
cancellationToken: cancellationToken
);
await foreach (var message in stream)
{
//
@@ -79,11 +95,16 @@ namespace xAiApi.Controllers.V1
//
var msgBytes = message.Text.ToBytes();
await Response.Body.WriteAsync(msgBytes, 0, msgBytes.Length);
await Response.Body.WriteAsync(
msgBytes,
0,
msgBytes.Length
);
await Response.Body.FlushAsync();
}
//
// Closing Connection ...
await Response.Body.FlushAsync();
}
catch
+1 -14
View File
@@ -2,20 +2,7 @@
<configuration>
<packageSources>
<add key="megan" value="https://hub.megan.ir/nuget/index.json" />
<add key="nuget" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="baget" value="https://nuget.saherelmhub.ir/v3/index.json" protocolVersion="3" />
<!-- <add key="NugetIran" value="https://repo.nugetiran.ir/repository/nuget-group/" /> -->
<!-- <add key="nuget" value="https://api.nuget.org/v3/index.json" protocolVersion="3" /> -->
<!-- <add key="RunFlare" value="https://mirror-nuget.runflare.com/v3/index.json" protocolVersion="3" /> -->
<!-- <add key="jfrog" value="https://jfrog.rpk.ir/artifactory/api/nuget/v3/nuget-rpk-virtual" disableTLSCertificateValidation="true" /> -->
</packageSources>
<packageSourceCredentials>
<!-- Credentials for other repositories (if needed) -->
<!-- <jfrog>
<add key="Username" value="admin" />
<add key="ClearTextPassword" value="Aliz@123" />
</jfrog> -->
</packageSourceCredentials>
<!-- <config>
<add key="signatureValidationMode" value="accept" />
</config> -->
</configuration>