This commit is contained in:
2026-08-14 23:03:14 +03:30
parent aaa1ae2a2b
commit 6723454690
+59 -29
View File
@@ -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)
{
//
case Constants.XAiProvider.Ollama:
//
// Instance Ollama Client using Custom HttpCLient ...
var ollamaClient = new OllamaApiClient(httpClient, model);
result =
new ChatClientBuilder(ollamaClient)
.Build();
}
else if (isDeepSeekBased)
{
break;
//
if (apiKey is null ||
string.IsNullOrWhiteSpace(apiKey))
case Constants.XAiProvider.DeepSeek:
break;
//
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())
{
throw new Exception("Inavlid Args ...");
XException.InvalidData.Throw();
}
//
var deepseekClient = new DeepSeekChatClient(apiKey: apiKey);
result = deepseekClient;
}
else
{
//
// TODO: Implement this ...
}
//
return result ?? throw new NotSupportedException("Chat Client not found ...");
return result;
}
/// <summary>
@@ -198,7 +221,7 @@ namespace xAiApi.Providers
/// </summary>
/// <param name="url"></param>
/// <returns></returns>
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
/// <param name="forcePrompt"></param>
/// <returns></returns>
public virtual IList<ChatMessage> 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
/// <param name="forceMessage"></param>
/// <returns></returns>
public virtual IList<ChatMessage> GetHistory(
ChatMessage? message = null,
ChatMessage message = null,
bool forceMessage = true
)
{