add Extension Method for Handling Attachment of ApiKey on AI Model Proxyfing ...
This commit is contained in:
@@ -59,5 +59,6 @@ namespace xAiModels.Constants
|
|||||||
public const string DefaultXAiProjectDescriptionResourceID = "XAiPrjD";
|
public const string DefaultXAiProjectDescriptionResourceID = "XAiPrjD";
|
||||||
|
|
||||||
//
|
//
|
||||||
|
public const string XOpenAINoKey = "no-key-required";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net.Http;
|
||||||
using xAiModels.Models;
|
using xAiModels.Models;
|
||||||
|
using xCommons.Constants;
|
||||||
using xModels.Extensions;
|
using xModels.Extensions;
|
||||||
using xCommons.Extensions;
|
using xCommons.Extensions;
|
||||||
using xAiModels.Constants;
|
using xAiModels.Constants;
|
||||||
@@ -462,5 +464,35 @@ namespace xAiModels.Extensions
|
|||||||
//
|
//
|
||||||
return result;
|
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