Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions LlamaApp.LlamaCpp.Tests/LlamaManagerSnapshotEqualityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,36 @@ public void Any_Observable_Field_Change_Is_A_Change(string field)
Assert.False(LlamaManager.SnapshotsEqual(a, b));
}

[Theory]
[InlineData("audio")]
[InlineData("video")]
[InlineData("future-input")]
public void Input_Modality_Changes_Are_Published(string modality)
{
var before = Model() with { InputModalities = ["text"] };
var after = before with { InputModalities = ["text", modality] };
Assert.False(LlamaManager.SnapshotsEqual([before], [after]));
Assert.False(LlamaManager.SnapshotsEqual([after], [before]));
}

[Fact]
public void Separate_Modality_Lists_With_Equal_Contents_Are_Equal()
{
var a = Model() with { InputModalities = new[] { "text", "audio", "video" } };
var b = Model() with { InputModalities = new[] { "text", "audio", "video" } };
Assert.True(LlamaManager.SnapshotsEqual([a], [b]));
}

[Fact]
public void Failure_Details_Are_Published_Without_A_Status_Change()
{
var before = Model();
var failed = before with { IsFailed = true, LoadExitCode = 7 };
Assert.False(LlamaManager.SnapshotsEqual([before], [failed]));
Assert.False(LlamaManager.SnapshotsEqual([failed], [failed with { LoadExitCode = 9 }]));
Assert.False(LlamaManager.SnapshotsEqual([failed], [failed with { IsFailed = false }]));
}

[Fact]
public void Load_State_Flip_Is_A_Change()
{
Expand Down
7 changes: 5 additions & 2 deletions LlamaApp.LlamaCpp/LlamaManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2096,7 +2096,10 @@ internal static bool SnapshotsEqual(IReadOnlyList<ServerModel>? a, IReadOnlyList
!string.Equals(x.Path, y.Path, StringComparison.Ordinal) ||
!string.Equals(x.Source, y.Source, StringComparison.Ordinal) ||
x.CanRemove != y.CanRemove ||
x.SupportsImage != y.SupportsImage)
x.SupportsImage != y.SupportsImage ||
!x.InputModalities.SequenceEqual(y.InputModalities, StringComparer.Ordinal) ||
x.IsFailed != y.IsFailed ||
x.LoadExitCode != y.LoadExitCode)
return false;
}
return true;
Expand Down Expand Up @@ -3919,4 +3922,4 @@ private static async Task DownloadAndRunInstallerAsync(CancellationToken cancel)
return null;
}
}
}
}
47 changes: 47 additions & 0 deletions LlamaApp.Tests/ModelItemInputModalitiesTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using LlamaApp.Views;
using Xunit;

namespace LlamaApp.Tests;

public class ModelItemInputModalitiesTests
{
[Theory]
[InlineData("image", true, false, false)]
[InlineData("audio", false, true, false)]
[InlineData("video", false, false, true)]
[InlineData("future-input", false, false, false)]
[InlineData("AUDIO", false, true, false)]
public void Declared_Input_Controls_Only_Its_Indicator(
string modality, bool vision, bool audio, bool video)
{
var item = new ModelItem();
item.ApplyInputModalities(["text", modality]);
Assert.Equal(vision, item.Vision);
Assert.Equal(audio, item.Audio);
Assert.Equal(video, item.Video);
}

[Fact]
public void Existing_Row_Updates_Notifies_And_Clears_All_Indicators()
{
var item = new ModelItem { Vision = true };
var changes = new List<string?>();
item.PropertyChanged += (_, e) => changes.Add(e.PropertyName);

item.ApplyInputModalities(["text", "audio", "video"]);
Assert.False(item.Vision);
Assert.True(item.Audio);
Assert.True(item.Video);
Assert.Equal(new[] { "Vision", "Audio", "Video" }, changes);

changes.Clear();
item.ApplyInputModalities(["text", "audio", "video"]);
Assert.Empty(changes);

item.ApplyInputModalities([]);
Assert.False(item.Vision);
Assert.False(item.Audio);
Assert.False(item.Video);
Assert.Equal(new[] { "Audio", "Video" }, changes);
}
}
24 changes: 24 additions & 0 deletions Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,30 @@
HorizontalAlignment="Center"
VerticalAlignment="Center" />
</Border>
<Border CornerRadius="{ThemeResource ControlCornerRadius}"
Background="{ThemeResource ControlFillColorSecondaryBrush}"
Padding="4,0"
Height="16"
VerticalAlignment="Center"
Visibility="{x:Bind Model.Audio, Mode=OneWay}"
ToolTipService.ToolTip="Supports audio input">
<TextBlock Text="Audio"
FontSize="10"
VerticalAlignment="Center"
Foreground="{ThemeResource TextFillColorSecondaryBrush}" />
</Border>
<Border CornerRadius="{ThemeResource ControlCornerRadius}"
Background="{ThemeResource ControlFillColorSecondaryBrush}"
Padding="4,0"
Height="16"
VerticalAlignment="Center"
Visibility="{x:Bind Model.Video, Mode=OneWay}"
ToolTipService.ToolTip="Supports video input">
<TextBlock Text="Video"
FontSize="10"
VerticalAlignment="Center"
Foreground="{ThemeResource TextFillColorSecondaryBrush}" />
</Border>
<!-- Subtitle: the file size at rest (the params
ride in the chip ahead of it); while a
download runs, the live detail line instead
Expand Down
4 changes: 3 additions & 1 deletion Views/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ private async Task PopulateLocalModelsAsync(
if (existing is not null)
{
reused.Add(existing);
existing.ApplyInputModalities(sm.InputModalities);
existing.IsLoaded = sm.IsLoaded;
existing.IsDownloading = sm.IsDownloading;
item = existing;
Expand Down Expand Up @@ -527,14 +528,14 @@ private static ModelItem BuildLocalItem(
Parameters = matched?.Parameters ?? "",
Size = matched?.Size ?? "",
License = matched?.License ?? "",
Vision = sm.SupportsImage, // authoritative — from the server
Downloadable = false,
Brand = brand,
Logo = ModelItem.ResolveLogoOrGeneric(brand),
// The server's path is not reliably populated — resolve
// locally when it isn't (enrolled scan map / cache layouts).
FilePath = sm.Path ?? LlamaManager.Shared.FindModelFilePath(sm.Id),
};
item.ApplyInputModalities(sm.InputModalities);
SeedServerState(item, sm);
return item;
}
Expand Down Expand Up @@ -2624,6 +2625,7 @@ private async Task ReconcileAsync(IReadOnlyList<LlamaManager.ServerModel> server

if (item is not null)
{
item.ApplyInputModalities(sm.InputModalities);
// Rows built before the file existed (an app-driven
// download) learn their on-disk path here — it drives the
// row's "reveal in Explorer" button. Resolution retries on
Expand Down
35 changes: 33 additions & 2 deletions Views/ModelItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,38 @@ public string RowToolTip
/// </summary>
public ulong SizeBytes { get; set; }
public string License { get; set; } = "";
public bool Vision { get; set; }
private bool _vision;
public bool Vision
{
get => _vision;
set
{
if (_vision == value) return;
_vision = value;
OnPropertyChanged();
}
}

public bool Audio { get; private set; }
public bool Video { get; private set; }

/// <summary>Refreshes the same row from the server's declared inputs, including removals.</summary>
public void ApplyInputModalities(IReadOnlyList<string> modalities)
{
Vision = modalities.Contains("image", StringComparer.OrdinalIgnoreCase);
var audio = modalities.Contains("audio", StringComparer.OrdinalIgnoreCase);
var video = modalities.Contains("video", StringComparer.OrdinalIgnoreCase);
Comment on lines +186 to +188

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should consider using an enum now that we have more modalities

if (Audio != audio)
{
Audio = audio;
OnPropertyChanged(nameof(Audio));
}
if (Video != video)
{
Video = video;
OnPropertyChanged(nameof(Video));
}
}

/// <summary>Quantization label, e.g. "Q4_0", "mxfp4" (used for ServerModelId).</summary>
public string? Quant { get; set; } = null;
Expand Down Expand Up @@ -861,4 +892,4 @@ private static ImageSource ResolveLogoFile(string logoFile)

bool Has(string key) => b.StartsWith(key, StringComparison.OrdinalIgnoreCase);
}
}
}
31 changes: 27 additions & 4 deletions Views/ModelItemDetailsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,11 @@
<StackPanel Grid.Column="1"
VerticalAlignment="Center"
Spacing="2">
<!-- Name with the tags inline: the name column is capped so
a long name ellipsizes instead of pushing the chips
out of view. -->
<!-- Let the name shrink for all input badges; keep the cap
so a long name cannot push the chips out of view. -->
<Grid ColumnSpacing="6">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" MaxWidth="215" />
<ColumnDefinition Width="*" MaxWidth="215" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
Expand Down Expand Up @@ -120,6 +119,30 @@
Opacity="0.55"
VerticalAlignment="Center" />
</Border>
<Border CornerRadius="{ThemeResource ControlCornerRadius}"
Background="{ThemeResource ControlFillColorSecondaryBrush}"
Padding="4,0"
Height="16"
VerticalAlignment="Center"
Visibility="{x:Bind ViewModel.Model.Audio, Mode=OneWay}"
ToolTipService.ToolTip="Supports audio input">
<TextBlock Text="Audio"
FontSize="10"
VerticalAlignment="Center"
Foreground="{ThemeResource TextFillColorSecondaryBrush}" />
</Border>
<Border CornerRadius="{ThemeResource ControlCornerRadius}"
Background="{ThemeResource ControlFillColorSecondaryBrush}"
Padding="4,0"
Height="16"
VerticalAlignment="Center"
Visibility="{x:Bind ViewModel.Model.Video, Mode=OneWay}"
ToolTipService.ToolTip="Supports video input">
<TextBlock Text="Video"
FontSize="10"
VerticalAlignment="Center"
Foreground="{ThemeResource TextFillColorSecondaryBrush}" />
</Border>
</StackPanel>
</Grid>
<TextBlock Text="{x:Bind ViewModel.HeaderSubtitle, Mode=OneWay}"
Expand Down
Loading