add Extension Method for Handling Attachment of ApiKey on AI Model Proxyfing ...
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using xAiModels.Models;
|
||||
using xCommons.Constants;
|
||||
using xModels.Extensions;
|
||||
using xCommons.Extensions;
|
||||
using xAiModels.Constants;
|
||||
@@ -462,5 +464,35 @@ namespace xAiModels.Extensions
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add Model Provider API Key ...
|
||||
/// </summary>
|
||||
/// <param name="descriptor"></param>
|
||||
/// <param name="request"></param>
|
||||
public static void AddModelDescriptorApiKey(
|
||||
this XAiModelDescriptor descriptor,
|
||||
HttpRequestMessage request
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
if (!descriptor.IsValid() || request.IsNull())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
var apiKey =
|
||||
descriptor.Provider != XAiModelProviderType.OpenAI
|
||||
? descriptor.ApiKey
|
||||
: descriptor.ApiKey.IsNullOrEmpty()
|
||||
? XAiModelsConstants.XOpenAINoKey
|
||||
: descriptor.ApiKey;
|
||||
request.Headers.TryAddWithoutValidation(
|
||||
name: XAuthorization.Header,
|
||||
value: $"{XAuthorization.TokenIdentifier} {apiKey}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user