last ...
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
using xAiApi.Models;
|
using xAiModels.Models;
|
||||||
|
|
||||||
namespace xAiApi.Configurations
|
namespace xAiApi.Configurations
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,5 +14,8 @@ namespace xAiApi.Constants
|
|||||||
//
|
//
|
||||||
public const string XAiEmbeddingModelName = "Embed";
|
public const string XAiEmbeddingModelName = "Embed";
|
||||||
public const string XAiEmbeddingPromptName = "Embedding";
|
public const string XAiEmbeddingPromptName = "Embedding";
|
||||||
|
|
||||||
|
//
|
||||||
|
public const string XOpenAINoKey = "no-key-required";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
namespace xAiApi.Constants
|
|
||||||
{
|
|
||||||
public enum XAiProvider
|
|
||||||
{
|
|
||||||
None,
|
|
||||||
Ollama,
|
|
||||||
DeepSeek,
|
|
||||||
HuggingFace
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
using System;
|
using System;
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using xAiApi.Configurations;
|
|
||||||
using xAiApi.Constants;
|
using xAiApi.Constants;
|
||||||
using xAiApi.Extensions;
|
using xAiApi.Extensions;
|
||||||
using xCommons.Extensions;
|
using xCommons.Extensions;
|
||||||
|
using xAiApi.Configurations;
|
||||||
using xExceptions.Constants;
|
using xExceptions.Constants;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
namespace xAiApi.DI
|
namespace xAiApi.DI
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,34 +1,15 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using xAiApi.Configurations;
|
|
||||||
using xAiApi.Constants;
|
using xAiApi.Constants;
|
||||||
using xAiApi.Models;
|
using xAiModels.Models;
|
||||||
using xCommons.Extensions;
|
using xCommons.Extensions;
|
||||||
|
using xAiModels.Extensions;
|
||||||
|
using xAiApi.Configurations;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace xAiApi.Extensions
|
namespace xAiApi.Extensions
|
||||||
{
|
{
|
||||||
public static class XModelsExtensions
|
public static class XModelsExtensions
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Validate a Model Descriptor ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="source"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static bool IsValid(this XAiModelDescriptor source)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var result =
|
|
||||||
!source.IsNullOrDefault() &&
|
|
||||||
!source.Name.IsNullOrEmpty() &&
|
|
||||||
!source.Url.IsNullOrEmpty() &&
|
|
||||||
source.Url.IsValidUrl() &&
|
|
||||||
!source.LLM.IsNullOrEmpty() &&
|
|
||||||
source.Provider != Constants.XAiProvider.None;
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Validate Configurations ...
|
/// Validate Configurations ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -51,52 +32,6 @@ namespace xAiApi.Extensions
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Validate Specified Param ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="source"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static bool IsValid(this XAiPromptParam source)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var result =
|
|
||||||
!source.IsNullOrDefault() &&
|
|
||||||
!source.Name.IsNullOrEmpty() &&
|
|
||||||
!source.Param.IsNullOrEmpty();
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Validate Specified Prompt ...
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="source"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static bool IsValid(this XAiPromptDescriptor source)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var result =
|
|
||||||
!source.IsNullOrDefault() &&
|
|
||||||
!source.Name.IsNullOrEmpty() &&
|
|
||||||
!source.Template.IsNullOrEmpty();
|
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
if (source.Params.HasChild())
|
|
||||||
{
|
|
||||||
result =
|
|
||||||
result &&
|
|
||||||
source.Params.All(x => x.IsValid());
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Extract Default Model Descriptor ...
|
/// Extract Default Model Descriptor ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1,35 +0,0 @@
|
|||||||
using xAiApi.Constants;
|
|
||||||
|
|
||||||
namespace xAiApi.Models
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Describe an Ai Model ...
|
|
||||||
/// </summary>
|
|
||||||
public class XAiModelDescriptor
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Provider Name ...
|
|
||||||
/// </summary>
|
|
||||||
public string Name { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// LLM Provider Url ...
|
|
||||||
/// </summary>
|
|
||||||
public string Url { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Model Name ...
|
|
||||||
/// </summary>
|
|
||||||
public string LLM { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Api Key for Connection ...
|
|
||||||
/// </summary>
|
|
||||||
public string ApiKey { get; set; } = null;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Model Provider ...
|
|
||||||
/// </summary>
|
|
||||||
public XAiProvider Provider { get; set; } = XAiProvider.Ollama;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
namespace xAiApi.Models
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Describe Specified Prompt ...
|
|
||||||
/// </summary>
|
|
||||||
public class XAiPromptDescriptor
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Prompt Name ...
|
|
||||||
/// </summary>
|
|
||||||
public string Name { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Prompt Template ...
|
|
||||||
/// </summary>
|
|
||||||
public string Template { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Prompt Description ...
|
|
||||||
/// </summary>
|
|
||||||
public string Description { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Prompt Template Params ...
|
|
||||||
/// </summary>
|
|
||||||
public XAiPromptParam[] Params { get; set; } = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Specified a Prompt Param ...
|
|
||||||
/// </summary>
|
|
||||||
public class XAiPromptParam
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Param Name ...
|
|
||||||
/// </summary>
|
|
||||||
public string Name { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Param Identifier ...
|
|
||||||
/// </summary>
|
|
||||||
public string Param { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Parma Description ...
|
|
||||||
/// </summary>
|
|
||||||
public string Description { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+36
-13
@@ -1,19 +1,24 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using OpenAI;
|
||||||
|
using OllamaSharp;
|
||||||
|
using System.Net.Http;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using xAiApi.Constants;
|
||||||
using xAiApi.Interfaces;
|
using xAiApi.Interfaces;
|
||||||
|
using xAiApi.Extensions;
|
||||||
|
using System.ClientModel;
|
||||||
using xCommons.Extensions;
|
using xCommons.Extensions;
|
||||||
|
using xAiModels.Constants;
|
||||||
using xAiModels.Interfaces;
|
using xAiModels.Interfaces;
|
||||||
using xExceptions.Constants;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using Microsoft.Extensions.AI;
|
|
||||||
using xAiModels.Extensions;
|
using xAiModels.Extensions;
|
||||||
using xAiApi.Configurations;
|
using xAiApi.Configurations;
|
||||||
using xAiApi.Extensions;
|
using xExceptions.Constants;
|
||||||
using System.Net.Http;
|
using System.Threading.Tasks;
|
||||||
using OllamaSharp;
|
using Microsoft.Extensions.AI;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System.ClientModel.Primitives;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
namespace xAiApi.Providers
|
namespace xAiApi.Providers
|
||||||
{
|
{
|
||||||
@@ -161,7 +166,7 @@ namespace xAiApi.Providers
|
|||||||
switch (modelDescriptor.Provider)
|
switch (modelDescriptor.Provider)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
case Constants.XAiProvider.Ollama:
|
case XAiModelProviderType.Ollama:
|
||||||
//
|
//
|
||||||
// Instance Ollama Client using Custom HttpCLient ...
|
// Instance Ollama Client using Custom HttpCLient ...
|
||||||
var ollamaClient = new OllamaApiClient(httpClient, model);
|
var ollamaClient = new OllamaApiClient(httpClient, model);
|
||||||
@@ -169,13 +174,31 @@ namespace xAiApi.Providers
|
|||||||
new ChatClientBuilder(ollamaClient)
|
new ChatClientBuilder(ollamaClient)
|
||||||
.Build();
|
.Build();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
//
|
//
|
||||||
case Constants.XAiProvider.DeepSeek:
|
case XAiModelProviderType.OpenAI:
|
||||||
|
//
|
||||||
|
// Instance Ollama Client using Custom HttpCLient ...
|
||||||
|
var llamaClient = new OpenAIClient(
|
||||||
|
new ApiKeyCredential(apiKey.IsNullOrEmpty() ? XAiApiConstants.XOpenAINoKey : apiKey),
|
||||||
|
new OpenAIClientOptions
|
||||||
|
{
|
||||||
|
Endpoint = url,
|
||||||
|
Transport = new HttpClientPipelineTransport(httpClient)
|
||||||
|
}
|
||||||
|
);
|
||||||
|
result =
|
||||||
|
llamaClient
|
||||||
|
.GetChatClient(model)
|
||||||
|
.AsIChatClient();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
//
|
//
|
||||||
case Constants.XAiProvider.HuggingFace:
|
case XAiModelProviderType.DeepSeek:
|
||||||
|
break;
|
||||||
|
|
||||||
|
//
|
||||||
|
case XAiModelProviderType.HuggingFace:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -1,20 +1,21 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using OllamaSharp;
|
using OllamaSharp;
|
||||||
using OllamaSharp.Models;
|
using System.Threading;
|
||||||
using xAiApi.Configurations;
|
|
||||||
using xAiApi.Constants;
|
using xAiApi.Constants;
|
||||||
|
using xAiModels.Models;
|
||||||
using xAiApi.Extensions;
|
using xAiApi.Extensions;
|
||||||
using xAiApi.Interfaces;
|
using xAiApi.Interfaces;
|
||||||
using xAiApi.Models;
|
using OllamaSharp.Models;
|
||||||
using xAiModels.Interfaces;
|
|
||||||
using xAiService.Helpers;
|
using xAiService.Helpers;
|
||||||
using xCommons.Extensions;
|
using xCommons.Extensions;
|
||||||
|
using xAiModels.Extensions;
|
||||||
|
using xAiModels.Interfaces;
|
||||||
|
using xAiApi.Configurations;
|
||||||
using xExceptions.Constants;
|
using xExceptions.Constants;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace xAiApi.Providers
|
namespace xAiApi.Providers
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -41,15 +41,15 @@
|
|||||||
"ApiKey": "",
|
"ApiKey": "",
|
||||||
"Name": "Gemma",
|
"Name": "Gemma",
|
||||||
"LLM": "gemma3:1b",
|
"LLM": "gemma3:1b",
|
||||||
"Provider": "Ollama",
|
"Provider": "OpenAI",
|
||||||
"Url": "http://localhost:11434"
|
"Url": "http://178.131.88.93:1112"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ApiKey": "",
|
"ApiKey": "",
|
||||||
"Name": "Embed",
|
"Name": "Embed",
|
||||||
"LLM": "bge-m3",
|
"LLM": "bge-m3",
|
||||||
"Provider": "Ollama",
|
"Provider": "OpenAI",
|
||||||
"Url": "http://localhost:11434"
|
"Url": "http://178.131.88.93:1113"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"Prompts": [
|
"Prompts": [
|
||||||
|
|||||||
Reference in New Issue
Block a user