Compare commits
1
Commits
c8ad34944a
...
664579623a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
664579623a |
@@ -59,5 +59,6 @@ namespace xAiModels.Constants
|
||||
public const string DefaultXAiProjectDescriptionResourceID = "XAiPrjD";
|
||||
|
||||
//
|
||||
public const string XOpenAINoKey = "no-key-required";
|
||||
}
|
||||
}
|
||||
@@ -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