last ...
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
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
|
||||
{
|
||||
/// <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="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public Task<ChatResponse> GetResponseAsync(
|
||||
string prompt,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generated Response ...
|
||||
/// </summary>
|
||||
/// <param name="prompt"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<string> 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<string, string>
|
||||
{
|
||||
{ XAiApiQueryParams.Prompt, prompt }
|
||||
}
|
||||
);
|
||||
|
||||
//
|
||||
var response = await RunRestRequest<string>(
|
||||
client,
|
||||
request,
|
||||
XHttpMethod.GET,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
return response;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user