mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-14 01:13:48 +00:00
Added Requesty as a provider (#1006)
Co-authored-by: Thorsten Sommer <SommerEngineering@users.noreply.github.com>
This commit is contained in:
1 parent
f912af321f
commit
2bd3d41421
44 files changed
+518
-65
No files matched your search
@@ -66,7 +66,7 @@ public sealed class ProviderAlibabaCloud() : BaseProvider(LLMProviders.ALIBABA_C
|
||||
return Task.FromResult(TranscriptionResult.Failure());
|
||||
}
|
||||
|
||||
/// <inhertidoc />
|
||||
/// <inheritdoc />
|
||||
public override async Task<IReadOnlyList<IReadOnlyList<float>>> EmbedTextAsync(Model embeddingModel, SettingsManager settingsManager, CancellationToken token = default, params List<string> texts)
|
||||
{
|
||||
var requestedSecret = await Program.RUST_SERVICE.GetAPIKey(this, SecretStoreType.EMBEDDING_PROVIDER);
|
||||
|
||||
@@ -191,7 +191,7 @@ public sealed class ProviderAnthropic() : BaseProvider(LLMProviders.ANTHROPIC, n
|
||||
return Task.FromResult(TranscriptionResult.Failure());
|
||||
}
|
||||
|
||||
/// <inhertidoc />
|
||||
/// <inheritdoc />
|
||||
public override Task<IReadOnlyList<IReadOnlyList<float>>> EmbedTextAsync(Model embeddingModel, SettingsManager settingsManager, CancellationToken token = default, params List<string> texts)
|
||||
{
|
||||
throw this.CreateEmbeddingsNotSupportedException();
|
||||
|
||||
@@ -66,7 +66,7 @@ public sealed class ProviderDeepSeek() : BaseProvider(LLMProviders.DEEP_SEEK, ne
|
||||
return Task.FromResult(TranscriptionResult.Failure());
|
||||
}
|
||||
|
||||
/// <inhertidoc />
|
||||
/// <inheritdoc />
|
||||
public override Task<IReadOnlyList<IReadOnlyList<float>>> EmbedTextAsync(Model embeddingModel, SettingsManager settingsManager, CancellationToken token = default, params List<string> texts)
|
||||
{
|
||||
throw this.CreateEmbeddingsNotSupportedException();
|
||||
|
||||
@@ -68,7 +68,7 @@ public class ProviderFireworks() : BaseProvider(LLMProviders.FIREWORKS, new Uri(
|
||||
return await this.PerformStandardTranscriptionRequest(requestedSecret, transcriptionModel, audioFilePath, token: token);
|
||||
}
|
||||
|
||||
/// <inhertidoc />
|
||||
/// <inheritdoc />
|
||||
public override Task<IReadOnlyList<IReadOnlyList<float>>> EmbedTextAsync(Model embeddingModel, SettingsManager settingsManager, CancellationToken token = default, params List<string> texts)
|
||||
{
|
||||
throw this.CreateEmbeddingsNotSupportedException();
|
||||
|
||||
@@ -81,7 +81,7 @@ public sealed class ProviderGWDG() : BaseProvider(LLMProviders.GWDG, new Uri("ht
|
||||
return await this.PerformStandardTranscriptionRequest(requestedSecret, transcriptionModel, audioFilePath, token: token);
|
||||
}
|
||||
|
||||
/// <inhertidoc />
|
||||
/// <inheritdoc />
|
||||
public override async Task<IReadOnlyList<IReadOnlyList<float>>> EmbedTextAsync(Model embeddingModel, SettingsManager settingsManager, CancellationToken token = default, params List<string> texts)
|
||||
{
|
||||
var requestedSecret = await Program.RUST_SERVICE.GetAPIKey(this, SecretStoreType.EMBEDDING_PROVIDER);
|
||||
|
||||
@@ -69,7 +69,7 @@ public class ProviderGoogle() : BaseProvider(LLMProviders.GOOGLE, new Uri("https
|
||||
return Task.FromResult(TranscriptionResult.Failure());
|
||||
}
|
||||
|
||||
/// <inhertidoc />
|
||||
/// <inheritdoc />
|
||||
public override async Task<IReadOnlyList<IReadOnlyList<float>>> EmbedTextAsync(Model embeddingModel, SettingsManager settingsManager, CancellationToken token = default, params List<string> texts)
|
||||
{
|
||||
var requestedSecret = await Program.RUST_SERVICE.GetAPIKey(this, SecretStoreType.EMBEDDING_PROVIDER);
|
||||
|
||||
@@ -72,7 +72,7 @@ public class ProviderGroq() : BaseProvider(LLMProviders.GROQ, new Uri("https://a
|
||||
return await this.PerformStandardTranscriptionRequest(requestedSecret, transcriptionModel, audioFilePath, token: token);
|
||||
}
|
||||
|
||||
/// <inhertidoc />
|
||||
/// <inheritdoc />
|
||||
public override Task<IReadOnlyList<IReadOnlyList<float>>> EmbedTextAsync(Model embeddingModel, SettingsManager settingsManager, CancellationToken token = default, params List<string> texts)
|
||||
{
|
||||
throw this.CreateEmbeddingsNotSupportedException();
|
||||
|
||||
@@ -69,7 +69,7 @@ public sealed class ProviderHelmholtz() : BaseProvider(LLMProviders.HELMHOLTZ, n
|
||||
return await this.PerformStandardTranscriptionRequest(requestedSecret, transcriptionModel, audioFilePath, token: token);
|
||||
}
|
||||
|
||||
/// <inhertidoc />
|
||||
/// <inheritdoc />
|
||||
public override async Task<IReadOnlyList<IReadOnlyList<float>>> EmbedTextAsync(Model embeddingModel, SettingsManager settingsManager, CancellationToken token = default, params List<string> texts)
|
||||
{
|
||||
var requestedSecret = await Program.RUST_SERVICE.GetAPIKey(this, SecretStoreType.EMBEDDING_PROVIDER);
|
||||
|
||||
@@ -217,7 +217,7 @@ public sealed class ProviderHuggingFace : BaseProvider
|
||||
return await this.PerformStandardTranscriptionRequest(requestedSecret, transcriptionModel, audioFilePath, token: token);
|
||||
}
|
||||
|
||||
/// <inhertidoc />
|
||||
/// <inheritdoc />
|
||||
public override async Task<IReadOnlyList<IReadOnlyList<float>>> EmbedTextAsync(Model embeddingModel, SettingsManager settingsManager, CancellationToken token = default, params List<string> texts)
|
||||
{
|
||||
var requestedSecret = await Program.RUST_SERVICE.GetAPIKey(this, SecretStoreType.EMBEDDING_PROVIDER);
|
||||
|
||||
@@ -74,7 +74,7 @@ public sealed class ProviderIONOS() : BaseProvider(LLMProviders.IONOS, new Uri("
|
||||
return Task.FromResult(TranscriptionResult.Failure());
|
||||
}
|
||||
|
||||
/// <inhertidoc />
|
||||
/// <inheritdoc />
|
||||
public override async Task<IReadOnlyList<IReadOnlyList<float>>> EmbedTextAsync(Model embeddingModel, SettingsManager settingsManager, CancellationToken token = default, params List<string> texts)
|
||||
{
|
||||
var requestedSecret = await Program.RUST_SERVICE.GetAPIKey(this, SecretStoreType.EMBEDDING_PROVIDER);
|
||||
|
||||
@@ -19,6 +19,7 @@ public enum LLMProviders
|
||||
HETZNER = 16,
|
||||
IONOS = 17,
|
||||
LITE_LLM = 18,
|
||||
REQUESTY = 19,
|
||||
|
||||
FIREWORKS = 5,
|
||||
GROQ = 6,
|
||||
|
||||
@@ -14,6 +14,7 @@ using AIStudio.Provider.Mistral;
|
||||
using AIStudio.Provider.OpenAI;
|
||||
using AIStudio.Provider.OpenRouter;
|
||||
using AIStudio.Provider.Perplexity;
|
||||
using AIStudio.Provider.Requesty;
|
||||
using AIStudio.Provider.SelfHosted;
|
||||
using AIStudio.Provider.X;
|
||||
using AIStudio.Settings;
|
||||
@@ -62,6 +63,7 @@ public static class LLMProvidersExtensions
|
||||
LLMProviders.HETZNER => "Hetzner (Experimental)",
|
||||
LLMProviders.IONOS => "IONOS",
|
||||
LLMProviders.LITE_LLM => "LiteLLM",
|
||||
LLMProviders.REQUESTY => "Requesty",
|
||||
|
||||
LLMProviders.GROQ => "Groq",
|
||||
LLMProviders.FIREWORKS => "Fireworks.ai",
|
||||
@@ -100,6 +102,7 @@ public static class LLMProvidersExtensions
|
||||
LLMProviders.HETZNER => "Hetzner",
|
||||
LLMProviders.IONOS => "IONOS",
|
||||
LLMProviders.LITE_LLM => "LiteLLM",
|
||||
LLMProviders.REQUESTY => "Requesty",
|
||||
|
||||
LLMProviders.GROQ => "Groq",
|
||||
LLMProviders.FIREWORKS => "Fireworks.ai",
|
||||
@@ -170,6 +173,18 @@ public static class LLMProvidersExtensions
|
||||
// of a self-hosted model here and let the user assign the level themselves.
|
||||
LLMProviders.LITE_LLM => Confidence.USER_OPERATED_GATEWAY.WithSources("https://docs.litellm.ai/docs/data_security").WithLevel(settingsManager.GetConfiguredConfidenceLevel(llmProvider)),
|
||||
|
||||
// Requesty Ltd is based in London and works under the UK GDPR and the EU GDPR. Unless logging
|
||||
// is switched off, it keeps requests for up to 30 days, and it may use the content of free
|
||||
// accounts for training. Where a model runs depends on the model rather than on Requesty:
|
||||
// names ending in "@eu" or in another European region stay in Europe, the others may not.
|
||||
// That is why we state the region but leave the trust level unknown.
|
||||
LLMProviders.REQUESTY => Confidence.UNKNOWN.WithRegion("Europe, United Kingdom").WithSources(
|
||||
"https://www.requesty.ai/privacy",
|
||||
"https://www.requesty.ai/privacy/subprocessors",
|
||||
"https://www.requesty.ai/dpa",
|
||||
"https://www.requesty.ai/terms"
|
||||
).WithLevel(settingsManager.GetConfiguredConfidenceLevel(llmProvider)),
|
||||
|
||||
LLMProviders.SELF_HOSTED => Confidence.SELF_HOSTED.WithLevel(settingsManager.GetConfiguredConfidenceLevel(llmProvider)),
|
||||
|
||||
LLMProviders.HELMHOLTZ => Confidence.GDPR_NO_TRAINING.WithRegion("Europe, Germany").WithSources("https://helmholtz.cloud/services/?serviceID=d7d5c597-a2f6-4bd1-b71e-4d6499d98570").WithLevel(settingsManager.GetConfiguredConfidenceLevel(llmProvider)),
|
||||
@@ -197,6 +212,7 @@ public static class LLMProvidersExtensions
|
||||
LLMProviders.GWDG => true,
|
||||
LLMProviders.OPEN_ROUTER => true,
|
||||
LLMProviders.LITE_LLM => true,
|
||||
LLMProviders.REQUESTY => true,
|
||||
|
||||
//
|
||||
// Providers that do not support embeddings:
|
||||
@@ -237,6 +253,7 @@ public static class LLMProvidersExtensions
|
||||
LLMProviders.HELMHOLTZ => true,
|
||||
LLMProviders.GROQ => true,
|
||||
LLMProviders.LITE_LLM => true,
|
||||
LLMProviders.REQUESTY => true,
|
||||
|
||||
//
|
||||
// Providers that support transcription but provide no OpenAI-compatible API yet:
|
||||
@@ -319,6 +336,7 @@ public static class LLMProvidersExtensions
|
||||
LLMProviders.HETZNER => new ProviderHetzner { InstanceName = instanceName, ConfiguredProviderId = configuredProviderId, AdditionalJsonApiParameters = expertProviderApiParameter, TokenizerPath = tokenizerPath, IsEnterpriseConfiguration = isEnterpriseConfiguration },
|
||||
LLMProviders.IONOS => new ProviderIONOS { InstanceName = instanceName, ConfiguredProviderId = configuredProviderId, AdditionalJsonApiParameters = expertProviderApiParameter, TokenizerPath = tokenizerPath, IsEnterpriseConfiguration = isEnterpriseConfiguration },
|
||||
LLMProviders.LITE_LLM => new ProviderLiteLLM(hostname) { InstanceName = instanceName, ConfiguredProviderId = configuredProviderId, AdditionalJsonApiParameters = expertProviderApiParameter, TokenizerPath = tokenizerPath, IsEnterpriseConfiguration = isEnterpriseConfiguration },
|
||||
LLMProviders.REQUESTY => new ProviderRequesty { InstanceName = instanceName, ConfiguredProviderId = configuredProviderId, AdditionalJsonApiParameters = expertProviderApiParameter, TokenizerPath = tokenizerPath, IsEnterpriseConfiguration = isEnterpriseConfiguration },
|
||||
|
||||
LLMProviders.GROQ => new ProviderGroq { InstanceName = instanceName, ConfiguredProviderId = configuredProviderId, AdditionalJsonApiParameters = expertProviderApiParameter, TokenizerPath = tokenizerPath, IsEnterpriseConfiguration = isEnterpriseConfiguration },
|
||||
LLMProviders.FIREWORKS => new ProviderFireworks { InstanceName = instanceName, ConfiguredProviderId = configuredProviderId, AdditionalJsonApiParameters = expertProviderApiParameter, TokenizerPath = tokenizerPath, IsEnterpriseConfiguration = isEnterpriseConfiguration },
|
||||
@@ -357,6 +375,7 @@ public static class LLMProvidersExtensions
|
||||
LLMProviders.OPEN_ROUTER => "https://openrouter.ai/keys",
|
||||
LLMProviders.HETZNER => "https://experiments.hetzner.com",
|
||||
LLMProviders.IONOS => "https://cloud.ionos.com/compute/sign-up",
|
||||
LLMProviders.REQUESTY => "https://app.requesty.ai/api-keys",
|
||||
|
||||
LLMProviders.GROQ => "https://console.groq.com/",
|
||||
LLMProviders.FIREWORKS => "https://fireworks.ai/login",
|
||||
@@ -384,6 +403,7 @@ public static class LLMProvidersExtensions
|
||||
LLMProviders.HUGGINGFACE => "https://huggingface.co/settings/billing",
|
||||
LLMProviders.HETZNER => "https://experiments.hetzner.com",
|
||||
LLMProviders.IONOS => "https://dcd.ionos.com/latest/?page=dcd-ai-model-hub",
|
||||
LLMProviders.REQUESTY => "https://app.requesty.ai/",
|
||||
|
||||
_ => string.Empty,
|
||||
};
|
||||
@@ -404,6 +424,7 @@ public static class LLMProvidersExtensions
|
||||
LLMProviders.HUGGINGFACE => true,
|
||||
LLMProviders.HETZNER => true,
|
||||
LLMProviders.IONOS => true,
|
||||
LLMProviders.REQUESTY => true,
|
||||
|
||||
_ => false,
|
||||
};
|
||||
@@ -492,6 +513,7 @@ public static class LLMProvidersExtensions
|
||||
LLMProviders.HETZNER => true,
|
||||
LLMProviders.IONOS => true,
|
||||
LLMProviders.LITE_LLM => true,
|
||||
LLMProviders.REQUESTY => true,
|
||||
|
||||
LLMProviders.GROQ => true,
|
||||
LLMProviders.FIREWORKS => true,
|
||||
@@ -521,6 +543,7 @@ public static class LLMProvidersExtensions
|
||||
LLMProviders.OPEN_ROUTER => true,
|
||||
LLMProviders.HETZNER => true,
|
||||
LLMProviders.IONOS => true,
|
||||
LLMProviders.REQUESTY => true,
|
||||
|
||||
LLMProviders.GROQ => true,
|
||||
LLMProviders.FIREWORKS => true,
|
||||
|
||||
@@ -31,6 +31,7 @@ public static class LLMProvidersIconExtensions
|
||||
LLMProviders.HETZNER => $"{ICON_ROOT}/hetzner.svg",
|
||||
LLMProviders.IONOS => $"{ICON_ROOT}/ionos.svg",
|
||||
LLMProviders.LITE_LLM => $"{ICON_ROOT}/litellm.svg",
|
||||
LLMProviders.REQUESTY => $"{ICON_ROOT}/requesty.svg",
|
||||
LLMProviders.GROQ => $"{ICON_ROOT}/groq.svg",
|
||||
LLMProviders.FIREWORKS => $"{ICON_ROOT}/fireworks.svg",
|
||||
LLMProviders.HUGGINGFACE => $"{ICON_ROOT}/hugging-face.svg",
|
||||
|
||||
@@ -75,7 +75,7 @@ public sealed class ProviderMistral() : BaseProvider(LLMProviders.MISTRAL, new U
|
||||
return await this.PerformStandardTranscriptionRequest(requestedSecret, transcriptionModel, audioFilePath, token: token);
|
||||
}
|
||||
|
||||
/// <inhertidoc />
|
||||
/// <inheritdoc />
|
||||
public override async Task<IReadOnlyList<IReadOnlyList<float>>> EmbedTextAsync(Provider.Model embeddingModel, SettingsManager settingsManager, CancellationToken token = default, params List<string> texts)
|
||||
{
|
||||
var requestedSecret = await Program.RUST_SERVICE.GetAPIKey(this, SecretStoreType.EMBEDDING_PROVIDER);
|
||||
|
||||
@@ -328,7 +328,7 @@ public sealed class ProviderOpenAI() : BaseProvider(LLMProviders.OPEN_AI, new Ur
|
||||
return await this.PerformStandardTranscriptionRequest(requestedSecret, transcriptionModel, audioFilePath, token: token);
|
||||
}
|
||||
|
||||
/// <inhertidoc />
|
||||
/// <inheritdoc />
|
||||
public override async Task<IReadOnlyList<IReadOnlyList<float>>> EmbedTextAsync(Model embeddingModel, SettingsManager settingsManager, CancellationToken token = default, params List<string> texts)
|
||||
{
|
||||
var requestedSecret = await Program.RUST_SERVICE.GetAPIKey(this, SecretStoreType.EMBEDDING_PROVIDER);
|
||||
|
||||
@@ -10,9 +10,6 @@ namespace AIStudio.Provider.OpenRouter;
|
||||
|
||||
public sealed class ProviderOpenRouter() : BaseProvider(LLMProviders.OPEN_ROUTER, new Uri("https://openrouter.ai/api/v1/"), ExternalHttpTrustPolicy.SYSTEM_TRUST_ONLY, LOGGER)
|
||||
{
|
||||
private const string PROJECT_WEBSITE = "https://github.com/MindWorkAI/AI-Studio";
|
||||
private const string PROJECT_NAME = "MindWork AI Studio";
|
||||
|
||||
private static readonly ILogger<ProviderOpenRouter> LOGGER = Program.LOGGER_FACTORY.CreateLogger<ProviderOpenRouter>();
|
||||
|
||||
#region Implementation of IProvider
|
||||
@@ -54,12 +51,7 @@ public sealed class ProviderOpenRouter() : BaseProvider(LLMProviders.OPEN_ROUTER
|
||||
AdditionalApiParameters = apiParameters
|
||||
};
|
||||
},
|
||||
headersAction: headers =>
|
||||
{
|
||||
// Set custom headers for project identification:
|
||||
headers.Add("HTTP-Referer", PROJECT_WEBSITE);
|
||||
headers.Add("X-Title", PROJECT_NAME);
|
||||
},
|
||||
headersAction: ProjectAttribution.Apply,
|
||||
token: token))
|
||||
yield return content;
|
||||
}
|
||||
@@ -78,7 +70,7 @@ public sealed class ProviderOpenRouter() : BaseProvider(LLMProviders.OPEN_ROUTER
|
||||
return Task.FromResult(TranscriptionResult.Failure());
|
||||
}
|
||||
|
||||
/// <inhertidoc />
|
||||
/// <inheritdoc />
|
||||
public override async Task<IReadOnlyList<IReadOnlyList<float>>> EmbedTextAsync(Model embeddingModel, SettingsManager settingsManager, CancellationToken token = default, params List<string> texts)
|
||||
{
|
||||
var requestedSecret = await Program.RUST_SERVICE.GetAPIKey(this, SecretStoreType.EMBEDDING_PROVIDER);
|
||||
@@ -120,12 +112,7 @@ public sealed class ProviderOpenRouter() : BaseProvider(LLMProviders.OPEN_ROUTER
|
||||
.Select(n => new Model(n.Id, n.Name))
|
||||
.Where(model => model.IsChatModel(this.Provider)),
|
||||
apiKeyProvisional,
|
||||
requestConfigurator: (request, secretKey) =>
|
||||
{
|
||||
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", secretKey);
|
||||
request.Headers.Add("HTTP-Referer", PROJECT_WEBSITE);
|
||||
request.Headers.Add("X-Title", PROJECT_NAME);
|
||||
},
|
||||
requestConfigurator: ConfigureRequest,
|
||||
listingFactory: modelResponse => modelResponse.Data.Select(n => ModelListing.For(n.Id, n.ContextWindowTokens)),
|
||||
token: token);
|
||||
}
|
||||
@@ -153,12 +140,13 @@ public sealed class ProviderOpenRouter() : BaseProvider(LLMProviders.OPEN_ROUTER
|
||||
"embeddings/models",
|
||||
modelResponse => modelResponse.Data.Select(n => new Model(n.Id, n.Name)),
|
||||
apiKeyProvisional,
|
||||
requestConfigurator: (request, secretKey) =>
|
||||
{
|
||||
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", secretKey);
|
||||
request.Headers.Add("HTTP-Referer", PROJECT_WEBSITE);
|
||||
request.Headers.Add("X-Title", PROJECT_NAME);
|
||||
},
|
||||
requestConfigurator: ConfigureRequest,
|
||||
token: token);
|
||||
}
|
||||
|
||||
private static void ConfigureRequest(HttpRequestMessage request, string secretKey)
|
||||
{
|
||||
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", secretKey);
|
||||
ProjectAttribution.Apply(request.Headers);
|
||||
}
|
||||
}
|
||||
@@ -74,7 +74,7 @@ public sealed class ProviderPerplexity() : BaseProvider(LLMProviders.PERPLEXITY,
|
||||
return Task.FromResult(TranscriptionResult.Failure());
|
||||
}
|
||||
|
||||
/// <inhertidoc />
|
||||
/// <inheritdoc />
|
||||
public override Task<IReadOnlyList<IReadOnlyList<float>>> EmbedTextAsync(Model embeddingModel, SettingsManager settingsManager, CancellationToken token = default, params List<string> texts)
|
||||
{
|
||||
throw this.CreateEmbeddingsNotSupportedException();
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
using System.Net.Http.Headers;
|
||||
|
||||
namespace AIStudio.Provider;
|
||||
|
||||
/// <summary>
|
||||
/// The headers which tell a gateway that a request comes from AI Studio.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// OpenRouter and Requesty read the same two headers: "HTTP-Referer" for the address of the app,
|
||||
/// and "X-Title" for its name. OpenRouter lists apps by them in its rankings (App Attribution), and
|
||||
/// Requesty tags the analytics of its users with them (Origin Headers), so a person can tell the
|
||||
/// requests of AI Studio apart from those of their other tools. OpenRouter calls the second header
|
||||
/// "X-OpenRouter-Title" by now and still reads "X-Title"; staying with the name both gateways
|
||||
/// understand is what lets them share this.
|
||||
///
|
||||
/// Neither header says anything about the user: both values are the same for every installation.
|
||||
/// </remarks>
|
||||
public static class ProjectAttribution
|
||||
{
|
||||
/// <summary>
|
||||
/// The address the gateways identify the app by.
|
||||
/// </summary>
|
||||
private const string PROJECT_WEBSITE = "https://github.com/MindWorkAI/AI-Studio";
|
||||
|
||||
/// <summary>
|
||||
/// The name the gateways show for the app.
|
||||
/// </summary>
|
||||
private const string PROJECT_NAME = "MindWork AI Studio";
|
||||
|
||||
/// <summary>
|
||||
/// Adds the attribution headers to a request.
|
||||
/// </summary>
|
||||
/// <param name="headers">The headers of the request.</param>
|
||||
public static void Apply(HttpRequestHeaders headers)
|
||||
{
|
||||
headers.Add("HTTP-Referer", PROJECT_WEBSITE);
|
||||
headers.Add("X-Title", PROJECT_NAME);
|
||||
}
|
||||
}
|
||||
@@ -108,6 +108,7 @@ public static class ReasoningDispatcher
|
||||
LLMProviders.HETZNER or
|
||||
LLMProviders.IONOS or
|
||||
LLMProviders.LITE_LLM or
|
||||
LLMProviders.REQUESTY or
|
||||
LLMProviders.X or
|
||||
LLMProviders.DEEP_SEEK or
|
||||
LLMProviders.GROQ or
|
||||
|
||||
@@ -0,0 +1,185 @@
|
||||
using System.Net.Http.Headers;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
using AIStudio.Chat;
|
||||
using AIStudio.Models.Live;
|
||||
using AIStudio.Provider.OpenAI;
|
||||
using AIStudio.Settings;
|
||||
|
||||
namespace AIStudio.Provider.Requesty;
|
||||
|
||||
public sealed class ProviderRequesty() : BaseProvider(LLMProviders.REQUESTY, new Uri("https://router.requesty.ai/v1/"), ExternalHttpTrustPolicy.SYSTEM_TRUST_ONLY, LOGGER)
|
||||
{
|
||||
private static readonly ILogger<ProviderRequesty> LOGGER = Program.LOGGER_FACTORY.CreateLogger<ProviderRequesty>();
|
||||
|
||||
#region Implementation of IProvider
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string Id => LLMProviders.REQUESTY.ToSecretId();
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string InstanceName { get; set; } = "Requesty";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool HasModelLoadingCapability => true;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override async IAsyncEnumerable<ContentStreamChunk> StreamChatCompletion(Model chatModel, ChatThread chatThread, SettingsManager settingsManager, [EnumeratorCancellation] CancellationToken token = default)
|
||||
{
|
||||
await foreach (var content in this.StreamOpenAICompatibleChatCompletion<ChatCompletionAPIRequest, ChatCompletionDeltaStreamLine, NoChatCompletionAnnotationStreamLine>(
|
||||
"Requesty",
|
||||
chatModel,
|
||||
chatThread,
|
||||
settingsManager,
|
||||
async (systemPrompt, apiParameters, tools) =>
|
||||
{
|
||||
// Build the list of messages:
|
||||
var messages = await chatThread.Blocks.BuildMessagesUsingNestedImageUrlAsync(this.CreateSettingsProvider(chatModel));
|
||||
|
||||
return new ChatCompletionAPIRequest
|
||||
{
|
||||
Model = chatModel.Id,
|
||||
|
||||
// Build the messages:
|
||||
// - First of all the system prompt
|
||||
// - Then none-empty user and AI messages
|
||||
Messages = [systemPrompt, ..messages],
|
||||
|
||||
// Right now, we only support streaming completions:
|
||||
Stream = true,
|
||||
Tools = tools,
|
||||
AdditionalApiParameters = apiParameters
|
||||
};
|
||||
},
|
||||
headersAction: ProjectAttribution.Apply,
|
||||
token: token))
|
||||
yield return content;
|
||||
}
|
||||
|
||||
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
|
||||
/// <inheritdoc />
|
||||
public override async IAsyncEnumerable<ImageURL> StreamImageCompletion(Model imageModel, string promptPositive, string promptNegative = FilterOperator.String.Empty, ImageURL referenceImageURL = default, [EnumeratorCancellation] CancellationToken token = default)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
|
||||
|
||||
/// <inheritdoc />
|
||||
public override async Task<TranscriptionResult> TranscribeAudioAsync(Model transcriptionModel, string audioFilePath, SettingsManager settingsManager, CancellationToken token = default)
|
||||
{
|
||||
var requestedSecret = await Program.RUST_SERVICE.GetAPIKey(this, SecretStoreType.TRANSCRIPTION_PROVIDER);
|
||||
return await this.PerformStandardTranscriptionRequest(requestedSecret, transcriptionModel, audioFilePath, token: token);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override async Task<IReadOnlyList<IReadOnlyList<float>>> EmbedTextAsync(Model embeddingModel, SettingsManager settingsManager, CancellationToken token = default, params List<string> texts)
|
||||
{
|
||||
var requestedSecret = await Program.RUST_SERVICE.GetAPIKey(this, SecretStoreType.EMBEDDING_PROVIDER);
|
||||
return await this.PerformStandardTextEmbeddingRequest(requestedSecret, embeddingModel, token: token, texts: texts);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override Task<ModelLoadResult> GetTextModels(string? apiKeyProvisional = null, CancellationToken token = default)
|
||||
{
|
||||
return this.LoadModels(SecretStoreType.LLM_PROVIDER, apiKeyProvisional, token);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override Task<ModelLoadResult> GetImageModels(string? apiKeyProvisional = null, CancellationToken token = default)
|
||||
{
|
||||
return Task.FromResult(ModelLoadResult.FromModels([]));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override Task<ModelLoadResult> GetEmbeddingModels(string? apiKeyProvisional = null, CancellationToken token = default)
|
||||
{
|
||||
return this.LoadModelsOfRoute(SecretStoreType.EMBEDDING_PROVIDER, "models/embedding", apiKeyProvisional, token);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override Task<ModelLoadResult> GetTranscriptionModels(string? apiKeyProvisional = null, CancellationToken token = default)
|
||||
{
|
||||
return this.LoadModelsOfRoute(SecretStoreType.TRANSCRIPTION_PROVIDER, "models/transcription", apiKeyProvisional, token);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Loads the managed policies and the full model catalog, and offers both as one list.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// A managed policy, such as "claude-opus-5@eu", bundles several clouds which serve the same
|
||||
/// model, and Requesty decides which of them answers a request. Requesty lists these policies on
|
||||
/// a route of their own, and the catalog does not contain them. Both lists are read before
|
||||
/// anything is reported, because what is reported replaces everything this instance said
|
||||
/// before. When the managed route fails, the catalog alone is still offered.
|
||||
/// </remarks>
|
||||
/// <param name="storeType">Where the API key is stored.</param>
|
||||
/// <param name="apiKeyProvisional">An API key which is not stored yet.</param>
|
||||
/// <param name="token">The cancellation token to use.</param>
|
||||
/// <returns>The chat models.</returns>
|
||||
private async Task<ModelLoadResult> LoadModels(SecretStoreType storeType, string? apiKeyProvisional, CancellationToken token)
|
||||
{
|
||||
IList<RequestyModel> managedModels = [];
|
||||
await this.LoadModelsResponse<RequestyModelsResponse>(
|
||||
storeType,
|
||||
"models/managed",
|
||||
modelResponse =>
|
||||
{
|
||||
managedModels = modelResponse.Data;
|
||||
return [];
|
||||
},
|
||||
apiKeyProvisional,
|
||||
requestConfigurator: ConfigureRequest,
|
||||
token: token);
|
||||
|
||||
return await this.LoadModelsResponse<RequestyModelsResponse>(
|
||||
storeType,
|
||||
"models",
|
||||
modelResponse => managedModels.Concat(modelResponse.Data)
|
||||
.DistinctBy(n => n.Id)
|
||||
.Select(n => new Model(n.Id, null))
|
||||
.Where(model => model.IsChatModel(this.Provider)),
|
||||
apiKeyProvisional,
|
||||
requestConfigurator: ConfigureRequest,
|
||||
listingFactory: modelResponse => managedModels.Concat(modelResponse.Data)
|
||||
.DistinctBy(n => n.Id)
|
||||
.Select(n => ModelListing.For(n.Id, n.ContextWindowTokens)),
|
||||
token: token);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads the models Requesty offers for embedding or for transcription, each of which lives on
|
||||
/// a route of its own.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Nothing is reported from here: such a route answers with the models of its purpose alone,
|
||||
/// and what is reported replaces everything an instance said before. The windows of the chat
|
||||
/// models would go missing the moment somebody opens the embedding or transcription settings.
|
||||
///
|
||||
/// Nothing is filtered either. The route is the statement: Requesty serves these models to
|
||||
/// embed or to transcribe with, which is more than a name can say. Asking the registry on top
|
||||
/// could only drop a model whose name we do not recognize.
|
||||
/// </remarks>
|
||||
/// <param name="storeType">Where the API key is stored.</param>
|
||||
/// <param name="route">The route which lists the models, relative to the base URL.</param>
|
||||
/// <param name="apiKeyProvisional">An API key which is not stored yet.</param>
|
||||
/// <param name="token">The cancellation token to use.</param>
|
||||
/// <returns>The models of the route.</returns>
|
||||
private Task<ModelLoadResult> LoadModelsOfRoute(SecretStoreType storeType, string route, string? apiKeyProvisional, CancellationToken token)
|
||||
{
|
||||
return this.LoadModelsResponse<RequestyModelsResponse>(
|
||||
storeType,
|
||||
route,
|
||||
modelResponse => modelResponse.Data.Select(n => new Model(n.Id, null)),
|
||||
apiKeyProvisional,
|
||||
requestConfigurator: ConfigureRequest,
|
||||
token: token);
|
||||
}
|
||||
|
||||
private static void ConfigureRequest(HttpRequestMessage request, string secretKey)
|
||||
{
|
||||
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", secretKey);
|
||||
ProjectAttribution.Apply(request.Headers);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace AIStudio.Provider.Requesty;
|
||||
|
||||
/// <summary>
|
||||
/// A data model for a Requesty model from the API.
|
||||
/// </summary>
|
||||
/// <param name="Id">The model's ID.</param>
|
||||
/// <param name="ContextWindowTokens">How much the model reads and writes in one conversation, in tokens.</param>
|
||||
public readonly record struct RequestyModel(string Id, [property: JsonPropertyName("context_window")] int? ContextWindowTokens);
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace AIStudio.Provider.Requesty;
|
||||
|
||||
/// <summary>
|
||||
/// A data model for the response from the Requesty models endpoints.
|
||||
/// </summary>
|
||||
/// <param name="Data">The list of models.</param>
|
||||
public readonly record struct RequestyModelsResponse(IList<RequestyModel> Data);
|
||||
@@ -83,7 +83,7 @@ public sealed class ProviderSelfHosted(Host host, string hostname) : BaseProvide
|
||||
return await this.PerformStandardTranscriptionRequest(requestedSecret, transcriptionModel, audioFilePath, host, token);
|
||||
}
|
||||
|
||||
/// <inhertidoc />
|
||||
/// <inheritdoc />
|
||||
public override async Task<IReadOnlyList<IReadOnlyList<float>>> EmbedTextAsync(Provider.Model embeddingModel, SettingsManager settingsManager, CancellationToken token = default, params List<string> texts)
|
||||
{
|
||||
var requestedSecret = await Program.RUST_SERVICE.GetAPIKey(this, SecretStoreType.EMBEDDING_PROVIDER, isTrying: true);
|
||||
|
||||
@@ -67,7 +67,7 @@ public sealed class ProviderX() : BaseProvider(LLMProviders.X, new Uri("https://
|
||||
return Task.FromResult(TranscriptionResult.Failure());
|
||||
}
|
||||
|
||||
/// <inhertidoc />
|
||||
/// <inheritdoc />
|
||||
public override Task<IReadOnlyList<IReadOnlyList<float>>> EmbedTextAsync(Model embeddingModel, SettingsManager settingsManager, CancellationToken token = default, params List<string> texts)
|
||||
{
|
||||
throw this.CreateEmbeddingsNotSupportedException();
|
||||
|
||||
Reference in new issue
Block a user