using System;
using System.Threading.Tasks;
using Microsoft.Extensions.AI;
using OllamaSharp;
using xAiApi.AI.Interfaces;
using xCommons.Extensions;
using xExceptions.Constants;
namespace xAiApi.AI.Services
{
public class XAIService : IXAIService
{
//
public IChatClient TextGenreatorClient { get; }
public IChatClient ImageGenreatorClient { get; }
public XAIService()
{
//
// here we are Initialize Text Generator Model ...
TextGenreatorClient = new OllamaApiClient(
new Uri("http://localhost:11434"),
"gemma3:1b"
);
}
//
#region Actions ...
///
/// Generated Response ...
///
///
///
public async Task GetResponseAsync(string prompt)
{
//
// Validate ...
var isValid = !prompt.IsNullOrEmpty();
if (!isValid)
{
XException.InvalidArgs.Throw();
}
//
// Generate Response ...
var result = await TextGenreatorClient
.GetResponseAsync(prompt);
//
return result;
}
///
/// Generated Text ...
///
///
///
public async Task GetTextResponseAsync(string prompt)
{
//
var response = await GetResponseAsync(prompt);
return response.Text;
}
#endregion
}
}