Read the context window from four more model lists

This commit is contained in:
Thorsten Sommer committed 2026-09-13 10:59:41 +02:00
1 parent 1c03a46e2f
commit caf2aba4b9
16 files changed
+415 -28

No files matched your search

@@ -1,8 +1,16 @@
using System.Text.Json.Serialization;
namespace AIStudio.Provider.OpenRouter;
/// <summary>
/// A data model for an OpenRouter model from the API.
/// </summary>
/// <remarks>
/// The window is the model's, not that of any one provider behind it. OpenRouter also states a
/// window per provider it currently prefers, but it picks one per request, so a number taken from
/// there would describe a choice nobody has made yet.
/// </remarks>
/// <param name="Id">The model's ID.</param>
/// <param name="Name">The model's human-readable display name.</param>
public readonly record struct OpenRouterModel(string Id, string? Name);
/// <param name="ContextWindowTokens">How much the model reads and writes in one conversation, in tokens.</param>
public readonly record struct OpenRouterModel(string Id, string? Name, [property: JsonPropertyName("context_length")] int? ContextWindowTokens);
@@ -2,6 +2,7 @@ using System.Net.Http.Headers;
using System.Runtime.CompilerServices;
using AIStudio.Chat;
using AIStudio.Models.Live;
using AIStudio.Provider.OpenAI;
using AIStudio.Settings;
@@ -125,9 +126,21 @@ public sealed class ProviderOpenRouter() : BaseProvider(LLMProviders.OPEN_ROUTER
request.Headers.Add("HTTP-Referer", PROJECT_WEBSITE);
request.Headers.Add("X-Title", PROJECT_NAME);
},
listingFactory: modelResponse => modelResponse.Data.Select(n => ModelListing.For(n.Id, n.ContextWindowTokens)),
token: token);
}
/// <summary>
/// Loads the models OpenRouter offers for embedding, which live on a route of their own.
/// </summary>
/// <remarks>
/// Nothing is reported from here: this route answers with the embedding models 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 settings.
/// </remarks>
/// <param name="apiKeyProvisional">An API key which is not stored yet.</param>
/// <param name="token">The cancellation token to use.</param>
/// <returns>The embedding models.</returns>
private Task<ModelLoadResult> LoadEmbeddingModels(string? apiKeyProvisional, CancellationToken token)
{
return this.LoadModelsResponse<OpenRouterModelsResponse>(