mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-14 23:33:48 +00:00
Read the context window from four more model lists
This commit is contained in:
16 files changed
+415
-28
No files matched your search
@@ -151,4 +151,29 @@ public sealed class ListedModelsTests
|
||||
{
|
||||
Assert.That(ModelListing.NOTHING.ApplyTo(WHAT_THE_RULES_SAY), Is.EqualTo(WHAT_THE_RULES_SAY));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AWindowAProviderStatedIsTakenAsItIs()
|
||||
{
|
||||
Assert.That(ModelListing.For(MODEL, 32_768).Context.DefaultTokens, Is.EqualTo(32_768));
|
||||
}
|
||||
|
||||
[TestCase(0, TestName = "A window of no tokens")]
|
||||
[TestCase(-1, TestName = "A window of negative tokens")]
|
||||
[TestCase(null, TestName = "No window at all")]
|
||||
public void AWindowWhichIsNoWidthIsDroppedRatherThanRepaired(int? tokens)
|
||||
{
|
||||
//
|
||||
// Every dialect comes through this one factory, so a provider answering with something
|
||||
// nobody can interpret falls back to what the rules say -- and does so the same way for
|
||||
// all of them, rather than once per provider and slightly differently each time.
|
||||
//
|
||||
Assert.That(ModelListing.For(MODEL, tokens), Is.EqualTo(ModelListing.NOTHING));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AnEntryWithoutANameIsNoListing()
|
||||
{
|
||||
Assert.That(ModelListing.For(string.Empty, 32_768), Is.EqualTo(ModelListing.NOTHING));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
using AIStudio.Provider.HuggingFace;
|
||||
|
||||
namespace AIStudio.Tests.Provider;
|
||||
|
||||
/// <summary>
|
||||
/// Checks which window a model has when it is reached through the Hugging Face router.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The router is the one provider where the window does not belong to the model: the same weights
|
||||
/// run behind several inference providers, each configured by somebody else, and which of them
|
||||
/// answers depends on what the user chose.
|
||||
/// </remarks>
|
||||
[TestFixture]
|
||||
public sealed class HFModelTests
|
||||
{
|
||||
private const string AUTOMATIC = "";
|
||||
|
||||
private static readonly HFModel SERVED_BY_THREE = new("deepseek-ai/DeepSeek-R1",
|
||||
[
|
||||
new("novita", "live", 64_000),
|
||||
new("together", "live", 128_000),
|
||||
new("fireworks-ai", "live", 160_000),
|
||||
]);
|
||||
|
||||
[Test]
|
||||
public void AChosenProviderAnswersForItself()
|
||||
{
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(SERVED_BY_THREE.ContextWindowTokens("novita"), Is.EqualTo(64_000));
|
||||
Assert.That(SERVED_BY_THREE.ContextWindowTokens("together"), Is.EqualTo(128_000));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AChosenProviderIsFoundHoweverItIsSpelled()
|
||||
{
|
||||
Assert.That(SERVED_BY_THREE.ContextWindowTokens("Novita"), Is.EqualTo(64_000));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LettingTheRouterChooseMeansTheSmallestWindowOnOffer()
|
||||
{
|
||||
//
|
||||
// Nobody knows which provider the router will take. Promising the largest window would walk
|
||||
// a conversation into an error the user could not see coming; the smallest one only warns
|
||||
// them earlier than strictly necessary.
|
||||
//
|
||||
Assert.That(SERVED_BY_THREE.ContextWindowTokens(AUTOMATIC), Is.EqualTo(64_000));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AProviderWhichIsNotServingDoesNotDecideAnything()
|
||||
{
|
||||
var oneIsDown = new HFModel("deepseek-ai/DeepSeek-R1",
|
||||
[
|
||||
new("novita", "staging", 8_000),
|
||||
new("together", "live", 128_000),
|
||||
]);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(oneIsDown.ContextWindowTokens(AUTOMATIC), Is.EqualTo(128_000), "The small window belongs to a provider nobody can reach.");
|
||||
Assert.That(oneIsDown.ContextWindowTokens("novita"), Is.Null, "And asking for that provider by name does not bring it back either.");
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AProviderWhichDoesNotServeTheModelSaysNothingAboutIt()
|
||||
{
|
||||
Assert.That(SERVED_BY_THREE.ContextWindowTokens("cerebras"), Is.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AWindowNobodyStatedIsSkippedRatherThanCountedAsNothing()
|
||||
{
|
||||
var halfStated = new HFModel("deepseek-ai/DeepSeek-R1",
|
||||
[
|
||||
new("novita", "live", null),
|
||||
new("together", "live", 128_000),
|
||||
]);
|
||||
|
||||
Assert.That(halfStated.ContextWindowTokens(AUTOMATIC), Is.EqualTo(128_000), "A missing number is not the smallest number.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AModelNobodyServesHasNoWindow()
|
||||
{
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(new HFModel("org/model", null).ContextWindowTokens(AUTOMATIC), Is.Null);
|
||||
Assert.That(new HFModel("org/model", []).ContextWindowTokens(AUTOMATIC), Is.Null);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
using System.Text.Json;
|
||||
|
||||
using AIStudio.Provider.Groq;
|
||||
using AIStudio.Provider.OpenRouter;
|
||||
|
||||
using MistralModelsResponse = AIStudio.Provider.Mistral.ModelsResponse;
|
||||
using SelfHostedModelsResponse = AIStudio.Provider.SelfHosted.ModelsResponse;
|
||||
|
||||
namespace AIStudio.Tests.Provider;
|
||||
|
||||
/// <summary>
|
||||
/// Checks that the numbers a provider already sends actually arrive in the records reading them.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Every one of these providers spells the context window differently, and each record renames it
|
||||
/// to the one word the app uses. Getting such a name wrong fails silently -- the field stays null,
|
||||
/// the model list still loads, and the only symptom is a window nobody ever sees. The snippets
|
||||
/// below are shortened answers of the real routes, so that a rename is caught here rather than by
|
||||
/// somebody wondering why their window never shows up.
|
||||
///
|
||||
/// The options mirror what the providers deserialize with: names in snake case, which is what makes
|
||||
/// the renaming attributes necessary in the first place.
|
||||
/// </remarks>
|
||||
[TestFixture]
|
||||
public sealed class ModelListMetadataTests
|
||||
{
|
||||
private static readonly JsonSerializerOptions AS_THE_PROVIDERS_READ_IT = new()
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower,
|
||||
};
|
||||
|
||||
[Test]
|
||||
// ReSharper disable once InconsistentNaming
|
||||
public void VLLMStatesTheWindowItWasStartedWith()
|
||||
{
|
||||
var response = JsonSerializer.Deserialize<SelfHostedModelsResponse>("""
|
||||
{
|
||||
"object": "list",
|
||||
"data": [
|
||||
{ "id": "Qwen/Qwen3-32B", "object": "model", "owned_by": "vllm", "max_model_len": 32768 }
|
||||
]
|
||||
}
|
||||
""", AS_THE_PROVIDERS_READ_IT);
|
||||
|
||||
Assert.That(response.Data, Is.Not.Null);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(response.Data![0].ContextWindowTokens, Is.EqualTo(32_768));
|
||||
Assert.That(response.Data[0].OwnedBy, Is.EqualTo("vllm"), "Read with the shared options, this one arrives too -- it did not before.");
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AnEngineWhichStatesNoWindowLeavesItUnknown()
|
||||
{
|
||||
//
|
||||
// Ollama and LM Studio answer the very same route without that field. Nothing may fail
|
||||
// over it, and nothing may be invented for it either.
|
||||
//
|
||||
var response = JsonSerializer.Deserialize<SelfHostedModelsResponse>("""
|
||||
{
|
||||
"object": "list",
|
||||
"data": [ { "id": "gemma3:1b", "object": "model" } ]
|
||||
}
|
||||
""", AS_THE_PROVIDERS_READ_IT);
|
||||
|
||||
Assert.That(response.Data, Is.Not.Null);
|
||||
Assert.That(response.Data![0].ContextWindowTokens, Is.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void OpenRouterStatesTheWindowOfTheModel()
|
||||
{
|
||||
var response = JsonSerializer.Deserialize<OpenRouterModelsResponse>("""
|
||||
{
|
||||
"data": [
|
||||
{
|
||||
"id": "anthropic/claude-sonnet-4.5",
|
||||
"name": "Anthropic: Claude Sonnet 4.5",
|
||||
"context_length": 1000000,
|
||||
"architecture": { "tokenizer": "Claude" },
|
||||
"top_provider": { "max_completion_tokens": 64000 }
|
||||
}
|
||||
]
|
||||
}
|
||||
""", AS_THE_PROVIDERS_READ_IT);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(response.Data[0].ContextWindowTokens, Is.EqualTo(1_000_000));
|
||||
Assert.That(response.Data[0].Name, Is.EqualTo("Anthropic: Claude Sonnet 4.5"), "The fields we do read keep working next to the fields we deliberately do not.");
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GroqStatesTheWindowAsTheContextWindow()
|
||||
{
|
||||
var response = JsonSerializer.Deserialize<GroqModelsResponse>("""
|
||||
{
|
||||
"object": "list",
|
||||
"data": [ { "id": "llama-3.3-70b-versatile", "object": "model", "context_window": 131072 } ]
|
||||
}
|
||||
""", AS_THE_PROVIDERS_READ_IT);
|
||||
|
||||
Assert.That(response.Data[0].ContextWindowTokens, Is.EqualTo(131_072));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MistralStatesTheWindowAsAMaximumLength()
|
||||
{
|
||||
var response = JsonSerializer.Deserialize<MistralModelsResponse>("""
|
||||
{
|
||||
"object": "list",
|
||||
"data": [ { "id": "mistral-large-latest", "object": "model", "created": 1700000000, "owned_by": "mistralai", "max_context_length": 131072 } ]
|
||||
}
|
||||
""", AS_THE_PROVIDERS_READ_IT);
|
||||
|
||||
Assert.That(response.Data[0].ContextWindowTokens, Is.EqualTo(131_072));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheRouterStatesAWindowPerInferenceProvider()
|
||||
{
|
||||
var response = JsonSerializer.Deserialize<AIStudio.Provider.HuggingFace.ModelsResponse>("""
|
||||
{
|
||||
"data": [
|
||||
{
|
||||
"id": "deepseek-ai/DeepSeek-R1",
|
||||
"providers": [
|
||||
{ "provider": "novita", "status": "live", "context_length": 64000 },
|
||||
{ "provider": "together", "status": "live", "context_length": 128000 }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
""", AS_THE_PROVIDERS_READ_IT);
|
||||
|
||||
Assert.That(response.Data[0].Providers, Is.Not.Null);
|
||||
Assert.That(response.Data[0].Providers![0].ContextWindowTokens, Is.EqualTo(64_000));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user