Cleanup xAiService for Reconstruction ...
This commit is contained in:
@@ -1,143 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.AI;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using xAiService.Configurations;
|
||||
using xAiService.Constants;
|
||||
using xAiService.Interfaces;
|
||||
using xCommons.Providers;
|
||||
using xHttpService.Constants;
|
||||
using xIdentityModels.Models;
|
||||
using xIdentityService.Interfaces;
|
||||
using xIdentityService.Providers;
|
||||
|
||||
namespace xAiService.Services
|
||||
{
|
||||
public class XAiService : XBaseIdentityHttpProvider, IXAiService
|
||||
{
|
||||
/// <summary>
|
||||
/// XAiService Configurations ...
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public XAIServiceConfiguration Configuration { get; }
|
||||
|
||||
public XAiService(
|
||||
ILogger<XAiService> logger,
|
||||
IXTokenProvider tokenProvider,
|
||||
IXIdentityProvider identityProvider,
|
||||
XAIServiceConfiguration configuration,
|
||||
XValidationProvider validationProvider
|
||||
) : base(
|
||||
configuration.Url,
|
||||
logger,
|
||||
configuration.XPoweredValue,
|
||||
configuration.DefaultClientTimeout,
|
||||
tokenProvider,
|
||||
identityProvider,
|
||||
validationProvider
|
||||
)
|
||||
{ }
|
||||
|
||||
//
|
||||
#region Text Actions ...
|
||||
/// <summary>
|
||||
/// Generated Response ...
|
||||
/// </summary>
|
||||
/// <param name="prompt"></param>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public Task<ChatResponse> GetResponseAsync(
|
||||
string prompt,
|
||||
XUserClaimsInfoDto userInfo,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generated Response ...
|
||||
/// </summary>
|
||||
/// <param name="prompt"></param>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<string> GetTextResponseAsync(
|
||||
string prompt,
|
||||
XUserClaimsInfoDto userInfo,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
ValidationProvider.NotEmpty(prompt);
|
||||
|
||||
//
|
||||
var client = GetRestClient(userInfo);
|
||||
var request = GetRestRequet(
|
||||
endpoint: XAiApiEndpoint.Ask,
|
||||
addXPoweredValue: true,
|
||||
queryStrings: new Dictionary<string, string>
|
||||
{
|
||||
{ XAiApiQueryParams.Prompt, prompt }
|
||||
}
|
||||
);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<string>(
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.GET,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generate Text Response Stream ...
|
||||
/// </summary>
|
||||
/// <param name="prompt"></param>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<Stream> GetTextReponseStreamAsync(
|
||||
string prompt,
|
||||
XUserClaimsInfoDto userInfo,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate Args ...
|
||||
ValidationProvider
|
||||
.GroupValidationBuilder()
|
||||
.AddNotEmpty(prompt)
|
||||
.AddNotNull(userInfo)
|
||||
.AddNotZero(userInfo.ExpiresAt)
|
||||
.AddNotEmpty(userInfo.AccessToken)
|
||||
.AddNotEmpty(userInfo.RefreshToken)
|
||||
.ValidateGroup();
|
||||
|
||||
//
|
||||
var tokens = ToTokenResponse(userInfo);
|
||||
var result = await StreamData(
|
||||
tokens: tokens,
|
||||
addXPoweredValue: true,
|
||||
endpoint: XAiApiEndpoint.Stream,
|
||||
cancellationToken: cancellationToken,
|
||||
queryStrings: new Dictionary<string, string>
|
||||
{
|
||||
{ XAiApiQueryParams.Prompt, prompt }
|
||||
}
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user