using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.AI;
using Microsoft.Extensions.Logging;
using xAiService.Base;
using xAiService.Configurations;
using xAiService.Constants;
using xAiService.Interfaces;
using xCommons.Providers;
using xHttpService.Constants;
using xIdentityService.Interfaces;
namespace xAiService.Services
{
public class XAiService : XBaseIdentityHttpProvider, IXAiService
{
///
/// XAiService Configurations ...
///
///
public XAIServiceConfiguration Configuration { get; }
public XAiService(
ILogger logger,
IXTokenProvider tokenProvider,
IXIdentityProvider identityProvider,
XAIServiceConfiguration configuration,
XValidationProvider validationProvider
) : base(
configuration.Url,
logger,
configuration.XPoweredValue,
configuration.DefaultClientTimeout,
tokenProvider,
identityProvider,
validationProvider
)
{ }
//
#region Text Actions ...
///
/// Generated Response ...
///
///
///
///
public Task GetResponseAsync(
string prompt,
CancellationToken cancellationToken = default
)
{
throw new System.NotImplementedException();
}
///
/// Generated Response ...
///
///
///
///
public async Task GetTextResponseAsync(
string prompt,
CancellationToken cancellationToken = default
)
{
//
// Validate Args ...
ValidationProvider.NotEmpty(prompt);
//
var client = GetRestClient();
var request = GetRestRequet(
endpoint: XAiApiEndpoint.Ask,
addXPoweredValue: true,
queryStrings: new Dictionary
{
{ XAiApiQueryParams.Prompt, prompt }
}
);
//
var response = await RunRestRequest(
client,
request,
XHttpMethod.GET,
cancellationToken: cancellationToken
);
//
return response;
}
#endregion
}
}