last ...
This commit is contained in:
+32
-17
@@ -4,6 +4,7 @@ using OllamaSharp;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using xAiApi.Constants;
|
||||
using xAiModels.Models;
|
||||
using xAiApi.Interfaces;
|
||||
using xAiApi.Extensions;
|
||||
using System.ClientModel;
|
||||
@@ -24,6 +25,16 @@ namespace xAiApi.Providers
|
||||
{
|
||||
public abstract class XAIServiceBase : IXAiServiceBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Chat Options ...
|
||||
/// </summary>
|
||||
public ChatOptions Options { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Descriptor of Models which used in Service ...
|
||||
/// </summary>
|
||||
public XAiModelDescriptor Descriptor { get; }
|
||||
|
||||
private readonly IXAiDataProvider dataProvider;
|
||||
private readonly ILogger<XAIServiceBase> logger;
|
||||
private readonly XAiApiConfiguration configuration;
|
||||
@@ -31,12 +42,25 @@ namespace xAiApi.Providers
|
||||
protected XAIServiceBase(
|
||||
IXAiDataProvider dataProvider,
|
||||
ILogger<XAIServiceBase> logger,
|
||||
XAiApiConfiguration configuration
|
||||
XAiApiConfiguration configuration,
|
||||
string model = null
|
||||
)
|
||||
{
|
||||
this.logger = logger;
|
||||
this.dataProvider = dataProvider;
|
||||
this.configuration = configuration;
|
||||
|
||||
//
|
||||
// Prepare Embedding Model Descriptor ...
|
||||
Descriptor = configuration.GetModel(model);
|
||||
if (!Descriptor.IsValid())
|
||||
{
|
||||
XException.InvalidConfiguration.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Prepare Chat Options based On Tools ...
|
||||
Options = new ChatOptions();
|
||||
}
|
||||
|
||||
//
|
||||
@@ -130,28 +154,19 @@ namespace xAiApi.Providers
|
||||
/// <summary>
|
||||
/// Get LLM Client instance for Communicating with LLM ...
|
||||
/// </summary>
|
||||
/// <param name="llm"></param>
|
||||
/// <returns></returns>
|
||||
public virtual IChatClient GetClient(string llm = null)
|
||||
public virtual IChatClient GetClient()
|
||||
{
|
||||
//
|
||||
// Retrieve Model Descriptor ...
|
||||
var modelDescriptor = configuration.GetModel(llm);
|
||||
if (modelDescriptor.IsNullOrDefault())
|
||||
{
|
||||
XException.NotFound.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Try to Initialize LLm ...
|
||||
var model = modelDescriptor.LLM;
|
||||
var apiKey = modelDescriptor.ApiKey;
|
||||
var url = new Uri(modelDescriptor.Url);
|
||||
var httpClient = GetHttpClient(modelDescriptor.Url);
|
||||
var model = Descriptor.LLM;
|
||||
var apiKey = Descriptor.ApiKey;
|
||||
var url = new Uri(Descriptor.Url);
|
||||
var httpClient = GetHttpClient(Descriptor.Url);
|
||||
|
||||
//
|
||||
IChatClient result = null;
|
||||
switch (modelDescriptor.Provider)
|
||||
switch (Descriptor.Provider)
|
||||
{
|
||||
//
|
||||
case XAiModelProviderType.Ollama:
|
||||
@@ -163,7 +178,7 @@ namespace xAiApi.Providers
|
||||
.UseFunctionInvocation()
|
||||
.Build();
|
||||
break;
|
||||
|
||||
|
||||
//
|
||||
case XAiModelProviderType.OpenAI:
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user