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 { /// /// 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, XUserClaimsInfoDto userInfo, CancellationToken cancellationToken = default ) { throw new System.NotImplementedException(); } /// /// Generated Response ... /// /// /// /// /// public async Task 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 { { XAiApiQueryParams.Prompt, prompt } } ); // var response = await RunRestRequest( client, request, XHttpMethod.GET, cancellationToken: cancellationToken ); // return response; } /// /// Generate Text Response Stream ... /// /// /// /// /// public async Task 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 { { XAiApiQueryParams.Prompt, prompt } } ); // return result; } #endregion } }