diff --git a/Providers/XAIServiceBase.cs b/Providers/XAIServiceBase.cs
index a1f7cfc..49b11ea 100644
--- a/Providers/XAIServiceBase.cs
+++ b/Providers/XAIServiceBase.cs
@@ -1,5 +1,4 @@
using System;
-using System.Linq;
using System.Threading;
using xAiApi.Interfaces;
using xCommons.Extensions;
@@ -10,9 +9,11 @@ using System.Collections.Generic;
using Microsoft.Extensions.Logging;
using System.Runtime.CompilerServices;
using Microsoft.Extensions.AI;
-using xAiApi.Models;
+using xAiModels.Extensions;
using xAiApi.Configurations;
using xAiApi.Extensions;
+using System.Net.Http;
+using OllamaSharp;
namespace xAiApi.Providers
{
@@ -148,10 +149,6 @@ namespace xAiApi.Providers
XException.NotFound.Throw();
}
- //
- bool isOllamaBased = modelDescriptor.Provider == Constants.XAiProvider.Ollama;
- bool isDeepSeekBased = modelDescriptor.Provider == Constants.XAiProvider.DeepSeek;
-
//
// Try to Initialize LLm ...
var model = modelDescriptor.LLM;
@@ -161,36 +158,62 @@ namespace xAiApi.Providers
//
IChatClient result = null;
- if (isOllamaBased)
+ switch (modelDescriptor.Provider)
{
//
- // Instance Ollama Client using Custom HttpCLient ...
- var ollamaClient = new OllamaApiClient(httpClient, model);
- result =
- new ChatClientBuilder(ollamaClient)
- .Build();
- }
- else if (isDeepSeekBased)
- {
- //
- if (apiKey is null ||
- string.IsNullOrWhiteSpace(apiKey))
- {
- throw new Exception("Inavlid Args ...");
- }
+ case Constants.XAiProvider.Ollama:
+ //
+ // Instance Ollama Client using Custom HttpCLient ...
+ var ollamaClient = new OllamaApiClient(httpClient, model);
+ result =
+ new ChatClientBuilder(ollamaClient)
+ .Build();
+ break;
//
- var deepseekClient = new DeepSeekChatClient(apiKey: apiKey);
- result = deepseekClient;
- }
- else
- {
+ case Constants.XAiProvider.DeepSeek:
+ break;
+
//
- // TODO: Implement this ...
+ case Constants.XAiProvider.HuggingFace:
+ break;
+
+ //
+ default:
+ break;
+ }
+
+ // //
+ // if (isOllamaBased)
+ // {
+ // }
+ // else if (isDeepSeekBased)
+ // {
+ // //
+ // if (apiKey is null ||
+ // string.IsNullOrWhiteSpace(apiKey))
+ // {
+ // throw new Exception("Inavlid Args ...");
+ // }
+
+ // //
+ // var deepseekClient = new DeepSeekChatClient(apiKey: apiKey);
+ // result = deepseekClient;
+ // }
+ // else
+ // {
+ // //
+ // // TODO: Implement this ...
+ // }
+
+ //
+ if (result.IsNullOrDefault())
+ {
+ XException.InvalidData.Throw();
}
//
- return result ?? throw new NotSupportedException("Chat Client not found ...");
+ return result;
}
///
@@ -198,7 +221,7 @@ namespace xAiApi.Providers
///
///
///
- public virtual HttpClient GetHttpClient(string? url = null)
+ public virtual HttpClient GetHttpClient(string url = null)
{
//
var result = new HttpClient
@@ -208,9 +231,9 @@ namespace xAiApi.Providers
Timeout = Timeout.InfiniteTimeSpan,
//
- BaseAddress = url is null
+ BaseAddress = url.IsNullOrEmpty()
? null
- : new Uri(url!),
+ : new Uri(url),
//
// OR set a very long timeout (e.g., 30 minutes for large file uploads)
@@ -228,10 +251,17 @@ namespace xAiApi.Providers
///
///
public virtual IList GetHistory(
- string? prompt = null,
+ string prompt = null,
bool forcePrompt = true
)
{
+ //
+ // Validate Args ...
+ if (prompt.IsNullOrEmpty())
+ {
+ XException.InvalidArgs.Throw();
+ }
+
//
// User Prompt ...
var promptMessage = new ChatMessage(
@@ -269,7 +299,7 @@ namespace xAiApi.Providers
///
///
public virtual IList GetHistory(
- ChatMessage? message = null,
+ ChatMessage message = null,
bool forceMessage = true
)
{